From ab0655d5a97a65d8bf1eb35211aea646f773214b 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. --- tests/pylorax/results/groups-only.dict | 1 + tests/pylorax/results/groups-only.toml | 6 ++++++ tests/pylorax/test_projects.py | 11 +++++++++-- tests/pylorax/test_recipes.py | 9 +++++++++ tests/pylorax/test_server.py | 26 ++++++++++++++++++++------ 5 files changed, 45 insertions(+), 8 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 1a062e7e..94abd68b 100644 --- a/tests/pylorax/test_projects.py +++ b/tests/pylorax/test_projects.py @@ -184,7 +184,7 @@ class ProjectsTest(unittest.TestCase): def test_projects_depsolve(self): deps = projects_depsolve(self.yb, [("bash", "*.*")], []) self.assertTrue(len(deps) > 3) - self.assertEqual(deps[2]["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""" @@ -225,13 +225,20 @@ class ProjectsTest(unittest.TestCase): self.assertTrue(len(modules) > 0) self.assertTrue(len(modules[0]["dependencies"]) > 3) self.assertEqual(modules[0]["name"], "bash") - self.assertEqual(modules[0]["dependencies"][2]["name"], "basesystem") + self.assertTrue("basesystem" in [dep["name"] for dep in modules[0]["dependencies"]]) def test_modules_info_yum_raises_exception(self): with self.assertRaises(ProjectsError): with mock.patch.object(self.yb, 'doPackageLists', side_effect=YumBaseError('TESTING')): modules_info(self.yb, ["bash"]) + def test_groups_depsolve(self): + deps = projects_depsolve(self.yb, [], ["base"]) + names = [grp["name"] for grp in deps] + self.assertTrue("acl" in names) # mandatory package + self.assertTrue("bash-completion" in names) # default package + self.assertFalse("gpm" 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..73a65640 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("base")] 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("base")] 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 b1964875..50f1b37d 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -119,6 +119,7 @@ class ServerTestCase(unittest.TestCase): "packages": [{"name":"openssh-server", "version": "7.*"}, {"name": "rsync", "version": "3.1.*"}, {"name": "tmux", "version": "1.8"}], + "groups": [], "version": "0.0.1"}]} resp = self.server.get("/api/v0/blueprints/info/http-server") data = json.loads(resp.data) @@ -132,6 +133,7 @@ class ServerTestCase(unittest.TestCase): {"name":"glusterfs-cli", "version":"3.8.*"}], "name":"glusterfs", "packages":[{"name":"samba", "version":"4.7.*"}], + "groups": [], "version": "0.0.1"}, {"description":"An example http server with PHP and MySQL support.", "modules":[{"name":"httpd", "version":"2.4.*"}, @@ -143,6 +145,7 @@ class ServerTestCase(unittest.TestCase): "packages": [{"name":"openssh-server", "version": "7.*"}, {"name": "rsync", "version": "3.1.*"}, {"name": "tmux", "version": "1.8"}], + "groups": [], "version": "0.0.1"}, ]} resp = self.server.get("/api/v0/blueprints/info/http-server,glusterfs") @@ -186,7 +189,8 @@ class ServerTestCase(unittest.TestCase): "modules":[{"name":"glusterfs", "version":"3.8.*"}, {"name":"glusterfs-cli", "version":"3.8.*"}], "packages":[{"name":"samba", "version":"4.7.*"}, - {"name":"tmux", "version":"1.8"}]} + {"name":"tmux", "version":"1.8"}], + "groups": []} resp = self.server.post("/api/v0/blueprints/new", data=json.dumps(test_blueprint), @@ -220,6 +224,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): @@ -230,7 +240,8 @@ class ServerTestCase(unittest.TestCase): "modules":[{"name":"glusterfs", "version":"3.8.*"}, {"name":"glusterfs-cli", "version":"3.8.*"}], "packages":[{"name":"samba", "version":"4.7.*"}, - {"name":"tmux", "version":"1.8"}]} + {"name":"tmux", "version":"1.8"}], + "groups": []} resp = self.server.post("/api/v0/blueprints/workspace", data=json.dumps(test_blueprint), @@ -256,7 +267,8 @@ class ServerTestCase(unittest.TestCase): "modules":[{"name":"glusterfs", "version":"3.8.*"}, {"name":"glusterfs-cli", "version":"3.8.*"}], "packages":[{"name":"samba", "version":"4.7.*"}, - {"name":"tmux", "version":"1.8"}]} + {"name":"tmux", "version":"1.8"}], + "groups": []} resp = self.server.post("/api/v0/blueprints/workspace", data=json.dumps(test_blueprint), @@ -478,7 +490,7 @@ class ServerTestCase(unittest.TestCase): self.assertNotEqual(data, None) deps = data.get("projects") self.assertEqual(len(deps) > 10, True) - self.assertEqual(deps[2]["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""" @@ -632,7 +644,8 @@ class ServerTestCase(unittest.TestCase): modules = data.get("modules") self.assertEqual(len(modules), 1) self.assertEqual(modules[0]["name"], "bash") - self.assertEqual(modules[0]["dependencies"][2]["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""" @@ -642,7 +655,8 @@ class ServerTestCase(unittest.TestCase): "modules":[{"name":"glusterfs", "version":"3.8.*"}, {"name":"glusterfs-cli", "version":"3.8.*"}], "packages":[{"name":"samba", "version":"4.7.*"}, - {"name":"tmux", "version":"1.8"}]} + {"name":"tmux", "version":"1.8"}], + "groups": []} resp = self.server.post("/api/v0/blueprints/new?branch=test", data=json.dumps(test_blueprint),