From d15ee60ca7ad62004c5e036203f095cc27660f90 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Sun, 10 Apr 2022 22:21:41 +0200 Subject: Introduce a new macro (%p) representing the parent value of a given key --- tests/conftest.py | 15 +++++++-------- tests/test_cli.py | 4 +--- tests/test_envtoolkit_instance.py | 13 +++++++++++-- 3 files changed, 19 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/conftest.py b/tests/conftest.py index 0770adb..5dcc456 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,17 +30,16 @@ def config_data(): ) }, 'instances': { - 'default': {'ETOOLKIT_PROMPT': '(%i)'}, + '_default': { + 'ETOOLKIT_PROMPT': '(%i)', + 'PYTHONPATH': '/home/foo/%i/python', + }, 'dev': { - 'ETOOLKIT_PARENT': 'default', - 'PYTHONPATH': ':/home/user/.pythonpath', - 'DB_CONNECTION': ( - 'enc-val$1$Y/TBb1F3siHTw6qZg9ERzZfA8PLPf2CwGSQLpu9jYWw=$FT' - '5tS9o+ABvsxogIXpJim16Gz5SVtV8=' - ), + 'ETOOLKIT_PARENT': '_default', + 'PYTHONPATH': '%p:/home/user/%i/.pythonpath', }, 'secret': { - 'ETOOLKIT_PARENT': 'default', + 'ETOOLKIT_PARENT': '_default', 'ETOOLKIT_SENSITIVE': ['PASSWORD'], 'GNUPGHOME': '%h/private/.gnupg', 'PASSWORD': ( diff --git a/tests/test_cli.py b/tests/test_cli.py index 884e676..684c2e7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -89,9 +89,7 @@ def test_list(capsys, config_file): main(['-c', f'{config_file}', '-l']) assert exit_info.type == SystemExit assert exit_info.value.code == 0 - assert capsys.readouterr().out.strip() == ( - f'default{os.linesep}dev{os.linesep}secret' - ) + assert capsys.readouterr().out.strip() == f'dev{os.linesep}secret' def test_help(capsys): diff --git a/tests/test_envtoolkit_instance.py b/tests/test_envtoolkit_instance.py index 9061dc8..09baa31 100644 --- a/tests/test_envtoolkit_instance.py +++ b/tests/test_envtoolkit_instance.py @@ -1,5 +1,5 @@ # etoolkit -# Copyright (C) 2021-22 Simeon Simeonov +# Copyright (C) 2021-2022 Simeon Simeonov # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -63,4 +63,13 @@ def test_get_environ(config_data): def test_get_full_name(config_data): """Tests the EtoolkitInstance.get_full_name method""" instance = etoolkit.EtoolkitInstance('secret', config_data) - assert instance.get_full_name('->') == 'default->secret' + assert instance.get_full_name('->') == '_default->secret' + + +def test_parent_vars(config_data): + """Tests the EtoolkitInstance.get_full_name method""" + instance = etoolkit.EtoolkitInstance('dev', config_data) + assert instance.get_full_name('->') == '_default->dev' + assert instance.get_environ()['PYTHONPATH'] == ( + '/home/foo/_default/python:/home/user/dev/.pythonpath' + ) -- cgit v1.3