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
1=== modified file 'charmworld/views/api.py'
2--- charmworld/views/api.py 2013-10-07 12:10:22 +0000
3+++ charmworld/views/api.py 2013-10-07 19:56:38 +0000
4@@ -182,6 +182,18 @@
5 }
6 }
7
8+ @classmethod
9+ def _bundle_result(cls, bundle, db):
10+ """Build standard metadata around a bundle search result."""
11+ bundle_obj = Bundle(bundle)
12+ bundle_metadata = cls._build_bundle_metadata(bundle_obj, db)
13+ return {
14+ 'bundle': bundle_metadata,
15+ 'metadata': {
16+ 'doctype': BUNDLE,
17+ }
18+ }
19+
20 def _related_charms(self, charm_data):
21 charm = Charm(charm_data)
22 charms_provide = set(charm.i_provides)
23@@ -428,21 +440,23 @@
24 query, sort=[('store_data.revision', pymongo.DESCENDING)])
25 return charm_id, trailing, charm
26
27- def _build_bundle_metadata(self, bundle, db):
28+ @classmethod
29+ def _build_bundle_metadata(cls, bundle, db):
30 bundle_dict = dict(bundle)
31 # Add the list of files in the bundle.
32 bundle_dict['files'] = bundle.get_file_list(db)
33 bundle_dict['charm_metadata'] = {}
34+ service_data = bundle_dict.get('data')
35 # Now load the charm information we require for the services in the
36 # bundle.
37 for service, data in bundle.data['services'].iteritems():
38 charm = resolve_charm_from_bundle_info(
39 db,
40 data,
41- bundle_dict.get('series')
42+ service_data.get('series')
43 )
44 if charm:
45- formatted = self._format_charm(Charm(charm))
46+ formatted = cls._format_charm(Charm(charm))
47 bundle_dict['charm_metadata'][service] = formatted
48
49 return bundle_dict
50@@ -656,12 +670,9 @@
51 results = []
52 for item in items:
53 if item['doctype'] == BUNDLE:
54- result = {
55- 'bundle': Bundle(item['data'])._representation,
56- 'metadata': {
57- 'doctype': BUNDLE,
58- }
59- }
60+ result = self._bundle_result(
61+ Bundle(item['data'])._representation,
62+ self.request.db)
63 else:
64 result = self._charm_result(Charm(item['data']))
65 results.append(result)
66
67=== modified file 'charmworld/views/tests/test_api.py'
68--- charmworld/views/tests/test_api.py 2013-10-07 14:23:34 +0000
69+++ charmworld/views/tests/test_api.py 2013-10-07 19:56:38 +0000
70@@ -1528,10 +1528,39 @@
71 found_bundle = result[0]
72 self.assertEqual(BUNDLE, found_bundle['metadata']['doctype'])
73 self.assertEqual(bundle.name, found_bundle['bundle']['name'])
74+ # Bundles have been adjusted to include filenames
75+ self.assertEqual([], found_bundle['bundle']['files'])
76+ # Bundles also include charm metadata
77+ self.assertEqual({}, found_bundle['bundle']['charm_metadata'])
78+
79 found_charm = result[1]
80 self.assertEqual(CHARM, found_charm['metadata']['doctype'])
81 self.assertEqual(charm['store_url'], found_charm['charm']['url'])
82
83+ def test_search_result_bundles_includes_metadata(self):
84+ self.use_index_client()
85+ _id, charm = factory.makeCharm(self.db, promulgated=True)
86+ services = {
87+ u'charm': {
88+ u'charm': charm['name']
89+ }
90+ }
91+ bundle = self.make_indexed_bundle(
92+ series=charm['series'],
93+ services=services,
94+ with_basket=True)
95+
96+ factory.make_bundle_file(self.db, bundle, u'README', 'Test Content')
97+ result = self.get_response(self.search_endpoint).json_body['result']
98+ self.assertEqual(1, len(result))
99+ found_bundle = result[0]['bundle']
100+ self.assertEqual(['README'], found_bundle['files'])
101+ self.assertTrue(found_bundle['charm_metadata']['charm'])
102+ self.assertEqual(
103+ charm['name'],
104+ found_bundle['charm_metadata']['charm']['name']
105+ )
106+
107 def test_charm_wrong_revision(self):
108 """Retrieving a charm does not work if the revision is wrong."""
109 self.use_index_client()

Subscribers

People subscribed via source and target branches