Merge lp:~benji/charmworld/missing-head into lp:~juju-jitsu/charmworld/trunk

Proposed by Benji York
Status: Merged
Merged at revision: 430
Proposed branch: lp:~benji/charmworld/missing-head
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 54 lines (+22/-1)
2 files modified
charmworld/views/api/__init__.py (+3/-1)
charmworld/views/tests/test_api.py (+19/-0)
To merge this branch: bzr merge lp:~benji/charmworld/missing-head
Reviewer Review Type Date Requested Status
Juju-Jitsu Hackers Pending
Review via email: mp+192621@code.launchpad.net

Description of the change

Add handling for "-HEAD" revisions to API2

https://codereview.appspot.com/16950043/

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmworld/views/api/__init__.py'
2--- charmworld/views/api/__init__.py 2013-10-22 21:02:10 +0000
3+++ charmworld/views/api/__init__.py 2013-10-25 00:46:20 +0000
4@@ -749,10 +749,12 @@
5 def _find_charm(self, path):
6 charm_id, trailing = self._extract_charm_id(path)
7 try:
8- owner, series, name, revision = self._parse_charm_id(charm_id)
9+ owner, series, name, _ = self._parse_charm_id(charm_id)
10 except ValueError:
11 charm = None
12 else:
13+ if name.endswith('-HEAD'):
14+ name = name[:-5]
15 if owner is None:
16 charm = self.request.db.charms.find_one({
17 'promulgated': True,
18
19=== modified file 'charmworld/views/tests/test_api.py'
20--- charmworld/views/tests/test_api.py 2013-10-24 17:24:43 +0000
21+++ charmworld/views/tests/test_api.py 2013-10-25 00:46:20 +0000
22@@ -1641,6 +1641,15 @@
23 u'type': u'no_such_charm',
24 })
25
26+ def test_latest_revision_not_fetchable_with_HEAD_revision(self):
27+ # API2 understands a revision named "HEAD", API3 does not.
28+ kwargs = dict(owner='foo', series='bar', name='baz', promulgated=True)
29+ self.use_index_client()
30+ old_id, old_charm = self.make_charm(store_revision=1, **kwargs)
31+ new_id, new_charm = self.make_charm(store_revision=2, **kwargs)
32+ response = self.get_response('charm', remainder='bar/baz-HEAD')
33+ self.assertEqual(404, response.status_code)
34+
35 def test_charm_no_revision(self):
36 # Retrieving a charm with no revision results in the latest one.
37 self.use_index_client()
38@@ -1754,6 +1763,16 @@
39 response = self.get_response('charm', remainder=old_id)
40 self.assertEqual(response.json['charm']['id'], new_id)
41
42+ def test_latest_revision_fetchable_with_HEAD_revision(self):
43+ # If the charm_id specifies the name "HEAD" API2 should return the
44+ # latest revision.
45+ kwargs = dict(owner='foo', series='bar', name='baz', promulgated=True)
46+ self.use_index_client()
47+ old_id, old_charm = self.make_charm(store_revision=1, **kwargs)
48+ new_id, new_charm = self.make_charm(store_revision=2, **kwargs)
49+ response = self.get_response('charm', remainder='bar/baz-HEAD')
50+ self.assertEqual(response.json['charm']['id'], new_id)
51+
52 def test_charms_interesting_only_contain_charms(self):
53 self.use_index_client()
54 bundle = self.make_indexed_bundle()

Subscribers

People subscribed via source and target branches