def test_forseti_unsupported_api_is_ok(self, mock_logger, mock_discovery_build): """Test that unsupported API is ok. Args: mock_logger (Mock): Mock objects. mock_discovery_build (Mock): Mock object. Setup: * Pick a non-supported API. * Pick a valid version (not officially supported by Forseti). * Instantiate the Base Client with the API name and version. Expect: * Unsupported API will call LOGGER.warn(). """ api_name = 'zoo' self.assertFalse(api_name in _supported_apis.SUPPORTED_APIS) provided_versions = ['v1', 'v2'] mock_credentials = mock.MagicMock() repo_client = base.BaseRepositoryClient(api_name, credentials=mock_credentials, versions=provided_versions) expected_repr = 'API: name=zoo, versions=[\'v1\', \'v2\']' self.assertEqual(expected_repr, '%s' % repo_client) mock_logger.warn.assert_called_with(mock.ANY, api_name)
def test_forseti_unsupported_valid_version_is_ok(self, mock_logger, mock_discovery_build): """Test that Forseti-supported API with unsupported valid version is ok. Args: mock_logger (Mock): Mock objects. mock_discovery_build (Mock): Mock object. Setup: * Pick one of the supported APIs. * Pick a valid version (not officially supported by Forseti). * Instantiate the Base Client with the API name and version. Expect: * Unsupported version will call LOGGER.warn(). """ api_name = 'cloudresourcemanager' self.assertTrue(api_name in _supported_apis.SUPPORTED_APIS) provided_version = 'v1beta1' self.assertFalse(provided_version in _supported_apis. SUPPORTED_APIS[api_name]['supported_versions']) mock_credentials = mock.MagicMock() repo_client = base.BaseRepositoryClient(api_name, credentials=mock_credentials, versions=[provided_version]) self.assertEqual((api_name, [provided_version]), (repo_client.name, repo_client.versions)) mock_logger.warn.assert_called_with(mock.ANY, api_name, provided_version)
def test_init_repository_no_supported_version(self, mock_discovery_build): """Verify that _init_repository will pick a version if none provided.""" class ZooRepository(base.GCPRepository): def __init__(self, **kwargs): super(ZooRepository, self).__init__(component='a', **kwargs) # Return a different mock object each time build is called. mock_discovery_build.side_effect = [mock.Mock(), mock.Mock()] mock_credentials = mock.MagicMock() repo_client = base.BaseRepositoryClient('zoo', credentials=mock_credentials, versions=['v2', 'v1']) repo = repo_client._init_repository(ZooRepository) self.assertEqual(repo_client.gcp_services['v1'], repo.gcp_service) self.assertNotEqual(repo_client.gcp_services['v2'], repo.gcp_service)
def test_forseti_supported_api_is_ok(self, mock_discovery_build): """Test that Forseti-supported API in BaseClient.__init__() works. Args: mock_discovery_build (Mock): Mock object. Setup: * Pick one of the supported APIs. * Instantiate the Base Client with just the API name. Expect: * The resulting API client service has the same API name and version as the supported API. """ api_name = _supported_apis.SUPPORTED_APIS.keys()[0] supported_api = _supported_apis.SUPPORTED_APIS[api_name] mock_credentials = mock.MagicMock() repo_client = base.BaseRepositoryClient(api_name, credentials=mock_credentials) self.assertEqual((api_name, [supported_api['default_version']]), (repo_client.name, repo_client.versions))