def test_get_application_settings_azure_only_billing(self): """Test to get application settings for azure only billing_source.""" resource_group = "testrg" storage_account = "testsa" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/applications?filter[source_id]={self.source_id}", status_code=200, json={ "data": [{ "extra": { "resource_group": resource_group, "storage_account": storage_account } }] }, ) response = client.get_application_settings("Azure") self.assertEqual( response.get("billing_source").get("data_source").get( "resource_group"), resource_group) self.assertEqual( response.get("billing_source").get("data_source").get( "storage_account"), storage_account) self.assertIsNone(response.get("authentication"))
def test_get_application_settings_malformed_response(self): """Test to get application settings for a malformed repsonse.""" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/applications?filter[source_id]={self.source_id}", status_code=200, json={"foo": [{"extra": {"bucket": "testbucket"}}]}, ) with self.assertRaises(SourcesHTTPClientError): _ = client.get_application_settings("AWS")
def test_get_application_settings_ocp(self): """Test to get application settings for ocp.""" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/applications?filter[source_id]={self.source_id}", status_code=200, json={"data": [{"extra": {}}]}, ) response = client.get_application_settings("OCP") self.assertIsNone(response)
def __init__(self, auth_header, source_id): """Constructor.""" sources_network = SourcesHTTPClient(auth_header, source_id) details = sources_network.get_source_details() self.name = details.get("name") self.source_type_id = int(details.get("source_type_id")) self.source_uuid = details.get("uid") self.source_type_name = sources_network.get_source_type_name( self.source_type_id) self.source_type = SOURCE_PROVIDER_MAP.get(self.source_type_name) self.app_settings = sources_network.get_application_settings( self.source_type)
def test_get_application_settings_aws(self): """Test to get application settings for aws.""" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/applications?filter[source_id]={self.source_id}", status_code=200, json={"data": [{"extra": {"bucket": "testbucket"}}]}, ) response = client.get_application_settings("AWS") expected_settings = {"billing_source": {"data_source": {"bucket": "testbucket"}}} self.assertEqual(response, expected_settings)
def test_get_application_settings_azure_authentication(self): """Test to get application settings for azure for authentications.""" subscription_id = "subscription-uuid" client = SourcesHTTPClient(auth_header=Config.SOURCES_FAKE_HEADER, source_id=self.source_id) with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/applications?filter[source_id]={self.source_id}", status_code=200, json={"data": [{"extra": {"subscription_id": subscription_id}}]}, ) response = client.get_application_settings("Azure") self.assertIsNone(response.get("billing_source")) self.assertEqual(response.get("authentication").get("credentials").get("subscription_id"), subscription_id)