From 3178b59147cdeb9f6ebd3d9e21241e2eb1003b71 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 7 Apr 2023 14:40:03 +0200 Subject: [PATCH] Added JSONProcessorTestCase --- unittests/unittests_core/core_test_suite.py | 4 ++ .../utils/credential_manager_test_case.py | 36 ++++++++++++++++-- .../utils/json_processor_test_case.py | 38 +++++++++++++++++++ .../unittests_core/utils/string_test_case.py | 1 - 4 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 unittests/unittests_core/utils/json_processor_test_case.py diff --git a/unittests/unittests_core/core_test_suite.py b/unittests/unittests_core/core_test_suite.py index ce89f776..a50d9b90 100644 --- a/unittests/unittests_core/core_test_suite.py +++ b/unittests/unittests_core/core_test_suite.py @@ -1,5 +1,7 @@ import unittest +from unittests_core.utils.credential_manager_test_case import CredentialManagerTestCase +from unittests_core.utils.json_processor_test_case import JSONProcessorTestCase from unittests_core.utils.string_test_case import StringTestCase @@ -8,6 +10,8 @@ class CoreTestSuite(unittest.TestSuite): unittest.TestSuite.__init__(self) loader = unittest.TestLoader() + self.addTests(loader.loadTestsFromTestCase(CredentialManagerTestCase)) + self.addTests(loader.loadTestsFromTestCase(JSONProcessorTestCase)) self.addTests(loader.loadTestsFromTestCase(StringTestCase)) def run(self, *args): diff --git a/unittests/unittests_core/utils/credential_manager_test_case.py b/unittests/unittests_core/utils/credential_manager_test_case.py index f1991eb4..c602dfa1 100644 --- a/unittests/unittests_core/utils/credential_manager_test_case.py +++ b/unittests/unittests_core/utils/credential_manager_test_case.py @@ -1,10 +1,40 @@ import unittest +from cpl_core.utils import CredentialManager + class CredentialManagerTestCase(unittest.TestCase): - def setUp(self): pass - def test_equal(self): - pass + def test_encrypt(self): + self.assertEqual("ZkVjSkplQUx4aW1zWHlPbA==", CredentialManager.encrypt("fEcJJeALximsXyOl")) + self.assertEqual("QmtVd1l4dW5Sck9jRmVTQQ==", CredentialManager.encrypt("BkUwYxunRrOcFeSA")) + self.assertEqual("c2FtaHF1VkNSdmZpSGxDcQ==", CredentialManager.encrypt("samhquVCRvfiHlCq")) + self.assertEqual("S05aWHBPYW9DbkRSV01rWQ==", CredentialManager.encrypt("KNZXpOaoCnDRWMkY")) + self.assertEqual("QmtUV0Zsb3h1Y254UkJWeg==", CredentialManager.encrypt("BkTWFloxucnxRBVz")) + self.assertEqual("VFdNTkRuYXB1b1dndXNKdw==", CredentialManager.encrypt("TWMNDnapuoWgusJw")) + self.assertEqual("WVRiQXVSZXRMblpicWNrcQ==", CredentialManager.encrypt("YTbAuRetLnZbqckq")) + self.assertEqual("bmN4aExackxhYUVVdnV2VA==", CredentialManager.encrypt("ncxhLZrLaaEUvuvT")) + self.assertEqual("dmpNT0J5U0lLQmFrc0pIYQ==", CredentialManager.encrypt("vjMOBySIKBaksJHa")) + self.assertEqual("ZHd6WHFzSlFvQlhRbGtVZw==", CredentialManager.encrypt("dwzXqsJQoBXQlkUg")) + self.assertEqual("Q0lmUUhOREtiUmxnY2VCbQ==", CredentialManager.encrypt("CIfQHNDKbRlgceBm")) + + def test_decrypt(self): + self.assertEqual("fEcJJeALximsXyOl", CredentialManager.decrypt("ZkVjSkplQUx4aW1zWHlPbA==")) + self.assertEqual("BkUwYxunRrOcFeSA", CredentialManager.decrypt("QmtVd1l4dW5Sck9jRmVTQQ==")) + self.assertEqual("samhquVCRvfiHlCq", CredentialManager.decrypt("c2FtaHF1VkNSdmZpSGxDcQ==")) + self.assertEqual("KNZXpOaoCnDRWMkY", CredentialManager.decrypt("S05aWHBPYW9DbkRSV01rWQ==")) + self.assertEqual("BkTWFloxucnxRBVz", CredentialManager.decrypt("QmtUV0Zsb3h1Y254UkJWeg==")) + self.assertEqual("TWMNDnapuoWgusJw", CredentialManager.decrypt("VFdNTkRuYXB1b1dndXNKdw==")) + self.assertEqual("YTbAuRetLnZbqckq", CredentialManager.decrypt("WVRiQXVSZXRMblpicWNrcQ==")) + self.assertEqual("ncxhLZrLaaEUvuvT", CredentialManager.decrypt("bmN4aExackxhYUVVdnV2VA==")) + self.assertEqual("vjMOBySIKBaksJHa", CredentialManager.decrypt("dmpNT0J5U0lLQmFrc0pIYQ==")) + self.assertEqual("dwzXqsJQoBXQlkUg", CredentialManager.decrypt("ZHd6WHFzSlFvQlhRbGtVZw==")) + self.assertEqual("CIfQHNDKbRlgceBm", CredentialManager.decrypt("Q0lmUUhOREtiUmxnY2VCbQ==")) + + def test_build_string(self): + self.assertEqual( + "TestStringWithCredentialsfEcJJeALximsXyOlHere", + CredentialManager.build_string("TestStringWithCredentials$credentialsHere", "ZkVjSkplQUx4aW1zWHlPbA=="), + ) diff --git a/unittests/unittests_core/utils/json_processor_test_case.py b/unittests/unittests_core/utils/json_processor_test_case.py new file mode 100644 index 00000000..4f969a9d --- /dev/null +++ b/unittests/unittests_core/utils/json_processor_test_case.py @@ -0,0 +1,38 @@ +import unittest + +from cpl_core.utils.json_processor import JSONProcessor + + +class SubTestClass: + def __init__(self, value: str = None): + self.value = value + + +class TestClass: + def __init__(self, i: int = None, s: str = None, d: dict = None, l: list = None, value: SubTestClass = None): + self.i = i + self.s = s + self.d = d + self.l = l + self.value = value + + +class JSONProcessorTestCase(unittest.TestCase): + def setUp(self): + pass + + def test_process(self): + test_dict = { + "i": 10, + "s": "Hello World", + "d": {"test": "Test"}, + "l": range(0, 11), + "value": {"value": "Hello World"}, + } + test: TestClass = JSONProcessor.process(TestClass, test_dict) + + self.assertEqual(test.i, test_dict["i"]) + self.assertEqual(test.s, test_dict["s"]) + self.assertEqual(test.d, test_dict["d"]) + self.assertEqual(test.l, test_dict["l"]) + self.assertEqual(test.value.value, test_dict["value"]["value"]) diff --git a/unittests/unittests_core/utils/string_test_case.py b/unittests/unittests_core/utils/string_test_case.py index 665117e4..7a5173f2 100644 --- a/unittests/unittests_core/utils/string_test_case.py +++ b/unittests/unittests_core/utils/string_test_case.py @@ -5,7 +5,6 @@ from cpl_core.utils import String class StringTestCase(unittest.TestCase): - def setUp(self): pass