Add DELETE /recipes/workspace/<recipe_name> route and tests

This will delete the workspace copy of the recipe.
This commit is contained in:
Brian C. Lane 2017-11-13 11:21:14 -08:00
parent 83e13c4ca8
commit 6e453e70dc
2 changed files with 34 additions and 1 deletions

View File

@ -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/<recipe_name>", 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)

View File

@ -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/<recipe_name>"""
# 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})