From 1ca2f8670d8ed10e9dfc1fa60bb35ba2e98160c5 Mon Sep 17 00:00:00 2001 From: Dominique Roux Date: Wed, 29 Jan 2020 17:15:34 +0100 Subject: [PATCH] Wrote first unit tests --- .gitlab-ci.yml | 5 +++++ test/__init__.py | 0 test/test_mac_local.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 test/__init__.py create mode 100644 test/test_mac_local.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4cb4c86 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,5 @@ +image: python:3 + +pythonTests: + script: + - python -m unittest -v test/test_mac_local.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_mac_local.py b/test/test_mac_local.py new file mode 100644 index 0000000..3a4ac3a --- /dev/null +++ b/test/test_mac_local.py @@ -0,0 +1,37 @@ +import unittest +from unittest.mock import Mock + +from uncloud.hack.mac import MAC +from uncloud import UncloudException + +class TestMacLocal(unittest.TestCase): + def setUp(self): + self.config = Mock() + self.config.arguments = {"no_db":True} + self.mac = MAC(self.config) + self.mac.create() + + def testMacInt(self): + self.assertEqual(self.mac.__int__(), int("0x420000000001",0), "wrong first MAC index") + + def testMacRepr(self): + self.assertEqual(self.mac.__repr__(), '420000000001', "wrong first MAC index") + + def testMacStr(self): + self.assertEqual(self.mac.__str__(), '42:00:00:00:00:01', "wrong first MAC index") + + def testValidationRaise(self): + with self.assertRaises(UncloudException): + self.mac.validate_mac("2") + + def testValidation(self): + self.assertTrue(self.mac.validate_mac("42:00:00:00:00:01"), "Validation of a given MAC not working properly") + + def testNextMAC(self): + self.mac.create() + self.assertEqual(self.mac.__repr__(), '420000000001', "wrong second MAC index") + self.assertEqual(self.mac.__int__(), int("0x420000000001",0), "wrong second MAC index") + self.assertEqual(self.mac.__str__(), '42:00:00:00:00:01', "wrong second MAC index") + +if __name__ == '__main__': + unittest.main()