← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ilasc/turnip:nonexitent-repo-repack-gc into turnip:master

 

Ioana Lasc has proposed merging ~ilasc/turnip:nonexitent-repo-repack-gc into turnip:master.

Commit message:
Add check for nonexitent repo to repack and gc api

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ilasc/turnip/+git/turnip/+merge/401623
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/turnip:nonexitent-repo-repack-gc into turnip:master.
diff --git a/turnip/api/tests/test_api.py b/turnip/api/tests/test_api.py
index 85683b1..419e72e 100644
--- a/turnip/api/tests/test_api.py
+++ b/turnip/api/tests/test_api.py
@@ -834,12 +834,22 @@ class ApiTestCase(TestCase, ApiRepoStoreMixin):
 
     def test_repo_repack(self):
         """Ensure commit exists in pack."""
+        factory = RepoFactory(self.repo_store, num_branches=2, num_commits=1)
+        factory.build()
         resp = self.app.post_json('/repo/{}/repack'.format(self.repo_path))
         self.assertEqual(200, resp.status_code)
+        # test for nonexistent repositories
+        resp = self.app.post_json('/repo/nonexistent/repack', expect_errors=True)
+        self.assertEqual(404, resp.status_code)
 
     def test_repo_gc(self):
+        factory = RepoFactory(self.repo_store, num_branches=2, num_commits=1)
+        factory.build()
         resp = self.app.post_json('/repo/{}/gc'.format(self.repo_path))
         self.assertEqual(200, resp.status_code)
+        # test for nonexistent repositories
+        resp = self.app.post_json('/repo/nonexistent/gc', expect_errors=True)
+        self.assertEqual(404, resp.status_code)
 
     def test_repo_detect_merges_missing_target(self):
         """A non-existent target OID returns HTTP 404."""
diff --git a/turnip/api/views.py b/turnip/api/views.py
index 6f9c410..26a2dc3 100644
--- a/turnip/api/views.py
+++ b/turnip/api/views.py
@@ -143,6 +143,11 @@ class RepackAPI(BaseAPI):
     @validate_path
     def post(self, repo_store, repo_name):
         repo_path = os.path.join(repo_store, repo_name)
+        repo_path = os.path.join(repo_store, repo_name)
+        if not os.path.exists(repo_path):
+            self.request.errors.add(
+                'body', 'name', 'repository does not exist')
+            raise exc.HTTPNotFound()
         kwargs = dict(repo_path=repo_path)
         store.repack.apply_async(kwargs=kwargs)
         return Response(status=200)
@@ -159,6 +164,11 @@ class GarbageCollectAPI(BaseAPI):
     @validate_path
     def post(self, repo_store, repo_name):
         repo_path = os.path.join(repo_store, repo_name)
+        repo_path = os.path.join(repo_store, repo_name)
+        if not os.path.exists(repo_path):
+            self.request.errors.add(
+                'body', 'name', 'repository does not exist')
+            raise exc.HTTPNotFound()
         kwargs = dict(repo_path=repo_path)
         store.gc.apply_async(kwargs=kwargs)
         return Response(status=200)