示例#1
0
 def test_load_configuration_with_aliases(self):
     my = {
         "version": "2",
         "zdravomil": {
             "enabled": False
         },
         "betka": {
             "enabled": False
         },
     }
     conf = config.load_configuration(conf_str=json.dumps(my))
     # our 'zdravomil' key has been merged into default's 'dockerfile-linter' key
     assert conf["dockerfile-linter"]["enabled"] is False
     assert conf["upstream-to-downstream"]["enabled"] is False
示例#2
0
    def test_load_configuration(self, bot_cfg_path):
        from_file = config.load_configuration(conf_path=bot_cfg_path)
        from_string = config.load_configuration(conf_str=bot_cfg_path.read_text())
        assert from_file == from_string

        # no arguments -> default config
        assert config.load_configuration()

        with pytest.raises(AttributeError):
            config.load_configuration('both args', 'specified')

        with pytest.raises(AttributeError):
            config.load_configuration(conf_path='/does/not/exist')
示例#3
0
 def test_load_configuration_with_aliases(self):
     my = {
         "version": "2",
         "zdravomil": {
             "enabled": False
         },
         "upstream-to-downstream": {
             "enabled": True,
             "master_checker": True
         }
     }
     conf = config.load_configuration(conf_str=json.dumps(my))
     # our 'zdravomil' key has been merged into default's 'dockerfile-linter' key
     assert conf['dockerfile-linter']['enabled'] is False
     assert conf['upstream-to-downstream']['enabled'] is True
示例#4
0
    def is_enabled(self, config_url=None, config_path=None):
        """
        Is bot enabled in config ?
        If config_url OR config_path is provided, fetch/load the config first
        """
        if config_url and config_path:
            raise AttributeError("Provide EITHER config_url OR config_path")

        if config_url:
            self.config = fetch_config(self.cfg_key, config_url)
        elif config_path:
            self.config = load_configuration(config_path).get(self.cfg_key, {})

        if not self.config:
            raise RuntimeError("config has not been loaded yet")

        return self.config.get("enabled", False)