Added pipe tests

This commit is contained in:
Sven Heidemann 2023-04-07 14:52:17 +02:00
parent 04f610c799
commit 75fde0f444
6 changed files with 68 additions and 4 deletions

View File

@ -13,7 +13,7 @@ class IPAddressPipe(PipeABC):
for i in range(0, len(value)):
byte = value[i]
if byte > 255:
if byte > 255 or byte < 0:
raise Exception("Invalid IP")
if i == len(value) - 1:

View File

@ -1,5 +1,8 @@
import unittest
from unittests_core.pipes.bool_pipe_test_case import BoolPipeTestCase
from unittests_core.pipes.ip_address_pipe_test_case import IPAddressTestCase
from unittests_core.pipes.version_pipe_test_case import VersionPipeTestCase
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
@ -10,9 +13,19 @@ 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))
tests = [
# pipes
BoolPipeTestCase,
IPAddressTestCase,
VersionPipeTestCase,
# utils
CredentialManagerTestCase,
JSONProcessorTestCase,
StringTestCase,
]
for test in tests:
self.addTests(loader.loadTestsFromTestCase(test))
def run(self, *args):
super().run(*args)

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,14 @@
import unittest
from cpl_core.pipes import BoolPipe
class BoolPipeTestCase(unittest.TestCase):
def setUp(self):
pass
def test_transform(self):
pipe = BoolPipe()
self.assertEqual("True", pipe.transform(True))
self.assertEqual("False", pipe.transform(False))

View File

@ -0,0 +1,20 @@
import unittest
from cpl_core.pipes import IPAddressPipe
class IPAddressTestCase(unittest.TestCase):
def setUp(self):
pass
def test_transform(self):
pipe = IPAddressPipe()
self.assertEqual("192.168.178.1", pipe.transform([192, 168, 178, 1]))
self.assertEqual("255.255.255.255", pipe.transform([255, 255, 255, 255]))
self.assertEqual("0.0.0.0", pipe.transform([0, 0, 0, 0]))
self.assertRaises(Exception, lambda: pipe.transform([-192, 168, 178, 1]))
self.assertRaises(Exception, lambda: pipe.transform([256, 168, 178, 1]))
self.assertRaises(Exception, lambda: pipe.transform([256, 168, 178]))
self.assertRaises(Exception, lambda: pipe.transform([256, 168, 178, 1, 1]))

View File

@ -0,0 +1,16 @@
import unittest
from cpl_core.pipes.version_pipe import VersionPipe
class VersionPipeTestCase(unittest.TestCase):
def setUp(self):
pass
def test_transform(self):
pipe = VersionPipe()
self.assertEqual("1.1.1", pipe.transform({"Major": 1, "Minor": 1, "Micro": 1}))
self.assertEqual("0.1.1", pipe.transform({"Major": 0, "Minor": 1, "Micro": 1}))
self.assertEqual("0.0.1", pipe.transform({"Major": 0, "Minor": 0, "Micro": 1}))
self.assertEqual("0.0.0", pipe.transform({"Major": 0, "Minor": 0, "Micro": 0}))