def test_Adapter_create(self, MockPicSureConnection): conn = MockPicSureConnection() adapter = PicSureHpds.Adapter(conn) # correct type self.assertIsInstance(adapter, PicSureHpds.Adapter) # correct reference to connection self.assertIs(adapter.connection_reference, conn)
def test_Adapter_func_help(self, MockPicSureConnection): conn = MockPicSureConnection() adapter = PicSureHpds.Adapter(conn) with patch('sys.stdout', new=io.StringIO()) as fake_stdout: adapter.help() sys.stdout = sys.__stdout__ # Reset redirect. Needed for it to work! captured = fake_stdout.getvalue() print("Captured:\n" + captured) self.assertTrue(len(captured) > 0)
def test_Adapter_func_getResource(self, MockPicSureConnection): test_uuid = "my-test-uuid" conn = MockPicSureConnection() adapter = PicSureHpds.Adapter(conn) resource = adapter.useResource(test_uuid) # correct type? self.assertIsInstance(resource, PicSureHpds.HpdsResourceConnection) # correct uuid? self.assertEqual(resource.resource_uuid, test_uuid)
def test_Adapter_func_unlockResource(self, MockHttp, MockPicSureConnection): test_url = "http://endpoint.url/pic-sure/" test_token = "my-JWT-token" test_uuid = "my-test-uuid" test_key = "0000DEADBEEF00000000DEADBEEF0000" resp_headers = {"status": "200"} json_content = json.dumps({"resourceCredentials": {"key": test_key}}) MockHttp.return_value = (resp_headers, json_content.encode("utf-8")) conn = MockPicSureConnection() conn.url = test_url adapter = PicSureHpds.Adapter(conn) adapter.unlockResource(test_uuid, test_key) MockHttp.assert_called_with( body=json_content, headers={'Content-Type': 'application/json'}, method="POST", uri=test_url + "query")