def test_from_config_with_missing_id(): mock_http_response = copy.deepcopy(common.EXAMPLE_AUTH_RESPONSE) mock_response = MockHTTPResponse(response_dict=mock_http_response, headers={'X-Subject-Token': 'fake_token'}) project_response_without_name = copy.deepcopy(PROJECT_RESPONSE) del project_response_without_name[0]["id"] with mock.patch('datadog_checks.openstack_controller.api.Authenticator._post_auth_token', return_value=mock_response): with mock.patch('datadog_checks.openstack_controller.api.Authenticator._get_auth_projects', return_value=project_response_without_name): cred = Authenticator.from_config(log, 'http://10.0.2.15:5000', GOOD_USERS[0]['user']) assert cred is None
def test_from_config(): mock_http_response = copy.deepcopy(common.EXAMPLE_AUTH_RESPONSE) mock_response = MockHTTPResponse(response_dict=mock_http_response, headers={'X-Subject-Token': 'fake_token'}) with mock.patch('datadog_checks.openstack_controller.api.Authenticator._post_auth_token', return_value=mock_response): with mock.patch('datadog_checks.openstack_controller.api.Authenticator._get_auth_projects', return_value=PROJECTS_RESPONSE): cred = Authenticator.from_config(log, 'http://10.0.2.15:5000', GOOD_USERS[0]['user']) assert isinstance(cred, Credential) assert cred.auth_token == "fake_token" assert cred.name == "name 2" assert cred.domain_id == "3333" assert cred.tenant_id == "2222" assert cred.nova_endpoint == "http://10.0.2.15:8774/v2.1/0850707581fe4d738221a72db0182876" assert cred.neutron_endpoint == "http://10.0.2.15:9292"