From ab6decec0bd8813f8a31f1b5a737e40a51f2c4bd Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 13 Nov 2017 15:04:49 -0800 Subject: [PATCH] Add revert_recipe function And adjust the tests to use it so that it covers both revert_recipe and revert_file. --- src/pylorax/api/recipes.py | 17 +++++++++++++++++ tests/pylorax/test_recipes.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/pylorax/api/recipes.py b/src/pylorax/api/recipes.py index 65885f90..87429ea7 100644 --- a/src/pylorax/api/recipes.py +++ b/src/pylorax/api/recipes.py @@ -379,6 +379,23 @@ def delete_file(repo, branch, filename): message = "Recipe %s deleted" % filename return repo.create_commit(ref, sig, sig, "UTF-8", message, tree, [parent_commit]) +def revert_recipe(repo, branch, recipe_name, commit): + """Revert the contents of a recipe to that of a previous commit + + :param repo: Open repository + :type repo: Git.Repository + :param branch: Branch name + :type branch: str + :param recipe_name: Recipe name to revert + :type recipe_name: str + :param commit: Commit hash + :type commit: str + :returns: OId of the new commit + :rtype: Git.OId + :raises: Can raise errors from Ggit + """ + return revert_file(repo, branch, recipe_filename(recipe_name), commit) + def revert_file(repo, branch, filename, commit): """Revert the contents of a file to that of a previous commit diff --git a/tests/pylorax/test_recipes.py b/tests/pylorax/test_recipes.py index fc935763..6f1b2277 100644 --- a/tests/pylorax/test_recipes.py +++ b/tests/pylorax/test_recipes.py @@ -184,7 +184,7 @@ class GitRecipesTest(unittest.TestCase): """Test reverting a file on a branch""" commits = recipes.list_commits(self.repo, "master", "http-server.toml") revert_to = commits[0].commit - oid = recipes.revert_file(self.repo, "master", "http-server.toml", revert_to) + oid = recipes.revert_recipe(self.repo, "master", "http-server", revert_to) self.assertNotEqual(oid, None) commits = recipes.list_commits(self.repo, "master", "http-server.toml")