From 6e453e70dcd41d637c4ac8f51cd112e0a7323fea Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 13 Nov 2017 11:21:14 -0800 Subject: [PATCH] Add DELETE /recipes/workspace/ route and tests This will delete the workspace copy of the recipe. --- src/pylorax/api/v0.py | 14 +++++++++++++- tests/pylorax/test_server.py | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 1c2bc6e4..e1d49dcf 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -23,7 +23,7 @@ from pykickstart.version import makeVersion, RHEL7 from pylorax.api.crossdomain import crossdomain from pylorax.api.recipes import list_branch_files, read_recipe_commit, recipe_filename, list_commits from pylorax.api.recipes import recipe_from_dict, recipe_from_toml, commit_recipe -from pylorax.api.workspace import workspace_read, workspace_write +from pylorax.api.workspace import workspace_read, workspace_write, workspace_delete from pylorax.creator import DRACUT_DEFAULT, mount_boot_part_over_root from pylorax.creator import make_appliance, make_image, make_livecd, make_live_images from pylorax.creator import make_runtime, make_squashfs @@ -180,3 +180,15 @@ def v0_api(api): return jsonify(status=False, error={"msg":str(e)}), 400 else: return jsonify(status=True) + + @api.route("/api/v0/recipes/workspace/", methods=["DELETE"]) + @crossdomain(origin="*") + def v0_recipes_delete_workspace(recipe_name): + """Delete a recipe from the workspace""" + try: + with api.config["GITLOCK"].lock: + workspace_delete(api.config["GITLOCK"].repo, "master", recipe_name) + except Exception as e: + return jsonify(status=False, error={"msg":str(e)}), 400 + else: + return jsonify(status=True) diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index f35e5142..c9913ca2 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -222,3 +222,24 @@ class ServerTestCase(unittest.TestCase): changes = data.get("changes") self.assertEqual(len(changes), 1) self.assertEqual(changes[0], {"name":"glusterfs", "changed":True}) + + def test_recipes_ws_delete(self): + """Test DELETE /api/v0/recipes/workspace/""" + # Write to the workspace first, just use the test_recipes_ws_json test for this + self.test_recipes_ws_json() + + # Delete it + resp = self.server.delete("/api/v0/recipes/workspace/glusterfs") + data = json.loads(resp.data) + self.assertEqual(data, {"status":True}) + + # Make sure it isn't the workspace copy and that changed is False + resp = self.server.get("/api/v0/recipes/info/glusterfs") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + recipes = data.get("recipes") + self.assertEqual(len(recipes), 1) + self.assertEqual(recipes[0]["version"], "0.2.1") + changes = data.get("changes") + self.assertEqual(len(changes), 1) + self.assertEqual(changes[0], {"name":"glusterfs", "changed":False})