Skip to content

Commit

Permalink
feat: InsightsClientConfig.save()
Browse files Browse the repository at this point in the history
Add the possibility to save the current configuration of insights-client
to the file on the filesystem.

Signed-off-by: Pino Toscano <[email protected]>
  • Loading branch information
ptoscano committed Feb 9, 2024
1 parent 54ce5f8 commit ca31c81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pytest_client_tools/insights_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def reload(self):
with contextlib.suppress(configparser.DuplicateSectionError):
self._config.add_section("insights-client")

def save(self):
with open(self._path, "w") as f:
self._config.write(f, space_around_delimiters=False)

def __getattr__(self, name):
if name in self._KEYS_BOOL:
read_func = self._config.getboolean
Expand Down
6 changes: 6 additions & 0 deletions tests/test_insights_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def test_config_set_keys(tmp_path):
# unknown key; setting will set a class attribute, not a config value
conf.unknown = "see"
assert conf.unknown == "see"
# save and check the result
conf.save()
conf_file_text = conf_file.read_text()
assert "cmd_timeout=60" in conf_file_text
assert "loglevel=DEBUG" in conf_file_text
assert "see" not in conf_file_text


def test_config_reload(tmp_path):
Expand Down

0 comments on commit ca31c81

Please sign in to comment.