Merge lp:~rharding/charmworld/bundle-metadata3 into lp:~juju-jitsu/charmworld/trunk

Proposed by Richard Harding
Status: Merged
Approved by: Richard Harding
Approved revision: 418
Merged at revision: 410
Proposed branch: lp:~rharding/charmworld/bundle-metadata3
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 109 lines (+49/-9)
2 files modified
charmworld/views/api.py (+20/-9)
charmworld/views/tests/test_api.py (+29/-0)
To merge this branch: bzr merge lp:~rharding/charmworld/bundle-metadata3
Reviewer Review Type Date Requested Status
Juju Gui Bot continuous-integration Approve
Benji York (community) Approve
Review via email: mp+189691@code.launchpad.net

Commit message

Update the search & interesting calls to include the bundle file/charm_metadata.

Brings up to match the bundle details call.

Description of the change

Update the search and interesting calls to include the bundle file/charm_metadata added to the details call.

- Added a path in the item_results to call a _bundle_result just as it does for _charm_result.
- _bundle_result does the work sharing the methods to find the list of files and the charm details for the bundle before adding to the result list.
- Drive by fixing a bug where the series was pulled from the wrong place in the bundle json. Made sure a functional test in the search results verified that the name/series combo works for finding charms that are promulgated.
- Only added tests to search since they share the same code paths and the interesting already has tests that bundles go through the interesting call.

QA:

Perform a search for wiki and verify that the bundle results have the two added fields of metadata.

http://charmworld:2464/api/3/search/?text=wiki

To post a comment you must log in.
417. By Richard Harding

Sync with trunk

Revision history for this message
Benji York (benji) wrote :

The branch looks good.

The _bundle_result class method could use a docstring (and perhaps a different name, but I can't think of an improvement right now). Also, how about "bundle_metadata" instead of "bundle_built"?

review: Approve
418. By Richard Harding

Update per review

Revision history for this message
Juju Gui Bot (juju-gui-bot) :
review: Approve (continuous-integration)

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-10-07 12:10:22 +0000
+++ charmworld/views/api.py 2013-10-07 19:56:38 +0000
@@ -182,6 +182,18 @@
182 }182 }
183 }183 }
184184
185 @classmethod
186 def _bundle_result(cls, bundle, db):
187 """Build standard metadata around a bundle search result."""
188 bundle_obj = Bundle(bundle)
189 bundle_metadata = cls._build_bundle_metadata(bundle_obj, db)
190 return {
191 'bundle': bundle_metadata,
192 'metadata': {
193 'doctype': BUNDLE,
194 }
195 }
196
185 def _related_charms(self, charm_data):197 def _related_charms(self, charm_data):
186 charm = Charm(charm_data)198 charm = Charm(charm_data)
187 charms_provide = set(charm.i_provides)199 charms_provide = set(charm.i_provides)
@@ -428,21 +440,23 @@
428 query, sort=[('store_data.revision', pymongo.DESCENDING)])440 query, sort=[('store_data.revision', pymongo.DESCENDING)])
429 return charm_id, trailing, charm441 return charm_id, trailing, charm
430442
431 def _build_bundle_metadata(self, bundle, db):443 @classmethod
444 def _build_bundle_metadata(cls, bundle, db):
432 bundle_dict = dict(bundle)445 bundle_dict = dict(bundle)
433 # Add the list of files in the bundle.446 # Add the list of files in the bundle.
434 bundle_dict['files'] = bundle.get_file_list(db)447 bundle_dict['files'] = bundle.get_file_list(db)
435 bundle_dict['charm_metadata'] = {}448 bundle_dict['charm_metadata'] = {}
449 service_data = bundle_dict.get('data')
436 # Now load the charm information we require for the services in the450 # Now load the charm information we require for the services in the
437 # bundle.451 # bundle.
438 for service, data in bundle.data['services'].iteritems():452 for service, data in bundle.data['services'].iteritems():
439 charm = resolve_charm_from_bundle_info(453 charm = resolve_charm_from_bundle_info(
440 db,454 db,
441 data,455 data,
442 bundle_dict.get('series')456 service_data.get('series')
443 )457 )
444 if charm:458 if charm:
445 formatted = self._format_charm(Charm(charm))459 formatted = cls._format_charm(Charm(charm))
446 bundle_dict['charm_metadata'][service] = formatted460 bundle_dict['charm_metadata'][service] = formatted
447461
448 return bundle_dict462 return bundle_dict
@@ -656,12 +670,9 @@
656 results = []670 results = []
657 for item in items:671 for item in items:
658 if item['doctype'] == BUNDLE:672 if item['doctype'] == BUNDLE:
659 result = {673 result = self._bundle_result(
660 'bundle': Bundle(item['data'])._representation,674 Bundle(item['data'])._representation,
661 'metadata': {675 self.request.db)
662 'doctype': BUNDLE,
663 }
664 }
665 else:676 else:
666 result = self._charm_result(Charm(item['data']))677 result = self._charm_result(Charm(item['data']))
667 results.append(result)678 results.append(result)
668679
=== modified file 'charmworld/views/tests/test_api.py'
--- charmworld/views/tests/test_api.py 2013-10-07 14:23:34 +0000
+++ charmworld/views/tests/test_api.py 2013-10-07 19:56:38 +0000
@@ -1528,10 +1528,39 @@
1528 found_bundle = result[0]1528 found_bundle = result[0]
1529 self.assertEqual(BUNDLE, found_bundle['metadata']['doctype'])1529 self.assertEqual(BUNDLE, found_bundle['metadata']['doctype'])
1530 self.assertEqual(bundle.name, found_bundle['bundle']['name'])1530 self.assertEqual(bundle.name, found_bundle['bundle']['name'])
1531 # Bundles have been adjusted to include filenames
1532 self.assertEqual([], found_bundle['bundle']['files'])
1533 # Bundles also include charm metadata
1534 self.assertEqual({}, found_bundle['bundle']['charm_metadata'])
1535
1531 found_charm = result[1]1536 found_charm = result[1]
1532 self.assertEqual(CHARM, found_charm['metadata']['doctype'])1537 self.assertEqual(CHARM, found_charm['metadata']['doctype'])
1533 self.assertEqual(charm['store_url'], found_charm['charm']['url'])1538 self.assertEqual(charm['store_url'], found_charm['charm']['url'])
15341539
1540 def test_search_result_bundles_includes_metadata(self):
1541 self.use_index_client()
1542 _id, charm = factory.makeCharm(self.db, promulgated=True)
1543 services = {
1544 u'charm': {
1545 u'charm': charm['name']
1546 }
1547 }
1548 bundle = self.make_indexed_bundle(
1549 series=charm['series'],
1550 services=services,
1551 with_basket=True)
1552
1553 factory.make_bundle_file(self.db, bundle, u'README', 'Test Content')
1554 result = self.get_response(self.search_endpoint).json_body['result']
1555 self.assertEqual(1, len(result))
1556 found_bundle = result[0]['bundle']
1557 self.assertEqual(['README'], found_bundle['files'])
1558 self.assertTrue(found_bundle['charm_metadata']['charm'])
1559 self.assertEqual(
1560 charm['name'],
1561 found_bundle['charm_metadata']['charm']['name']
1562 )
1563
1535 def test_charm_wrong_revision(self):1564 def test_charm_wrong_revision(self):
1536 """Retrieving a charm does not work if the revision is wrong."""1565 """Retrieving a charm does not work if the revision is wrong."""
1537 self.use_index_client()1566 self.use_index_client()

Subscribers

People subscribed via source and target branches