diff options
Diffstat (limited to 'tests/test_envtoolkit_instance.py')
| -rw-r--r-- | tests/test_envtoolkit_instance.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/test_envtoolkit_instance.py b/tests/test_envtoolkit_instance.py index 73faed6..0147c6f 100644 --- a/tests/test_envtoolkit_instance.py +++ b/tests/test_envtoolkit_instance.py | |||
| @@ -22,6 +22,7 @@ import etoolkit | |||
| 22 | 22 | ||
| 23 | def test_instantiation(config_data): | 23 | def test_instantiation(config_data): |
| 24 | """Tests for object instatiation""" | 24 | """Tests for object instatiation""" |
| 25 | |||
| 25 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | 26 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: |
| 26 | instance = etoolkit.EtoolkitInstance('devv', config_data) | 27 | instance = etoolkit.EtoolkitInstance('devv', config_data) |
| 27 | assert exc_info.type is etoolkit.EtoolkitInstanceError | 28 | assert exc_info.type is etoolkit.EtoolkitInstanceError |
| @@ -31,7 +32,7 @@ def test_instantiation(config_data): | |||
| 31 | assert 'ETOOLKIT_PARENT' not in instance.raw_env_variables | 32 | assert 'ETOOLKIT_PARENT' not in instance.raw_env_variables |
| 32 | assert 'ETOOLKIT_SENSITIVE' not in instance.raw_env_variables | 33 | assert 'ETOOLKIT_SENSITIVE' not in instance.raw_env_variables |
| 33 | assert 'DB_CONNECTION' not in instance.sensitive_env_variables | 34 | assert 'DB_CONNECTION' not in instance.sensitive_env_variables |
| 34 | assert 'PASSWORD' in instance.sensitive_env_variables | 35 | assert 'ETOOLKIT_TEST_PASSWORD' in instance.sensitive_env_variables |
| 35 | assert instance.name == 'secret' | 36 | assert instance.name == 'secret' |
| 36 | assert ( | 37 | assert ( |
| 37 | instance.master_password_hash | 38 | instance.master_password_hash |
| @@ -40,15 +41,16 @@ def test_instantiation(config_data): | |||
| 40 | assert instance.master_password is None | 41 | assert instance.master_password is None |
| 41 | 42 | ||
| 42 | 43 | ||
| 43 | def test_get_environ(config_data): | 44 | def test_get_environ(config_data, master_password, wrong_master_password): |
| 44 | """Tests the EtoolkitInstance.get_environ method""" | 45 | """Tests the EtoolkitInstance.get_environ method""" |
| 46 | |||
| 45 | instance = etoolkit.EtoolkitInstance('secret', config_data) | 47 | instance = etoolkit.EtoolkitInstance('secret', config_data) |
| 46 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | 48 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: |
| 47 | env = instance.get_environ() | 49 | env = instance.get_environ() |
| 48 | assert exc_info.type is etoolkit.EtoolkitInstanceError | 50 | assert exc_info.type is etoolkit.EtoolkitInstanceError |
| 49 | assert exc_info.value.args[0] == 'Neither password or prompt function set' | 51 | assert exc_info.value.args[0] == 'Neither password or prompt function set' |
| 50 | 52 | ||
| 51 | instance.master_password = 'The very secret passwd' # wrong passwd | 53 | instance.master_password = wrong_master_password |
| 52 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: | 54 | with pytest.raises(etoolkit.EtoolkitInstanceError) as exc_info: |
| 53 | env = instance.get_environ() | 55 | env = instance.get_environ() |
| 54 | assert exc_info.type is etoolkit.EtoolkitInstanceError | 56 | assert exc_info.type is etoolkit.EtoolkitInstanceError |
| @@ -56,22 +58,24 @@ def test_get_environ(config_data): | |||
| 56 | 'Invalid tag when decrypting: enc-val$' | 58 | 'Invalid tag when decrypting: enc-val$' |
| 57 | ) | 59 | ) |
| 58 | 60 | ||
| 59 | instance.master_password = 'the very secret passwd' # correct passwd | 61 | instance.master_password = master_password |
| 60 | env = instance.get_environ() | 62 | env = instance.get_environ() |
| 61 | assert isinstance(env, dict) | 63 | assert isinstance(env, dict) |
| 62 | assert env['PASSWORD'] == 'secret2' | 64 | assert env['ETOOLKIT_TEST_PASSWORD'] == 'bar' |
| 63 | 65 | ||
| 64 | 66 | ||
| 65 | def test_get_full_name(config_data): | 67 | def test_get_full_name(config_data): |
| 66 | """Tests the EtoolkitInstance.get_full_name method""" | 68 | """Tests the EtoolkitInstance.get_full_name method""" |
| 69 | |||
| 67 | instance = etoolkit.EtoolkitInstance('secret', config_data) | 70 | instance = etoolkit.EtoolkitInstance('secret', config_data) |
| 68 | assert instance.get_full_name('->') == '_default->secret' | 71 | assert instance.get_full_name('->') == '_default->secret' |
| 69 | 72 | ||
| 70 | 73 | ||
| 71 | def test_parent_vars(config_data): | 74 | def test_parent_vars(config_data): |
| 72 | """Tests the EtoolkitInstance.get_full_name method""" | 75 | """Tests the EtoolkitInstance.get_full_name method""" |
| 76 | |||
| 73 | instance = etoolkit.EtoolkitInstance('dev', config_data) | 77 | instance = etoolkit.EtoolkitInstance('dev', config_data) |
| 74 | assert instance.get_full_name('->') == '_default->dev' | 78 | assert instance.get_full_name('->') == '_default->dev' |
| 75 | assert instance.get_environ()['PYTHONPATH'] == ( | 79 | assert instance.get_environ()['ETOOLKIT_TEST_PYTHONPATH'] == ( |
| 76 | '/home/foo/_default/python:/home/user/dev/.pythonpath' | 80 | '/home/foo/_default/python:/home/user/dev/.pythonpath' |
| 77 | ) | 81 | ) |
