def test_project_config_constructor(self, project_name, bucket_name, expected_bucket_name): """Test the direct construction of ProjectConfig.""" test_config = common.ProjectConfig(project_name, 'test_client_id', 'test_client_secret', bucket_name) self.assertEqual(project_name, test_config.project) self.assertEqual('test_client_id', test_config.client_id) self.assertEqual('test_client_secret', test_config.client_secret) self.assertEqual(expected_bucket_name, test_config.bucket) self.assertEqual('{}/configs'.format(expected_bucket_name), test_config.configs) # Test that two objects with the same constructor args are equal. self.assertEqual( test_config, common.ProjectConfig(project_name, 'test_client_id', 'test_client_secret', bucket_name)) # Test that two object with different constructor args are not equal. self.assertNotEqual( test_config, common.ProjectConfig(project_name, 'test_client_id', 'test_client_secret', 'INCORRECT')) # Test the string and representations for ProjectConfig. self.assertEqual('ProjectConfig for project: test_project.', str(test_config)) self.assertEqual( '<ProjectConfig({}, test_client_id, test_client_secret, {})>'. format(project_name, expected_bucket_name), repr(test_config))
def test_project_config_from_yaml(self): """Test the construction of ProjectConfig when loaded from a config file.""" expected_config = common.ProjectConfig( 'test_project', 'test_client_id', 'test_client_secret', None) config_file = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'config.yaml') self.fs.CreateFile(config_file, contents=_CONFIG) test_config = common.ProjectConfig.from_yaml('dev', config_file) self.assertEqual(expected_config, test_config)
def setUp(self): super(AuthTest, self).setUp() self._test_project = 'test_project' self._test_client_id = 'test_client_id' self._test_client_secret = 'test_client_secret' self._test_config = common.ProjectConfig( self._test_project, self._test_client_id, self._test_client_secret, None) # Save the real modules for clean up. self.real_open = __builtin__.open self.real_file = __builtin__.file # Create a fake file system and stub out builtin modules. self.fs = fake_filesystem.FakeFilesystem() self.os = fake_filesystem.FakeOsModule(self.fs) self.open = fake_filesystem.FakeFileOpen(self.fs) self.stubs = mox3_stubout.StubOutForTesting() self.stubs.SmartSet(__builtin__, 'open', self.open) self.stubs.SmartSet(auth, 'os', self.os)