diff --git a/code/tests.py b/code/tests.py index 978c32b..4c92f36 100755 --- a/code/tests.py +++ b/code/tests.py @@ -4,7 +4,7 @@ import json import unittest -from robots import json_to_txt, json_to_table, json_to_htaccess, json_to_nginx, json_to_haproxy, json_to_caddy, json_to_lighttpd +from robots import json_to_txt, json_to_table, json_to_htaccess, json_to_nginx, json_to_haproxy, json_to_caddy, json_to_lighttpd, consolidate, default_values, default_value class RobotsUnittestExtensions: def loadJson(self, pathname): @@ -97,6 +97,22 @@ class TestLighttpdConfigGeneration(unittest.TestCase, RobotsUnittestExtensions): self.assertEqualsFile("test_files/lighttpd-block-ai-bots.conf", robots_lighttpd) +class TestConsolidate(unittest.TestCase, RobotsUnittestExtensions): + maxDiff = 8192 + + def test_new_item(self): + existing = {} + self.assertEqual("George Jetson", consolidate(existing, "rosie", "operator", "George Jetson")) + + def test_ignores_defaults(self): + existing = {"rosie": { "operator": "George Jetson"}} + self.assertEqual("George Jetson", consolidate(existing, "rosie", "operator", default_value)) + + def test_new_description(self): + existing = {"rosie": { "description": default_value}} + self.assertEqual("Rosie is the robot maid from The Jetsons, an American animated sitcom.", + consolidate(existing, "rosie", "description", "Rosie is the robot maid from The Jetsons, an American animated sitcom") + if __name__ == "__main__": import os os.chdir(os.path.dirname(__file__))