Skip to content

Commit

Permalink
Test: Improved test coverage of EasyVault class
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Apr 4, 2021
1 parent 52d73fe commit fad0ca2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/changes.rst
Expand Up @@ -51,7 +51,7 @@ Released: not yet
* Improved error messages when writing vault file during 'EasyVault.encrypt()'
/ 'decrypt()'.

* Test: Improved test coverage of Keyring class.
* Test: Improved test coverage of Keyring and EasyVault classes.

**Cleanup:**

Expand Down
80 changes: 80 additions & 0 deletions tests/unittest/test_easy_vault.py
Expand Up @@ -785,3 +785,83 @@ def test_vault_get_yaml_fail2(yaml_load_exc, filepath):

# The code to be tested
vault.get_yaml()


class EasyVault_generate_key_type(EasyVault):
"""Derived class with generate_key() returning incorrect type"""

def generate_key(self, password):
"""Returns incorrect type unicode string"""
# pylint: disable=super-with-arguments
self_super = super(EasyVault_generate_key_type, self)
result = self_super.generate_key(password)
return result.decode('utf-8')


def test_vault_generate_key_type():
"""
Test function for overwritten EasyVault.generate_key() that returns
incorrect type.
"""
filepath = TEST_VAULT_ENCRYPTED
password = TEST_VAULT_PASSWORD

with saved_file(filepath):
with pytest.raises(TypeError):

# The code to be tested
EasyVault_generate_key_type(filepath, password)


class EasyVault_encrypt_data_type(EasyVault):
"""Derived class with encrypt_data() returning incorrect type"""

def encrypt_data(self, clear_data, key):
"""Returns incorrect type unicode string"""
# pylint: disable=super-with-arguments
self_super = super(EasyVault_encrypt_data_type, self)
result = self_super.encrypt_data(clear_data, key)
return result.decode('utf-8')


def test_vault_encrypt_data_type():
"""
Test function for overwritten EasyVault.encrypt_data() that returns
incorrect type.
"""
filepath = TEST_VAULT_DECRYPTED
password = TEST_VAULT_PASSWORD

with saved_file(filepath):
vault = EasyVault_encrypt_data_type(filepath, password)
with pytest.raises(TypeError):

# The code to be tested
vault.encrypt()


class EasyVault_decrypt_data_type(EasyVault):
"""Derived class with decrypt_data() returning incorrect type"""

def decrypt_data(self, encrypted_data, key):
"""Returns incorrect type unicode string"""
# pylint: disable=super-with-arguments
self_super = super(EasyVault_decrypt_data_type, self)
result = self_super.decrypt_data(encrypted_data, key)
return result.decode('utf-8')


def test_vault_decrypt_data_type():
"""
Test function for overwritten EasyVault.decrypt_data() that returns
incorrect type.
"""
filepath = TEST_VAULT_ENCRYPTED
password = TEST_VAULT_PASSWORD

with saved_file(filepath):
vault = EasyVault_decrypt_data_type(filepath, password)
with pytest.raises(TypeError):

# The code to be tested
vault.decrypt()

0 comments on commit fad0ca2

Please sign in to comment.