From f1b96836174555967f848be46110fb00b083011f Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Tue, 5 Oct 2021 12:08:52 +0530 Subject: [PATCH] tests: Use pytest's parametrize for KeyBasedEncryptor's unit tests --- .../encryption/test_key_based_encryptor.py | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_key_based_encryptor.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_key_based_encryptor.py index 10803cff9..56e6565a0 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_key_based_encryptor.py +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/encryption/test_key_based_encryptor.py @@ -1,3 +1,5 @@ +import pytest + from monkey_island.cc.server_utils.encryption import KeyBasedEncryptor PLAINTEXT = "password" @@ -15,19 +17,8 @@ def test_encrypt_decrypt_string_with_key(): assert decrypted == PLAINTEXT -def test_encrypt_decrypt_string_utf8_with_key_1(): - encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8_1) +@pytest.mark.parametrize("plaintext", [PLAINTEXT_UTF8_1, PLAINTEXT_UTF8_2, PLAINTEXT_UTF8_3]) +def test_encrypt_decrypt_string_utf8_with_key(plaintext): + encrypted = kb_encryptor.encrypt(plaintext) decrypted = kb_encryptor.decrypt(encrypted) - assert decrypted == PLAINTEXT_UTF8_1 - - -def test_encrypt_decrypt_string_utf8_with_key_2(): - encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8_2) - decrypted = kb_encryptor.decrypt(encrypted) - assert decrypted == PLAINTEXT_UTF8_2 - - -def test_encrypt_decrypt_string_utf8_with_key_3(): - encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8_3) - decrypted = kb_encryptor.decrypt(encrypted) - assert decrypted == PLAINTEXT_UTF8_3 + assert decrypted == plaintext