def setup_mocks_and_config_watcher(self):
     self.loader = mock.Mock()
     with mock.patch('staticconf.config.time') as self.mock_time:
         with mock.patch('staticconf.config.os.stat') as self.mock_stat:
             with tempfile.NamedTemporaryFile() as file:
                 with mock.patch('staticconf.config.os.path') as self.mock_path:
                     file.flush()
                     self.mock_stat.return_value.st_ino = 1
                     self.mock_stat.return_value.st_dev = 2
                     self.filename = file.name
                     self.watcher = config.ConfigurationWatcher(
                             self.loader, self.filename)
                     yield
 def test_call(self):
     self.callback_chain.namespace = 'the_namespace'
     with mock.patch('staticconf.config.reload') as mock_reload:
         self.callback_chain()
         for _, callback in self.callbacks:
             callback.assert_called_with()
             mock_reload.assert_called_with(name='the_namespace', all_names=False)
 def test_get_filename_list_from_string(self):
     with mock.patch(
             'staticconf.config.os.path.abspath') as mock_path_abspath:
         mock_path_abspath.side_effect = lambda p: p
         filename = 'thefilename.yaml'
         filenames = self.watcher.get_filename_list(filename)
         assert_equal(filenames, [filename])
 def test_get_filename_list_from_list(self):
     with mock.patch(
             'staticconf.config.os.path.abspath') as mock_path_abspath:
         mock_path_abspath.side_effect = lambda p: p
         filenames = ['b', 'g', 'z', 'a']
         expected = ['a', 'b', 'g', 'z']
         assert_equal(self.watcher.get_filename_list(filenames), expected)
Example #5
0
 def test_validate_keys_no_unknown_keys(self):
     proxies = [mock.Mock(config_key=i) for i in self.config_data]
     for mock_proxy in proxies:
         self.namespace.register_proxy(mock_proxy)
     with mock.patch('staticconf.config.log') as mock_log:
         self.namespace.validate_keys(self.config_data, True)
         self.namespace.validate_keys(self.config_data, False)
         assert not mock_log.warn.mock_calls
 def test_validate_keys_no_unknown_keys(self):
     proxies = [mock.Mock(config_key=i) for i in self.config_data]
     for mock_proxy in proxies:
         self.namespace.register_proxy(mock_proxy)
     with mock.patch('staticconf.config.log') as mock_log:
         self.namespace.validate_keys(self.config_data, True)
         self.namespace.validate_keys(self.config_data, False)
         assert not mock_log.warn.mock_calls
    def test_load(self):
        filename, namespace = "filename", "namespace"
        loader = mock.Mock()

        with mock.patch('staticconf.config.ConfigurationWatcher',
                        autospec=True) as mock_watcher_class:
            facade = config.ConfigFacade.load(filename, namespace, loader)

        facade.watcher.load_config.assert_called_with()
        assert_equal(facade.watcher, mock_watcher_class.return_value)
        reloader = facade.callback_chain
        assert_equal(reloader, facade.watcher.get_reloader())
Example #8
0
    def test_load(self):
        filename, namespace = "filename", "namespace"
        loader = mock.Mock()

        with mock.patch(
                'staticconf.config.ConfigurationWatcher',
                autospec=True) as mock_watcher_class:
            facade = config.ConfigFacade.load(filename, namespace, loader)

        facade.watcher.load_config.assert_called_with()
        assert_equal(facade.watcher, mock_watcher_class.return_value)
        reloader = facade.callback_chain
        assert_equal(reloader, facade.watcher.get_reloader())
Example #9
0
    def test_load_passes_comparators_to_configuration_watcher(self):
        filename, namespace = "filename", "namespace"
        loader = mock.Mock()
        comparator = mock.Mock(name='MockComparator')

        with mock.patch('staticconf.config.ConfigurationWatcher',
                        autospec=True) as mock_watcher_class:
            config.ConfigFacade.load(filename,
                                     namespace,
                                     loader,
                                     comparators=[comparator])
            mock_watcher_class.assert_called_with(mock.ANY,
                                                  filename,
                                                  min_interval=mock.ANY,
                                                  reloader=mock.ANY,
                                                  comparators=[comparator])
Example #10
0
 def test_validate_keys_unknown_log_keys_only(self):
     with mock.patch('staticconf.config.log') as mock_log:
         self.namespace.validate_keys(
             self.config_data,
             False,
             log_keys_only=True,
         )
         assert_equal(len(mock_log.info.mock_calls), 1)
         log_msg = mock_log.info.call_args[0][0]
         unknown = config.remove_by_keys(
             self.config_data,
             self.namespace.get_known_keys(),
         )
         for k, v in unknown:
             # Have to cast to strings here, since log_msg is a string
             key_string, val_string = str(k), str(v)
             assert key_string in log_msg
             assert val_string not in log_msg
 def test_validate_keys_unknown_log_keys_only(self):
     with mock.patch('staticconf.config.log') as mock_log:
         self.namespace.validate_keys(
             self.config_data,
             False,
             log_keys_only=True,
         )
         assert_equal(len(mock_log.info.mock_calls), 1)
         log_msg = mock_log.info.call_args[0][0]
         unknown = config.remove_by_keys(
             self.config_data,
             self.namespace.get_known_keys(),
         )
         for k, v in unknown:
             # Have to cast to strings here, since log_msg is a string
             key_string, val_string = str(k), str(v)
             assert key_string in log_msg
             assert val_string not in log_msg
    def test_load_passes_comparators_to_configuration_watcher(self):
        filename, namespace = "filename", "namespace"
        loader = mock.Mock()
        comparator = mock.Mock(name='MockComparator')

        with mock.patch(
            'staticconf.config.ConfigurationWatcher',
            autospec=True
        ) as mock_watcher_class:
            config.ConfigFacade.load(
                filename,
                namespace,
                loader,
                comparators=[comparator],
            )
            mock_watcher_class.assert_called_with(
                mock.ANY,
                filename,
                min_interval=mock.ANY,
                reloader=mock.ANY,
                comparators=[comparator],
            )
Example #13
0
 def mock_config(self):
     with mock.patch('staticconf.config') as self.mock_config:
         yield
def meta_schema():
    with mock.patch('staticconf.schema.config', autospec=True) as mock_config:
        with mock.patch('staticconf.schema.getters',
                        autospec=True) as mock_getters:
            schema_object = ATestingSchema()
            yield schema_object.__class__, mock_config, mock_getters
 def patch_namespace(self):
     self.namespace = 'the_namespace'
     patcher = mock.patch('staticconf.config.get_namespace', autospec=True)
     with patcher as self.mock_get_namespace:
         yield
 def test_get_filename_list_from_list(self):
     with mock.patch('staticconf.config.os.path.abspath') as mock_path_abspath:
         mock_path_abspath.side_effect = lambda p: p
         filenames = ['b', 'g', 'z', 'a']
         expected = ['a', 'b', 'g', 'z']
         assert_equal(self.watcher.get_filename_list(filenames), expected)
 def patch_registries(self):
     patcher = mock.patch('staticconf.getters.register_value_proxy')
     with patcher as self.mock_register:
         yield
 def test_validate_keys_unknown_log(self):
     with mock.patch('staticconf.config.log') as mock_log:
         self.namespace.validate_keys(self.config_data, False)
         assert_equal(len(mock_log.info.mock_calls), 1)
def meta_schema():
    with mock.patch('staticconf.schema.config', autospec=True) as mock_config:
        with mock.patch('staticconf.schema.getters',
                        autospec=True) as mock_getters:
            schema_object = ATestingSchema()
            yield schema_object.__class__, mock_config, mock_getters
 def test_get_filename_list_from_string(self):
     with mock.patch('staticconf.config.os.path.abspath') as mock_path_abspath:
         mock_path_abspath.side_effect = lambda p: p
         filename = 'thefilename.yaml'
         filenames = self.watcher.get_filename_list(filename)
         assert_equal(filenames, [filename])
 def mock_config(self):
     with mock.patch('staticconf.config') as self.mock_config:
         yield
Example #22
0
 def test_validate_keys_unknown_log(self):
     with mock.patch('staticconf.config.log') as mock_log:
         self.namespace.validate_keys(self.config_data, False)
         assert_equal(len(mock_log.info.mock_calls), 1)
Example #23
0
 def patch_registries(self):
     patcher = mock.patch('staticconf.getters.register_value_proxy')
     with patcher as self.mock_register:
         yield
Example #24
0
 def patch_namespace(self):
     self.namespace = 'the_namespace'
     patcher = mock.patch('staticconf.config.get_namespace', autospec=True)
     with patcher as self.mock_get_namespace:
         yield