58 Zeilen
1.9 KiB
Python
58 Zeilen
1.9 KiB
Python
|
import os
|
||
|
import unittest
|
||
|
|
||
|
from ansible_module.generic import Types, joindict, systemdbool
|
||
|
|
||
|
|
||
|
class TestTypes(unittest.TestCase):
|
||
|
"""tests the Types class"""
|
||
|
|
||
|
def testsimpletype(self):
|
||
|
"""this tests if an simple type is correctly build"""
|
||
|
output = Types.str(required=True, help="test", choices=("a", "1"), default="1")
|
||
|
self.assertIn("type", output)
|
||
|
self.assertIn("required", output)
|
||
|
self.assertIn("default", output)
|
||
|
self.assertIn("choices", output)
|
||
|
self.assertEqual(output["type"], "str")
|
||
|
self.assertEqual(Types.str.__name__, "str")
|
||
|
self.assertEqual(output["required"], True)
|
||
|
self.assertEqual(output["default"], "1")
|
||
|
self.assertTupleEqual(output["choices"], ("a", "1"))
|
||
|
Types.str()
|
||
|
|
||
|
def testlisttype(self):
|
||
|
"""this tests if the special type list is correctly build"""
|
||
|
output = Types.list(str)
|
||
|
Types.list("str")
|
||
|
self.assertIn("type", output)
|
||
|
self.assertIn("elements", output)
|
||
|
self.assertIn("required", output)
|
||
|
self.assertEqual(output["type"], "list")
|
||
|
self.assertEqual(output["required"], False)
|
||
|
self.assertEqual(output["elements"], "str")
|
||
|
Types.list(Types.dict(a=Types.str(help="")), help="")
|
||
|
Types.list("str")
|
||
|
|
||
|
def testdicttype(self):
|
||
|
output = Types.dict(help="HILFE")
|
||
|
self.assertIn("type", output)
|
||
|
self.assertIn("required", output)
|
||
|
self.assertIn("description", output)
|
||
|
self.assertIn("option", output)
|
||
|
|
||
|
|
||
|
class TestFuncs(unittest.TestCase):
|
||
|
def testsystemdbool(self):
|
||
|
self.assertEqual("Text", systemdbool("Text"))
|
||
|
self.assertEqual("no", systemdbool(False))
|
||
|
self.assertEqual("yes", systemdbool(True))
|
||
|
|
||
|
def testjoindict(self):
|
||
|
dicts = (
|
||
|
dict(a=1, b=2),
|
||
|
dict(b=3, c=4),
|
||
|
)
|
||
|
output = dict(a=1, b=3, c=4)
|
||
|
self.assertDictEqual(output, joindict(*dicts))
|