Пример #1
0
    def test_load_constants(self, mock_info_logging):
        test_client = _TestClientAPI()
        test_manager = gng_impl._Manager(
            self._valid_default_config,
            self._constants,
            None,
            False,
            storage_api=test_client,
        )
        test_manager._constants['test'].value = 'valid'
        test_manager._constants['other'].value = 'OVERRIDDEN'
        test_manager._constants['KeyError'] = app_constants.Constant(
            'KeyError', 'This constant is not stored and raises a KeyError',
            '')

        test_client.insert_blob(
            test_manager._config.constants_storage_path,
            {
                'test': '',
                'other': 'other valid'
            },
            bucket_name=test_manager._config.bucket,
        )

        test_manager.load_constants_from_storage()
        # Test the default value is used when the loaded value is invalid.
        self.assertEqual(test_manager._constants['test'].value, 'valid')
        # Test loading a valid value overrides the original.
        self.assertEqual(test_manager._constants['other'].value, 'other valid')
        # Test that the 'KeyError' constant calls logging.info.
        self.assertEqual(mock_info_logging.call_count, 1)
Пример #2
0
 def test_manager_init(self):
     test_config = common.ProjectConfig('KEY', 'PROJECT', 'ID', 'SECRET',
                                        'BUCKET', self._blank_config_path)
     test_constants = app_constants.get_default_constants()
     test_manager = gng_impl._Manager(test_config, test_constants, None)
     self.assertEqual(str(test_manager), "_Manager for project 'PROJECT'")
     self.assertEqual(repr(test_manager),
                      '<_Manager.new(/testdata/blank_config.yaml, KEY)>')
Пример #3
0
 def test_load_constants__storage_not_found(self, mock_error_logging):
   test_client = _TestClientAPI()
   test_manager = gng_impl._Manager(
       self._valid_default_config, self._constants, None, False,
       storage_api=test_client,
   )
   with mock.patch.object(
       test_client, 'get_blob', side_effect=storage.NotFoundError()):
     test_manager.load_constants_from_storage()
   self.assertEqual(mock_error_logging.call_count, 1)
Пример #4
0
 def test_manager_version(self, provided_version, expected):
   # This is to satisfy the freezegun api which requires this file.
   self.fs.CreateFile('/etc/mime.types')
   now = datetime.datetime(year=2018, month=1, day=1)
   test_manager = gng_impl._Manager(
       self._valid_default_config, self._constants, None,
       prefer_gcs=False, version=provided_version)
   with freezegun.freeze_time(now):
     with mock.patch.object(getpass, 'getuser', return_value='getuser'):
       self.assertEqual(test_manager.version, expected)
Пример #5
0
 def test_save_constants(self):
   test_client = _TestClientAPI()
   test_manager = gng_impl._Manager(
       self._valid_default_config, self._constants, None, False,
       storage_api=test_client,
   )
   test_manager._save_constants()
   self.assertEqual(
       test_client.get_blob(
           test_manager._config.constants_storage_path,
           test_manager._config.bucket),
       {'test': '', 'other': 'value'})
Пример #6
0
 def test_configure(self):
   test_client = _TestClientAPI()
   test_manager = gng_impl._Manager(
       self._valid_default_config, self._constants, None, False,
       storage_api=test_client,
   )
   with mock.patch.object(
       utils, 'input', side_effect=['test', 'new_value', gng_impl._QUIT]):
     other_manager = test_manager._configure()
   self.assertEqual(
       test_client.get_blob(
           other_manager._config.constants_storage_path,
           other_manager._config.bucket),
       {'test': 'new_value', 'other': 'value'})