launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #18095
[Merge] lp:~cjwatson/turnip/nonexistent-repo into lp:turnip
Colin Watson has proposed merging lp:~cjwatson/turnip/nonexistent-repo into lp:turnip.
Commit message:
Return HTTP 404 when asked about a non-existent repository.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/turnip/nonexistent-repo/+merge/252604
Return HTTP 404 when asked about a non-existent repository.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/turnip/nonexistent-repo into lp:turnip.
=== modified file 'turnip/api/tests/test_api.py'
--- turnip/api/tests/test_api.py 2015-03-10 03:22:33 +0000
+++ turnip/api/tests/test_api.py 2015-03-11 16:06:51 +0000
@@ -59,6 +59,11 @@
resp_sha = body[ref]['object'].get('sha1')
self.assertEqual(oid, resp_sha)
+ def test_repo_get_refs_nonexistent(self):
+ """get_refs on a non-existent repository returns HTTP 404."""
+ resp = self.app.get('/repo/1/refs', expect_errors=True)
+ self.assertEqual(resp.status_code, 404)
+
def test_ignore_non_unicode_refs(self):
"""Ensure non-unicode refs are dropped from ref collection."""
factory = RepoFactory(self.repo_store)
@@ -89,6 +94,22 @@
resp = self.get_ref(ref)
self.assertTrue(ref in resp)
+ def test_repo_get_ref_nonexistent_repository(self):
+ """get_ref on a non-existent repository returns HTTP 404."""
+ resp = self.app.get('/repo/1/refs/heads/master', expect_errors=True)
+ self.assertEqual(resp.status_code, 404)
+
+ def test_repo_get_ref_nonexistent_ref(self):
+ """get_ref on a non-existent ref in a repository returns HTTP 404."""
+ RepoFactory(self.repo_store, num_commits=1).build()
+ resp = self.app.get(
+ '/repo/{}/refs/heads/master'.format(self.repo_path))
+ self.assertEqual(resp.status_code, 200)
+ resp = self.app.get(
+ '/repo/{}/refs/heads/nonexistent'.format(self.repo_path),
+ expect_errors=True)
+ self.assertEqual(resp.status_code, 404)
+
def test_repo_get_unicode_ref(self):
factory = RepoFactory(self.repo_store)
commit_oid = factory.add_commit('foo', 'foobar.txt')
=== modified file 'turnip/api/views.py'
--- turnip/api/views.py 2015-03-10 03:22:33 +0000
+++ turnip/api/views.py 2015-03-11 16:06:51 +0000
@@ -73,7 +73,7 @@
def collection_get(self, repo_path):
try:
refs = store.get_refs(repo_path)
- except GitError:
+ except (KeyError, GitError):
return exc.HTTPNotFound() # 404
return json.dumps(refs, ensure_ascii=False)
@@ -82,6 +82,6 @@
ref = 'refs/' + self.request.matchdict['ref']
try:
ref = store.get_ref(repo_path, ref)
- except GitError:
+ except (KeyError, GitError):
return exc.HTTPNotFound()
return json.dumps(ref, ensure_ascii=False)
Follow ups