Merge lp:~abentley/charmworld/use-latest-charm into lp:~juju-jitsu/charmworld/trunk

Proposed by Aaron Bentley
Status: Merged
Approved by: Aaron Bentley
Approved revision: 376
Merged at revision: 377
Proposed branch: lp:~abentley/charmworld/use-latest-charm
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 111 lines (+41/-4)
5 files modified
charmworld/testing/factory.py (+1/-1)
charmworld/views/api.py (+2/-2)
charmworld/views/charms.py (+2/-1)
charmworld/views/tests/test_api.py (+20/-0)
charmworld/views/tests/test_charms.py (+16/-0)
To merge this branch: bzr merge lp:~abentley/charmworld/use-latest-charm
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+183661@code.launchpad.net

Commit message

Ensure latest version of charm is shown.

Description of the change

On API 2, on the old JSON API and on charm pages, the latest version of the charm was not being selected. (Bugs 1219061, 1219062, 1219064). This branch fixes it by sorting by revision.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmworld/testing/factory.py'
--- charmworld/testing/factory.py 2013-08-27 14:39:13 +0000
+++ charmworld/testing/factory.py 2013-09-03 13:32:38 +0000
@@ -146,7 +146,7 @@
146146
147def add_store_data(charm, promulgated=False, charm_error=False, revision=1):147def add_store_data(charm, promulgated=False, charm_error=False, revision=1):
148 address = get_address(charm, promulgated)148 address = get_address(charm, promulgated)
149 charm["store_url"] = make_store_url(1, address)149 charm["store_url"] = make_store_url(revision, address)
150 store_data = {150 store_data = {
151 "store_checked": "Thu Dec 6 17:42:05 2012"151 "store_checked": "Thu Dec 6 17:42:05 2012"
152 }152 }
153153
=== modified file 'charmworld/views/api.py'
--- charmworld/views/api.py 2013-08-29 18:42:06 +0000
+++ charmworld/views/api.py 2013-09-03 13:32:38 +0000
@@ -591,13 +591,13 @@
591 'promulgated': True,591 'promulgated': True,
592 'series': series,592 'series': series,
593 'name': name,593 'name': name,
594 })594 }, sort=[('store_data.revision', pymongo.DESCENDING)])
595 else:595 else:
596 charm = self.request.db.charms.find_one({596 charm = self.request.db.charms.find_one({
597 'owner': owner,597 'owner': owner,
598 'series': series,598 'series': series,
599 'name': name,599 'name': name,
600 })600 }, sort=[('store_data.revision', pymongo.DESCENDING)])
601 if charm is not None:601 if charm is not None:
602 api_id = self._get_api_id(Charm(charm))602 api_id = self._get_api_id(Charm(charm))
603 # Charm ID should match up to, but not including the revision.603 # Charm ID should match up to, but not including the revision.
604604
=== modified file 'charmworld/views/charms.py'
--- charmworld/views/charms.py 2013-08-28 21:53:44 +0000
+++ charmworld/views/charms.py 2013-09-03 13:32:38 +0000
@@ -287,7 +287,8 @@
287 spec["promulgated"] = True287 spec["promulgated"] = True
288 else:288 else:
289 spec["owner"] = request.matchdict['owner']289 spec["owner"] = request.matchdict['owner']
290 charm_data = found(request.db.charms.find_one(spec))290 charm_data = found(request.db.charms.find_one(
291 spec, sort=[('store_data.revision', pymongo.DESCENDING)]))
291 # We are phasing out is_featured from the charm data, so remove it if this292 # We are phasing out is_featured from the charm data, so remove it if this
292 # is an old charm record that still has it.293 # is an old charm record that still has it.
293 charm_data.pop('is_featured', None)294 charm_data.pop('is_featured', None)
294295
=== modified file 'charmworld/views/tests/test_api.py'
--- charmworld/views/tests/test_api.py 2013-08-30 13:29:38 +0000
+++ charmworld/views/tests/test_api.py 2013-09-03 13:32:38 +0000
@@ -1553,6 +1553,26 @@
1553 self.assertEqual(200, response.status_code)1553 self.assertEqual(200, response.status_code)
1554 self.assertEqual(charm, response.json_body)1554 self.assertEqual(charm, response.json_body)
15551555
1556 def test_latest_revision_unpromulgated(self):
1557 # API2 should always return the latest revision, even if the charm_id
1558 # specifies a newer one.
1559 kwargs = dict(owner='foo', series='bar', name='baz', promulgated=False)
1560 self.use_index_client()
1561 old_id, old_charm = self.make_charm(store_revision=1, **kwargs)
1562 new_id, new_charm = self.make_charm(store_revision=2, **kwargs)
1563 response = self.get_response('charm', remainder=old_id)
1564 self.assertEqual(response.json['charm']['id'], new_id)
1565
1566 def test_latest_revision_promulgated(self):
1567 # API2 should always return the latest revision, even if the charm_id
1568 # specifies a newer one.
1569 kwargs = dict(owner='foo', series='bar', name='baz', promulgated=True)
1570 self.use_index_client()
1571 old_id, old_charm = self.make_charm(store_revision=1, **kwargs)
1572 new_id, new_charm = self.make_charm(store_revision=2, **kwargs)
1573 response = self.get_response('charm', remainder=old_id)
1574 self.assertEqual(response.json['charm']['id'], new_id)
1575
1556 def test_charms_interesting_only_contain_charms(self):1576 def test_charms_interesting_only_contain_charms(self):
1557 self.use_index_client()1577 self.use_index_client()
1558 bundle = self.make_indexed_bundle()1578 bundle = self.make_indexed_bundle()
15591579
=== modified file 'charmworld/views/tests/test_charms.py'
--- charmworld/views/tests/test_charms.py 2013-08-29 18:36:12 +0000
+++ charmworld/views/tests/test_charms.py 2013-09-03 13:32:38 +0000
@@ -33,6 +33,7 @@
33 config,33 config,
34 distro_charm,34 distro_charm,
35 distro_charm_json,35 distro_charm_json,
36 find_charm,
36 found_charm_collection,37 found_charm_collection,
37 hook,38 hook,
38 interface,39 interface,
@@ -476,6 +477,21 @@
476 self.assertEqual(expect, response['icon_path'])477 self.assertEqual(expect, response['icon_path'])
477478
478479
480class TestFindCharm(ViewTestBase):
481
482 def test_find_charm_selects_latest_revision(self):
483 kwargs = dict(owner='foo', series='bar', name='baz')
484 old_id, old_charm = factory.makeCharm(self.db, store_revision=1,
485 **kwargs)
486 new_id, new_charm = factory.makeCharm(self.db, store_revision=2,
487 **kwargs)
488 request = self.getRequest()
489 request.matchdict.update(kwargs)
490 request.matchdict['charm'] = kwargs['name']
491 charm_data = find_charm(request)
492 self.assertEqual(new_id, charm_data['_id'])
493
494
479class CharmsViewHelpersTestCase(ViewTestBase):495class CharmsViewHelpersTestCase(ViewTestBase):
480496
481 def test_reconcile_revision_with_dashed_name(self):497 def test_reconcile_revision_with_dashed_name(self):

Subscribers

People subscribed via source and target branches