def test_get_data_source_errors(self): """Test to get application settings errors. Check first 2 SourcesHTTPClientError in get_data_source.""" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) source_types = list(APP_EXTRA_FIELD_MAP.keys()) + ["UNKNOWN_SOURCE_TYPE"] json_data = [None, []] for source_type, json in product(source_types, json_data): with self.subTest(test=(source_type, json)): with requests_mock.mock() as m: m.get( f"{MOCK_URL}/api/v1.0/{ENDPOINT_APPLICATIONS}?source_id={self.source_id}", status_code=200, json={"data": json}, ) with self.assertRaises(SourcesHTTPClientError): client.get_data_source(source_type)
def test_get_data_source_errors_invalid_extras(self): """Test to get application settings errors. Check last SourcesHTTPClientError in get_data_source""" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) source_types = list(APP_EXTRA_FIELD_MAP.keys()) + ["UNKNOWN_SOURCE_TYPE"] json_data = [[{"not_extras": {}}], [{"extra": {}}]] for source_type, json in product(source_types, json_data): with self.subTest(test=(source_type, json)): with requests_mock.mock() as m: m.get( f"{MOCK_URL}/api/v1.0/{ENDPOINT_APPLICATIONS}?source_id={self.source_id}", status_code=200, json={"data": json}, ) if source_type == Provider.PROVIDER_OCP: # ocp should always return empty dict self.assertDictEqual(client.get_data_source(source_type), {}) else: with self.assertRaises(SourcesHTTPClientError): client.get_data_source(source_type)
def test_get_data_source(self): """Test to get application settings.""" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) # aws bucket = "testbucket" # azure subscription_id = "subscription-uuid" resource_group = "testrg" storage_account = "testsa" # gcp dataset = "testdataset" table = [ {"source-type": Provider.PROVIDER_OCP, "json": {"extra": {}}, "expected": {}}, { "source-type": Provider.PROVIDER_AWS, "json": {"extra": {"bucket": bucket}}, "expected": {"bucket": bucket}, }, { "source-type": Provider.PROVIDER_AZURE, "json": { "extra": { "subscription_id": subscription_id, "resource_group": resource_group, "storage_account": storage_account, } }, "expected": {"resource_group": resource_group, "storage_account": storage_account}, }, { "source-type": Provider.PROVIDER_GCP, "json": {"extra": {"dataset": dataset}}, "expected": {"dataset": dataset}, }, ] for test in table: with self.subTest(test=test): with requests_mock.mock() as m: m.get( f"{MOCK_URL}/api/v1.0/{ENDPOINT_APPLICATIONS}?source_id={self.source_id}", status_code=200, json={"data": [test.get("json")]}, ) response = client.get_data_source(test.get("source-type")) self.assertDictEqual(response, test.get("expected"))