def test_sources_network_auth_info_error(self): """Test to get authentication information from Sources backend with error.""" test_source_id = 2 test_resource_id = 1 application_type_id = 2 app_id = 1 test_auth_header = Config.SOURCES_FAKE_HEADER ocp_source = Sources( source_id=test_source_id, auth_header=test_auth_header, endpoint_id=test_resource_id, source_type=Provider.PROVIDER_OCP, offset=1, ) ocp_source.save() with requests_mock.mock() as m: m.get(f"http://www.sources.com/api/v1.0/sources/{test_source_id}", status_code=400) m.get( SOURCES_APPS.format(application_type_id, test_source_id), status_code=200, json={"data": [{"id": app_id}]}, ) m.get( f"http://www.sources.com/api/v1.0/application_types?filter[name]=/insights/platform/cost-management", status_code=200, json={"data": [{"id": application_type_id}]}, ) m.patch(f"http://www.sources.com/api/v1.0/applications/{app_id}", status_code=204) source_integration.sources_network_auth_info(test_resource_id, test_auth_header) source_obj = Sources.objects.get(source_id=test_source_id) self.assertEquals(source_obj.authentication, {})
def test_sources_network_auth_info_ocp_with_cluster_id(self): """Test to get authentication information from Sources backend for OCP with cluster_id.""" test_source_id = 2 test_resource_id = 1 application_type = 2 cluster_id = faker.uuid4() test_auth_header = Config.SOURCES_FAKE_HEADER ocp_source = Sources( source_id=test_source_id, auth_header=test_auth_header, endpoint_id=test_resource_id, source_type=Provider.PROVIDER_OCP, offset=1, ) ocp_source.save() with requests_mock.mock() as m: m.get( f"http://www.sources.com/api/v1.0/sources/{test_source_id}", status_code=200, json={"source_ref": cluster_id}, ) m.get( f"http://www.sources.com/api/v1.0/application_types?filter[name]=/insights/platform/cost-management", status_code=200, json={"data": [{"id": application_type}]}, ) source_integration.sources_network_auth_info(test_resource_id, test_auth_header) source_obj = Sources.objects.get(source_id=test_source_id) self.assertEquals(source_obj.authentication, {"resource_name": cluster_id})
def test_sources_network_auth_info_unknown_provider(self): """Test to get authentication information from Sources backend with error.""" test_source_id = 2 test_resource_id = 1 test_auth_header = Config.SOURCES_FAKE_HEADER ocp_source = Sources(source_id=test_source_id, auth_header=test_auth_header, endpoint_id=test_resource_id, source_type='UNKNOWN', offset=1) ocp_source.save() source_integration.sources_network_auth_info(test_resource_id, test_auth_header) source_obj = Sources.objects.get(source_id=test_source_id) self.assertEquals(source_obj.authentication, {})
def test_sources_network_auth_info_error(self): """Test to get authentication information from Sources backend with error.""" test_source_id = 2 test_resource_id = 1 test_auth_header = Config.SOURCES_FAKE_HEADER ocp_source = Sources(source_id=test_source_id, auth_header=test_auth_header, endpoint_id=test_resource_id, source_type='OCP', offset=1) ocp_source.save() with requests_mock.mock() as m: m.get(f'http://www.sources.com/api/v1.0/sources/{test_source_id}', status_code=400) source_integration.sources_network_auth_info(test_resource_id, test_auth_header) source_obj = Sources.objects.get(source_id=test_source_id) self.assertEquals(source_obj.authentication, {})
def test_sources_network_auth_info_ocp_with_cluster_id(self): """Test to get authentication information from Sources backend for OCP with cluster_id.""" test_source_id = 2 test_resource_id = 1 cluster_id = faker.uuid4() test_auth_header = Config.SOURCES_FAKE_HEADER ocp_source = Sources(source_id=test_source_id, auth_header=test_auth_header, endpoint_id=test_resource_id, source_type='OCP', offset=1) ocp_source.save() with requests_mock.mock() as m: m.get(f'http://www.sources.com/api/v1.0/sources/{test_source_id}', status_code=200, json={'source_ref': cluster_id}) source_integration.sources_network_auth_info(test_resource_id, test_auth_header) source_obj = Sources.objects.get(source_id=test_source_id) self.assertEquals(source_obj.authentication, {'resource_name': cluster_id})
def test_sources_network_auth_info(self): """Test to get authentication information from Sources backend.""" test_source_id = 2 test_resource_id = 1 application_type_id = 2 app_id = 1 source_uid = faker.uuid4() test_auth_header = Config.SOURCES_FAKE_HEADER ocp_source = Sources(source_id=test_source_id, auth_header=test_auth_header, endpoint_id=test_resource_id, source_type=Provider.PROVIDER_OCP, offset=1) ocp_source.save() with requests_mock.mock() as m: m.get(f'http://www.sources.com/api/v1.0/sources/{test_source_id}', status_code=200, json={'uid': source_uid}) m.get( 'http://www.sources.com/api/v1.0/applications?filter[application_type_id]={}&filter[source_id]={}' .format(application_type_id, test_source_id), status_code=200, json={'data': [{ 'id': app_id }]}) m.get( f'http://www.sources.com/api/v1.0/application_types?filter[name]=/insights/platform/cost-management', status_code=200, json={'data': [{ 'id': application_type_id }]}) m.patch(f'http://www.sources.com/api/v1.0/applications/{app_id}', status_code=204) source_integration.sources_network_auth_info( test_resource_id, test_auth_header) source_obj = Sources.objects.get(source_id=test_source_id) self.assertEquals(source_obj.authentication, {})