From dbeb65394201b583e58f60791454e0430d322cbb Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Wed, 11 Jul 2018 14:07:45 -0400 Subject: [PATCH] Add group-based tests. (cherry picked from commit ab0655d5a97a65d8bf1eb35211aea646f773214b) (cherry picked from commit e151c8399d83a80c110a787d0318eed0c9c2546a) --- tests/pylorax/results/groups-only.dict | 1 + tests/pylorax/results/groups-only.toml | 6 ++++++ tests/pylorax/test_projects.py | 9 +++++++- tests/pylorax/test_recipes.py | 9 ++++++++ tests/pylorax/test_server.py | 29 +++++++++++++++++++------- 5 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 tests/pylorax/results/groups-only.dict create mode 100644 tests/pylorax/results/groups-only.toml diff --git a/tests/pylorax/results/groups-only.dict b/tests/pylorax/results/groups-only.dict new file mode 100644 index 00000000..099ea24a --- /dev/null +++ b/tests/pylorax/results/groups-only.dict @@ -0,0 +1 @@ +{'description': u'An example e-mail server.', 'packages': [], 'groups': [{'name': u'mail-server'}], 'modules': [], 'version': u'0.0.1', 'name': u'mail-server'} diff --git a/tests/pylorax/results/groups-only.toml b/tests/pylorax/results/groups-only.toml new file mode 100644 index 00000000..b9235832 --- /dev/null +++ b/tests/pylorax/results/groups-only.toml @@ -0,0 +1,6 @@ +name = "mail-server" +description = "An example e-mail server." +version = "0.0.1" + +[[groups]] +name = "mail-server" diff --git a/tests/pylorax/test_projects.py b/tests/pylorax/test_projects.py index d22f3b44..cca23a56 100644 --- a/tests/pylorax/test_projects.py +++ b/tests/pylorax/test_projects.py @@ -158,7 +158,7 @@ class ProjectsTest(unittest.TestCase): def test_projects_depsolve(self): deps = projects_depsolve(self.dbo, [("bash", "*.*")], []) self.assertTrue(len(deps) > 3) - self.assertEqual(deps[0]["name"], "basesystem") + self.assertTrue("basesystem" in [dep["name"] for dep in deps]) def test_projects_depsolve_version(self): """Test that depsolving with a partial wildcard version works""" @@ -195,6 +195,13 @@ class ProjectsTest(unittest.TestCase): self.assertEqual(modules[0]["name"], "bash") self.assertEqual(modules[0]["dependencies"][0]["name"], "basesystem") + def test_groups_depsolve(self): + deps = projects_depsolve(self.dbo, [], ["c-development"]) + names = [grp["name"] for grp in deps] + self.assertTrue("autoconf" in names) # mandatory package + self.assertTrue("ctags" in names) # default package + self.assertFalse("cmake" in names) # optional package + class ConfigureTest(unittest.TestCase): @classmethod diff --git a/tests/pylorax/test_recipes.py b/tests/pylorax/test_recipes.py index 3d5622f8..3b660189 100644 --- a/tests/pylorax/test_recipes.py +++ b/tests/pylorax/test_recipes.py @@ -32,6 +32,7 @@ class BasicRecipeTest(unittest.TestCase): ("minimal.toml", "minimal.dict"), ("modules-only.toml", "modules-only.dict"), ("packages-only.toml", "packages-only.dict"), + ("groups-only.toml", "groups-only.dict"), ("custom-base.toml", "custom-base.dict")] results_path = "./tests/pylorax/results/" self.input_toml = [] @@ -47,12 +48,16 @@ class BasicRecipeTest(unittest.TestCase): recipes.RecipeModule("httpd", "3.7.*")] self.old_packages = [recipes.RecipePackage("python", "2.7.*"), recipes.RecipePackage("parted", "3.2")] + self.old_groups = [recipes.RecipeGroup("backup-client"), + recipes.RecipeGroup("standard")] self.new_modules = [recipes.RecipeModule("toml", "2.1"), recipes.RecipeModule("httpd", "3.8.*"), recipes.RecipeModule("openssh", "2.8.1")] self.new_packages = [recipes.RecipePackage("python", "2.7.*"), recipes.RecipePackage("parted", "3.2"), recipes.RecipePackage("git", "2.13.*")] + self.new_groups = [recipes.RecipeGroup("console-internet"), + recipes.RecipeGroup("standard")] self.modules_result = [{"new": {"Modules": {"version": "2.8.1", "name": "openssh"}}, "old": None}, {"new": None, @@ -60,6 +65,9 @@ class BasicRecipeTest(unittest.TestCase): {"new": {"Modules": {"version": "3.8.*", "name": "httpd"}}, "old": {"Modules": {"version": "3.7.*", "name": "httpd"}}}] self.packages_result = [{"new": {"Packages": {"name": "git", "version": "2.13.*"}}, "old": None}] + self.groups_result = [{'new': {'Groups': {'name': 'console-internet'}}, 'old': None}, + {'new': None, 'old': {'Groups': {'name': 'backup-client'}}}] + @classmethod def tearDownClass(self): @@ -133,6 +141,7 @@ class BasicRecipeTest(unittest.TestCase): """Test the diff_items function""" self.assertEqual(recipes.diff_items("Modules", self.old_modules, self.new_modules), self.modules_result) self.assertEqual(recipes.diff_items("Packages", self.old_packages, self.new_packages), self.packages_result) + self.assertEqual(recipes.diff_items("Groups", self.old_groups, self.new_groups), self.groups_result) def recipe_diff_test(self): """Test the recipe_diff function""" diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index 5b413415..671a97bd 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -124,8 +124,9 @@ class ServerTestCase(unittest.TestCase): {"name": "php-mysqlnd", "version":"7.2.4"}], "name":"http-server", "packages": [{"name":"openssh-server", "version": "7.*"}, - {"name": "rsync", "version": "3.1.3"}, + {"name": "rsync", "version": "3.1.*"}, {"name": "tmux", "version": "2.7"}], + "groups": [], "version": "0.0.1"}]} resp = self.server.get("/api/v0/blueprints/info/http-server") data = json.loads(resp.data) @@ -141,6 +142,7 @@ class ServerTestCase(unittest.TestCase): {"name":"glusterfs-cli", "version":"4.0.*"}], "name":"glusterfs", "packages":[{"name":"samba", "version":"4.8.*"}], + "groups": [], "version": "0.0.1"}, {"description":"An example http server with PHP and MySQL support.", "modules":[{"name":"httpd", "version":"2.4.*"}, @@ -150,8 +152,9 @@ class ServerTestCase(unittest.TestCase): {"name": "php-mysqlnd", "version":"7.2.4"}], "name":"http-server", "packages": [{"name":"openssh-server", "version": "7.*"}, - {"name": "rsync", "version": "3.1.3"}, + {"name": "rsync", "version": "3.1.*"}, {"name": "tmux", "version": "2.7"}], + "groups": [], "version": "0.0.1"}, ]} resp = self.server.get("/api/v0/blueprints/info/http-server,glusterfs") @@ -197,7 +200,8 @@ class ServerTestCase(unittest.TestCase): "modules":[{"name":"glusterfs", "version":"4.0.*"}, {"name":"glusterfs-cli", "version":"4.0.*"}], "packages":[{"name":"samba", "version":"4.8.*"}, - {"name":"tmux", "version":"2.7"}]} + {"name":"tmux", "version":"2.7"}], + "groups": []} resp = self.server.post("/api/v0/blueprints/new", data=json.dumps(test_blueprint), @@ -231,6 +235,12 @@ class ServerTestCase(unittest.TestCase): test_blueprint = toml.loads(test_blueprint) test_blueprint["version"] = "0.2.1" + # The test_blueprint generated by toml.loads will not have any groups property + # defined, since there are no groups listed. However, /api/v0/blueprints/new will + # return an object with groups=[]. So, add that here to keep the equality test + # working. + test_blueprint["groups"] = [] + self.assertEqual(blueprints[0], test_blueprint) def test_07_blueprints_ws_json(self): @@ -241,7 +251,8 @@ class ServerTestCase(unittest.TestCase): "modules":[{"name":"glusterfs", "version":"4.0.*"}, {"name":"glusterfs-cli", "version":"4.0.*"}], "packages":[{"name":"samba", "version":"4.8.*"}, - {"name":"tmux", "version":"2.7"}]} + {"name":"tmux", "version":"2.7"}], + "groups": []} resp = self.server.post("/api/v0/blueprints/workspace", data=json.dumps(test_blueprint), @@ -267,7 +278,8 @@ class ServerTestCase(unittest.TestCase): "modules":[{"name":"glusterfs", "version":"4.0.*"}, {"name":"glusterfs-cli", "version":"4.0.*"}], "packages":[{"name":"samba", "version":"4.8.*"}, - {"name":"tmux", "version":"2.7"}]} + {"name":"tmux", "version":"2.7"}], + "groups": []} resp = self.server.post("/api/v0/blueprints/workspace", data=json.dumps(test_blueprint), @@ -491,7 +503,7 @@ class ServerTestCase(unittest.TestCase): self.assertNotEqual(data, None) deps = data.get("projects") self.assertEqual(len(deps) > 10, True) - self.assertEqual(deps[0]["name"], "basesystem") + self.assertTrue("basesystem" in [dep["name"] for dep in deps]) def test_projects_source_00_list(self): """Test /api/v0/projects/source/list""" @@ -654,7 +666,7 @@ class ServerTestCase(unittest.TestCase): modules = data.get("modules") self.assertEqual(len(modules) > 0, True) self.assertEqual(modules[0]["name"], "bash") - self.assertEqual(modules[0]["dependencies"][0]["name"], "basesystem") + self.assertTrue("basesystem" in [dep["name"] for dep in modules[0]["dependencies"]]) def test_blueprint_new_branch(self): """Test the /api/v0/blueprints/new route with a new branch""" @@ -664,7 +676,8 @@ class ServerTestCase(unittest.TestCase): "modules":[{"name":"glusterfs", "version":"4.0.*"}, {"name":"glusterfs-cli", "version":"4.0.*"}], "packages":[{"name":"samba", "version":"4.8.*"}, - {"name":"tmux", "version":"2.7"}]} + {"name":"tmux", "version":"2.7"}], + "groups": []} resp = self.server.post("/api/v0/blueprints/new?branch=test", data=json.dumps(test_blueprint),