diff options
| author | Simeon Simeonov | 2021-12-23 14:41:14 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2021-12-23 14:41:14 +0100 |
| commit | 4914b0c74ed669d6631897950ff1660ce91ef918 (patch) | |
| tree | 5bef79607256853f41fb3bb666e1c16604a7b258 /tests/test_envtoolkit_instance.py | |
Initial commit and release for Christmas with love1.0.0
Diffstat (limited to 'tests/test_envtoolkit_instance.py')
| -rw-r--r-- | tests/test_envtoolkit_instance.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test_envtoolkit_instance.py b/tests/test_envtoolkit_instance.py new file mode 100644 index 0000000..2ffacd2 --- /dev/null +++ b/tests/test_envtoolkit_instance.py | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | # etoolkit | ||
| 2 | # Copyright (C) 2021 Simeon Simeonov | ||
| 3 | |||
| 4 | # This program is free software: you can redistribute it and/or modify | ||
| 5 | # it under the terms of the GNU General Public License as published by | ||
| 6 | # the Free Software Foundation, either version 3 of the License, or | ||
| 7 | # (at your option) any later version. | ||
| 8 | |||
| 9 | # This program is distributed in the hope that it will be useful, | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | # GNU General Public License for more details. | ||
| 13 | |||
| 14 | # You should have received a copy of the GNU General Public License | ||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | """Tests for etoolkit.EtoolkitInstance""" | ||
| 17 | import pytest | ||
| 18 | |||
| 19 | import etoolkit | ||
| 20 | |||
| 21 | |||
| 22 | def test_instantiation(config_data, password_hash): | ||
| 23 | """Tests for object instatiation""" | ||
| 24 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | ||
| 25 | instance = etoolkit.EtoolkitInstance('devv', config_data) | ||
| 26 | assert exc_info.type is etoolkit.EtoolkitInstanceError | ||
| 27 | assert exc_info.value.args[0] == 'Unknown instance "devv"' | ||
| 28 | |||
| 29 | instance = etoolkit.EtoolkitInstance('secret', config_data) | ||
| 30 | assert 'ETOOLKIT_PARENT' not in instance.raw_env_variables | ||
| 31 | assert 'ETOOLKIT_SENSITIVE' not in instance.raw_env_variables | ||
| 32 | assert 'DB_CONNECTION' not in instance.sensitive_env_variables | ||
| 33 | assert 'PASSWORD' in instance.sensitive_env_variables | ||
| 34 | assert instance.name == 'secret' | ||
| 35 | assert instance.master_password_hash == password_hash | ||
| 36 | assert instance.master_password is None | ||
| 37 | |||
| 38 | |||
| 39 | def test_get_environ(config_data): | ||
| 40 | """Tests the EtoolkitInstance.get_environ method""" | ||
| 41 | instance = etoolkit.EtoolkitInstance('secret', config_data) | ||
| 42 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | ||
| 43 | env = instance.get_environ() | ||
| 44 | assert exc_info.type is etoolkit.EtoolkitInstanceError | ||
| 45 | assert exc_info.value.args[0] == 'Neither password or prompt function set' | ||
| 46 | |||
| 47 | instance.master_password = 'The very secret passwd' # wrong passwd | ||
| 48 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | ||
| 49 | env = instance.get_environ() | ||
| 50 | assert exc_info.type is etoolkit.EtoolkitInstanceError | ||
| 51 | assert exc_info.value.args[0].startswith( | ||
| 52 | 'Invalid tag when decrypting: enc-val$' | ||
| 53 | ) | ||
| 54 | |||
| 55 | instance.master_password = 'the very secret passwd' # correct passwd | ||
| 56 | env = instance.get_environ() | ||
| 57 | assert isinstance(env, dict) | ||
| 58 | assert env['PASSWORD'] == 'secret2' | ||
| 59 | |||
| 60 | |||
| 61 | def test_get_full_name(config_data): | ||
| 62 | """Tests the EtoolkitInstance.get_full_name method""" | ||
| 63 | instance = etoolkit.EtoolkitInstance('secret', config_data) | ||
| 64 | assert instance.get_full_name('->') == 'default->secret' | ||
