Ejemplo n.º 1
0
 def __init__(self, config_file: str = DEFAULT_CONFIG) -> None:
     """Init and load config"""
     self.logger.info("Initializing Shoulder Bird Parser")
     self.__configclient = ConfigFile()
     self.__configclient.load(config_file)
     if not self.__configclient.config:
         self.__configclient.create("module", MODULE_NAME)
         self.__configclient.create("version", MODULE_VERSION)
Ejemplo n.º 2
0
 def __init__(self,
              client: Client,
              config_file: str = DEFAULT_CONFIG) -> None:
     """Create instance and load configuration file"""
     self.logger.info("Initializing ChatKudos module")
     self.config = ConfigFile()
     self.config.load(config_file)
     if not self.config.config:
         self.config.create("module", MODULE_NAME)
         self.config.create("version", MODULE_VERSION)
Ejemplo n.º 3
0
 def __init__(self,
              client: Client,
              config_file: str = DEFAULT_CONFIG) -> None:
     """Create instance and load configuration file"""
     self.logger.info("Initializing Audit module")
     self.owner = os.getenv("BOT_OWNER", "")
     self.config = ConfigFile()
     self.config.load(config_file)
     self.allow_list: List[str] = self.config.config.get("allow-list", [])
     if not self.config.config:
         self.config.create("module", self.MODULE_NAME)
         self.config.create("version", self.MODULE_VERSION)
Ejemplo n.º 4
0
def test_unload() -> None:
    """Empty current config, reload from same file"""
    config = ConfigFile("./tests/fixtures/mock_config.json")
    config.load()

    assert config.config

    config.unload()

    assert config.config == {}

    config.load()

    assert config.config
Ejemplo n.º 5
0
def test_load() -> None:
    """Unit Test"""
    config = ConfigFile("./tests/fixtures/mock_config.json")
    # Missing file
    config.load("invalid.file")
    assert not config.config

    # Valid relative but invalid JSON
    config.load("README.md")
    assert not config.config

    # Valid default
    config.load()
    assert not config.config
Ejemplo n.º 6
0
def test_save() -> None:
    """Unit Test"""
    random.seed()
    key = f"unitTest{random.randint(1000,10000)}"  # nosec

    config = ConfigFile("./tests/fixtures/mock_config.json")
    config.load()

    assert config.config

    assert key not in config.config.keys()
    assert config.create(key, "Test Value")
    assert config.save()

    assert key in config.config.keys()
    assert config.delete(key)
    assert config.save()

    assert key not in config.config.keys()
    assert config.config
Ejemplo n.º 7
0
def test_config_crud() -> None:
    """Unit Test"""
    random.seed()
    key = f"unitTest{random.randint(1000,10000)}"  # nosec
    config = ConfigFile("./tests/fixtures/mock_config.json")

    assert config.create(key, "Test Value")
    assert key in config.config.keys()
    assert not config.create(12345, "Test Value")  # type: ignore
    assert 12345 not in config.config.keys()
    assert not config.create(key, "Test Value")

    assert config.read(key) == "Test Value"
    assert config.read(key + "00") is None

    assert config.update(key, "New Value")
    assert config.config.get(key) == "New Value"
    assert not config.update(key + "00", "New Value")
    assert key + "00" not in config.config.keys()

    assert config.delete(key)
    assert key not in config.config.keys()
    assert not config.delete(key)
Ejemplo n.º 8
0
def test_properties() -> None:
    """Unit Test"""
    config = ConfigFile("./tests/fixtures/mock_config.json")
    config.load()
    assert isinstance(config.config, dict)