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
1=== modified file 'charmworld/views/api.py'
2--- charmworld/views/api.py 2013-08-02 16:50:53 +0000
3+++ charmworld/views/api.py 2013-08-06 20:57:27 +0000
4@@ -324,8 +324,10 @@
5 charm = None
6 return charm_id, trailing, charm
7
8- def charm(self, path):
9+ def charm(self, path=None):
10 """Retrieve a charm according to its charm_id."""
11+ if path is None:
12+ raise HTTPNotFound(self.request.path)
13 charm_id, trailing, charm_data = self._find_charm(path)
14 if charm_data is None:
15 return json_response(
16@@ -344,8 +346,10 @@
17 else:
18 raise HTTPNotFound(self.request.path)
19
20- def bundle(self, path):
21+ def bundle(self, path=None):
22 """Retrieve a bundle based on id."""
23+ if path is None:
24+ raise HTTPNotFound(self.request.path)
25 fullpath = '/'.join(path)
26 if len(path) == 3:
27 # We have an owner.
28
29=== modified file 'charmworld/views/tests/test_api.py'
30--- charmworld/views/tests/test_api.py 2013-08-01 13:05:57 +0000
31+++ charmworld/views/tests/test_api.py 2013-08-06 20:57:27 +0000
32@@ -669,6 +669,10 @@
33 response = self.get_response('bundle', 'foo/bar')
34 self.assertEqual(404, response.status_code)
35
36+ def test_no_path(self):
37+ with self.assertRaises(HTTPNotFound):
38+ response = self.get_response('bundle', remainder=None)
39+
40 def test_valid_lookup_unpromulgated(self):
41 self.makeBundle(name='bat', owner='bac', basket='byobu-4')
42 response = self.get_response('bundle', '~bac/byobu-4/bat')
43@@ -836,6 +840,9 @@
44 self.assertEqual(404, response.status_code)
45 self.assertEqual({'type': 'no_such_charm', 'charm_id': 'foo'},
46 response.json_body)
47+ def test_no_path(self):
48+ with self.assertRaises(HTTPNotFound):
49+ response = self.get_response('charm', remainder=None)
50
51 @staticmethod
52 def get_id(charm):

Subscribers

People subscribed via source and target branches