Merge lp:~bac/charmworld/bug-1208035 into lp:~juju-jitsu/charmworld/trunk

Proposed by Brad Crittenden
Status: Merged
Approved by: Brad Crittenden
Approved revision: 336
Merged at revision: 337
Proposed branch: lp:~bac/charmworld/bug-1208035
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 52 lines (+13/-2)
2 files modified
charmworld/views/api.py (+6/-2)
charmworld/views/tests/test_api.py (+7/-0)
To merge this branch: bzr merge lp:~bac/charmworld/bug-1208035
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+178849@code.launchpad.net

Commit message

Return a 404 if no path information is passed to API URL for charm or bundle.

Description of the change

If the API URL for a charm or bundle is hit with no path information the handler was throwing an error as the path was non-optional, e.g.

http://staging.jujucharms.com/api/2/bundle
or
http://staging.jujucharms.com/api/2/charm

This branch allows the path to be empty but returns a 404 instead.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmworld/views/api.py'
--- charmworld/views/api.py 2013-08-02 16:50:53 +0000
+++ charmworld/views/api.py 2013-08-06 20:57:27 +0000
@@ -324,8 +324,10 @@
324 charm = None324 charm = None
325 return charm_id, trailing, charm325 return charm_id, trailing, charm
326326
327 def charm(self, path):327 def charm(self, path=None):
328 """Retrieve a charm according to its charm_id."""328 """Retrieve a charm according to its charm_id."""
329 if path is None:
330 raise HTTPNotFound(self.request.path)
329 charm_id, trailing, charm_data = self._find_charm(path)331 charm_id, trailing, charm_data = self._find_charm(path)
330 if charm_data is None:332 if charm_data is None:
331 return json_response(333 return json_response(
@@ -344,8 +346,10 @@
344 else:346 else:
345 raise HTTPNotFound(self.request.path)347 raise HTTPNotFound(self.request.path)
346348
347 def bundle(self, path):349 def bundle(self, path=None):
348 """Retrieve a bundle based on id."""350 """Retrieve a bundle based on id."""
351 if path is None:
352 raise HTTPNotFound(self.request.path)
349 fullpath = '/'.join(path)353 fullpath = '/'.join(path)
350 if len(path) == 3:354 if len(path) == 3:
351 # We have an owner.355 # We have an owner.
352356
=== modified file 'charmworld/views/tests/test_api.py'
--- charmworld/views/tests/test_api.py 2013-08-01 13:05:57 +0000
+++ charmworld/views/tests/test_api.py 2013-08-06 20:57:27 +0000
@@ -669,6 +669,10 @@
669 response = self.get_response('bundle', 'foo/bar')669 response = self.get_response('bundle', 'foo/bar')
670 self.assertEqual(404, response.status_code)670 self.assertEqual(404, response.status_code)
671671
672 def test_no_path(self):
673 with self.assertRaises(HTTPNotFound):
674 response = self.get_response('bundle', remainder=None)
675
672 def test_valid_lookup_unpromulgated(self):676 def test_valid_lookup_unpromulgated(self):
673 self.makeBundle(name='bat', owner='bac', basket='byobu-4')677 self.makeBundle(name='bat', owner='bac', basket='byobu-4')
674 response = self.get_response('bundle', '~bac/byobu-4/bat')678 response = self.get_response('bundle', '~bac/byobu-4/bat')
@@ -836,6 +840,9 @@
836 self.assertEqual(404, response.status_code)840 self.assertEqual(404, response.status_code)
837 self.assertEqual({'type': 'no_such_charm', 'charm_id': 'foo'},841 self.assertEqual({'type': 'no_such_charm', 'charm_id': 'foo'},
838 response.json_body)842 response.json_body)
843 def test_no_path(self):
844 with self.assertRaises(HTTPNotFound):
845 response = self.get_response('charm', remainder=None)
839846
840 @staticmethod847 @staticmethod
841 def get_id(charm):848 def get_id(charm):

Subscribers

People subscribed via source and target branches