Merge lp:~rharding/charmworld/move-bundle-url into lp:charmworld

Proposed by Richard Harding
Status: Merged
Approved by: Richard Harding
Approved revision: 445
Merged at revision: 442
Proposed branch: lp:~rharding/charmworld/move-bundle-url
Merge into: lp:charmworld
Diff against target: 255 lines (+44/-25)
5 files modified
charmworld/routes.py (+4/-4)
charmworld/views/api/__init__.py (+14/-5)
charmworld/views/tests/test_api.py (+14/-10)
charmworld/views/tests/test_bundles.py (+6/-6)
charmworld/views/tests/test_misc.py (+6/-0)
To merge this branch: bzr merge lp:~rharding/charmworld/move-bundle-url
Reviewer Review Type Date Requested Status
Juju Gui Bot continuous-integration Approve
Charmworld Developers Pending
Review via email: mp+193851@code.launchpad.net

Commit message

Update bundle user url to be /bundle/$id-bits.

- Update the api to provide that url as part of the bundle metadata so the gui
can link to it as a valid quickstart end point.
- Drive by to skip the test that fails with the known bug issue.
- Rename the TestApi2 and 3 back to not have the Z since we're just skipping
vs working around the issue.

https://codereview.appspot.com/21370044/

R=benji

Description of the change

Update bundle user url to be /bundle/$id-bits.

- Update the api to provide that url as part of the bundle metadata so the gui
can link to it as a valid quickstart end point.
- Drive by to skip the test that fails with the known bug issue.
- Rename the TestApi2 and 3 back to not have the Z since we're just skipping
vs working around the issue.

https://codereview.appspot.com/21370044/

To post a comment you must log in.
Revision history for this message
Richard Harding (rharding) wrote :
Download full text (11.4 KiB)

Reviewers: mp+193851_code.launchpad.net,

Message:
Please take a look.

Description:
Update bundle user url to be /bundle/$id-bits.

- Update the api to provide that url as part of the bundle metadata so
the gui
can link to it as a valid quickstart end point.
- Drive by to skip the test that fails with the known bug issue.
- Rename the TestApi2 and 3 back to not have the Z since we're just
skipping
vs working around the issue.

https://code.launchpad.net/~rharding/charmworld/move-bundle-url/+merge/193851

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/21370044/

Affected files (+43, -21 lines):
   A [revision details]
   M charmworld/routes.py
   M charmworld/views/api/__init__.py
   M charmworld/views/bundles.py
   M charmworld/views/tests/test_api.py
   M charmworld/views/tests/test_bundles.py
   M charmworld/views/tests/test_misc.py

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20131104185142-yu1k77h95eemcw1g
+New revision: <email address hidden>

Index: charmworld/routes.py
=== modified file 'charmworld/routes.py'
--- charmworld/routes.py 2013-10-29 19:59:01 +0000
+++ charmworld/routes.py 2013-11-04 20:52:52 +0000
@@ -54,13 +54,13 @@

      # Personal Bundles
      config.add_route("personal-bundle-json-revision",
- "/~{owner}/bundle/{basket}/{rev}/{bundle}/json")
+ "/bundle/~{owner}/{basket}/{rev}/{bundle}/json")
      config.add_route("personal-bundle-json",
- "/~{owner}/bundle/{basket}/{bundle}/json")
+ "/bundle/~{owner}/{basket}/{bundle}/json")
      config.add_route("personal-bundle-revision",
- "/~{owner}/bundle/{basket}/{rev}/{bundle}")
+ "/bundle/~{owner}/{basket}/{rev}/{bundle}")
      config.add_route("personal-bundle",
- "/~{owner}/bundle/{basket}/{bundle}")
+ "/bundle/~{owner}/{basket}/{bundle}")

      # Official (promulgated) Bundles
      config.add_route("official-bundle-json",

Index: charmworld/views/bundles.py
=== modified file 'charmworld/views/bundles.py'
--- charmworld/views/bundles.py 2013-10-29 19:59:01 +0000
+++ charmworld/views/bundles.py 2013-11-04 20:52:52 +0000
@@ -40,7 +40,7 @@
          for k, v in services.items():
              d = dict(name=k)
              for key in BundleDetail.service_keys:
- if key != 'options':
+ if key != 'option':
                      d[key] = v.get(key, u'')

              # Flatten options.

Index: charmworld/views/api/__init__.py
=== modified file 'charmworld/views/api/__init__.py'
--- charmworld/views/api/__init__.py 2013-10-24 22:04:01 +0000
+++ charmworld/views/api/__init__.py 2013-11-04 20:52:52 +0000
@@ -156,10 +156,10 @@
          }

      @classmethod
- def _bundle_result(cls, bundle, db):
+ def _bundle_result(cls, bundle, db, route_url):
          """Build standard metadata around a bundle search result."""
          bundle_obj = Bun...

442. By Richard Harding

Update per self-review

443. By Richard Harding

lint

Revision history for this message
Richard Harding (rharding) wrote :
Revision history for this message
Richard Harding (rharding) wrote :

Reviewer comments added.

https://codereview.appspot.com/21370044/diff/20001/charmworld/routes.py
File charmworld/routes.py (right):

https://codereview.appspot.com/21370044/diff/20001/charmworld/routes.py#newcode57
charmworld/routes.py:57:
"/bundle/~{owner}/{basket}/{rev}/{bundle}/json")
this could probably go into some sort of /bundle/*bits but leaving as
simple case of moving the url for the moment.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/api/__init__.py
File charmworld/views/api/__init__.py (right):

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/api/__init__.py#newcode159
charmworld/views/api/__init__.py:159: def _bundle_result(cls, bundle,
db, route_url):
route_url is needed to build the url to the person bundle json route
we're providing as an endpoint for the deployer/quickstart to use.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py
File charmworld/views/tests/test_api.py (right):

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py#newcode768
charmworld/views/tests/test_api.py:768: self.enable_routes()
because of the need to generate the route for the deployer_file_url we
need to enable routes on more tests.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py#newcode841
charmworld/views/tests/test_api.py:841:
u'http://example.com/bundle/%7Ebac/bat/4/byobu/json',
I'm so sorry, but the linter...he hates me.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py#newcode1585
charmworld/views/tests/test_api.py:1585: class TestAPI3(TestAPI,
API3Mixin):
remove the stupid Z. Just skipping the bad test for now. See later
files.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_misc.py
File charmworld/views/tests/test_misc.py (right):

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_misc.py#newcode54
charmworld/views/tests/test_misc.py:54: self.skipTest("See bug
#1237025
")
Skipping this as the new enable_routes() caused it to fail over here for
no good reason. Will look at as a follow up after bundles are released.

https://codereview.appspot.com/21370044/

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

LGTM

https://codereview.appspot.com/21370044/diff/20001/charmworld/routes.py
File charmworld/routes.py (right):

https://codereview.appspot.com/21370044/diff/20001/charmworld/routes.py#newcode57
charmworld/routes.py:57:
"/bundle/~{owner}/{basket}/{rev}/{bundle}/json")
On 2013/11/04 21:46:34, rharding wrote:
> this could probably go into some sort of /bundle/*bits but leaving as
simple
> case of moving the url for the moment.

If I'm understanding you correctly, I think I like it better this way.
It is easier to see the pattern matching spelled out in routes rather
than in code.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/api/__init__.py
File charmworld/views/api/__init__.py (right):

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/api/__init__.py#newcode429
charmworld/views/api/__init__.py:429: 'personal-bundle-json-revision',
**route_info)
Since route_info isn't used subsequently, I don't see why it is created
instead of just passing its contents as keyword arguments.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py
File charmworld/views/tests/test_api.py (right):

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py#newcode1
charmworld/views/tests/test_api.py:1: # Copyright<enter change
description here if sensible> 2012, 2013 Canonical
Something bad happened here.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py#newcode841
charmworld/views/tests/test_api.py:841:
u'http://example.com/bundle/%7Ebac/bat/4/byobu/json',
On 2013/11/04 21:46:34, rharding wrote:
> I'm so sorry, but the linter...he hates me.

Eww. That is bad.

It wouldn't accept the value being indented four more spaces?

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py#newcode1585
charmworld/views/tests/test_api.py:1585: class TestAPI3(TestAPI,
API3Mixin):
On 2013/11/04 21:46:34, rharding wrote:
> remove the stupid Z. Just skipping the bad test for now. See later
files.

I like the explicitness of the new approach better.

https://codereview.appspot.com/21370044/

Revision history for this message
Richard Harding (rharding) wrote :

Thanks for the review. I made a couple of small updates.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py
File charmworld/views/tests/test_api.py (right):

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py#newcode841
charmworld/views/tests/test_api.py:841:
u'http://example.com/bundle/%7Ebac/bat/4/byobu/json',
On 2013/11/05 12:55:46, benji wrote:
> On 2013/11/04 21:46:34, rharding wrote:
> > I'm so sorry, but the linter...he hates me.

> Eww. That is bad.

> It wouldn't accept the value being indented four more spaces?

No, it yelled about bad indentation. I was trapped between the line
length and the indentation fussing. I moved the string out into a
variable. I thought about it yesterday but it seemed ugly to me. Now
looking at it, it's much more sane.

https://codereview.appspot.com/21370044/diff/20001/charmworld/views/tests/test_api.py#newcode1585
charmworld/views/tests/test_api.py:1585: class TestAPI3(TestAPI,
API3Mixin):
On 2013/11/05 12:55:46, benji wrote:
> On 2013/11/04 21:46:34, rharding wrote:
> > remove the stupid Z. Just skipping the bad test for now. See later
files.

> I like the explicitness of the new approach better.

Thanks, removed the comments above as well. Missed that :/

https://codereview.appspot.com/21370044/

444. By Richard Harding

Updates per review

445. By Richard Harding

Fix the test for the basket/bundle order

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/routes.py'
2--- charmworld/routes.py 2013-10-29 19:59:01 +0000
3+++ charmworld/routes.py 2013-11-05 15:01:02 +0000
4@@ -54,13 +54,13 @@
5
6 # Personal Bundles
7 config.add_route("personal-bundle-json-revision",
8- "/~{owner}/bundle/{basket}/{rev}/{bundle}/json")
9+ "/bundle/~{owner}/{basket}/{rev}/{bundle}/json")
10 config.add_route("personal-bundle-json",
11- "/~{owner}/bundle/{basket}/{bundle}/json")
12+ "/bundle/~{owner}/{basket}/{bundle}/json")
13 config.add_route("personal-bundle-revision",
14- "/~{owner}/bundle/{basket}/{rev}/{bundle}")
15+ "/bundle/~{owner}/{basket}/{rev}/{bundle}")
16 config.add_route("personal-bundle",
17- "/~{owner}/bundle/{basket}/{bundle}")
18+ "/bundle/~{owner}/{basket}/{bundle}")
19
20 # Official (promulgated) Bundles
21 config.add_route("official-bundle-json",
22
23=== modified file 'charmworld/views/api/__init__.py'
24--- charmworld/views/api/__init__.py 2013-10-24 22:04:01 +0000
25+++ charmworld/views/api/__init__.py 2013-11-05 15:01:02 +0000
26@@ -156,10 +156,10 @@
27 }
28
29 @classmethod
30- def _bundle_result(cls, bundle, db):
31+ def _bundle_result(cls, bundle, db, route_url):
32 """Build standard metadata around a bundle search result."""
33 bundle_obj = Bundle(bundle)
34- bundle_metadata = cls._build_bundle_metadata(bundle_obj, db)
35+ bundle_metadata = cls._build_bundle_metadata(bundle_obj, db, route_url)
36 return {
37 'bundle': bundle_metadata,
38 'metadata': {
39@@ -414,11 +414,18 @@
40 return charm_id, trailing, charm
41
42 @classmethod
43- def _build_bundle_metadata(cls, bundle, db):
44+ def _build_bundle_metadata(cls, bundle, db, route_url):
45 bundle_dict = dict(bundle)
46 # Add the list of files in the bundle.
47 bundle_dict['files'] = bundle.get_file_list(db)
48 bundle_dict['charm_metadata'] = {}
49+ bundle_dict['deployer_file_url'] = route_url(
50+ 'personal-bundle-json-revision',
51+ basket=bundle_dict['basket_name'],
52+ bundle=bundle_dict['name'],
53+ owner=bundle_dict['owner'],
54+ rev=bundle_dict['basket_revision'],
55+ )
56 service_data = bundle_dict.get('data')
57 # Now load the charm information we require for the services in the
58 # bundle.
59@@ -515,7 +522,8 @@
60 result = {'type': 'no_such_bundle', 'bundle_id': '/'.join(path)}
61 return json_response(status, result)
62 if not trailing:
63- bundle = self._build_bundle_metadata(bundle, self.request.db)
64+ bundle = self._build_bundle_metadata(
65+ bundle, self.request.db, self.request.route_url)
66 return json_response(200, bundle)
67 elif trailing and '/'.join(trailing) == self.ICON_TRAILING:
68 return self._bundle_icon(bundle)
69@@ -697,7 +705,8 @@
70 if item['doctype'] == BUNDLE:
71 result = self._bundle_result(
72 Bundle(item['data'])._representation,
73- self.request.db)
74+ self.request.db,
75+ self.request.route_url)
76 else:
77 result = self._charm_result(Charm(item['data']))
78 results.append(result)
79
80=== modified file 'charmworld/views/tests/test_api.py'
81--- charmworld/views/tests/test_api.py 2013-10-25 01:16:39 +0000
82+++ charmworld/views/tests/test_api.py 2013-11-05 15:01:02 +0000
83@@ -1,5 +1,7 @@
84-# Copyright 2012, 2013 Canonical Ltd. This software is licensed under the
85-# GNU Affero General Public License version 3 (see the file LICENSE).
86+# Copyright 2012, 2013 Canonical
87+
88+# Ltd. This software is licensed under the GNU Affero General Public License
89+# version 3 (see the file LICENSE).
90
91 __metaclass__ = type
92
93@@ -764,6 +766,7 @@
94 self.get_response('bundle', remainder=None)
95
96 def test_valid_lookup_unpromulgated(self):
97+ self.enable_routes()
98 self.makeBundle(name='bat', owner='bac', basket_with_rev='byobu/4')
99 response = self.get_response('bundle', '~bac/byobu/4/bat')
100 self.assertEqual(200, response.status_code)
101@@ -773,6 +776,7 @@
102 self.assertEqual(404, response.status_code)
103
104 def test_valid_lookup_promulgated(self):
105+ self.enable_routes()
106 self.makeBundle(
107 name='bat', owner='bac', basket_with_rev='byobu/4',
108 promulgated=True)
109@@ -785,6 +789,7 @@
110 self.assertEqual(200, response.status_code)
111
112 def test_results_match(self):
113+ self.enable_routes()
114 # Make the charm that we'll use as a service.
115 _id, charm = factory.makeCharm(
116 self.db,
117@@ -801,6 +806,7 @@
118 basket_with_rev='byobu/4', services=services)
119 response = self.get_response('bundle', '~bac/byobu/4/bat')
120 self.assertEqual(200, response.status_code)
121+ deployer_url = u'http://example.com/bundle/%7Ebac/byobu/4/bat/json'
122 self.assertEqual(
123 response.json,
124 {
125@@ -832,6 +838,7 @@
126 u'permanent_url': u'bundle:~bac/byobu/4/bat',
127 u'promulgated': False,
128 u'title': u'',
129+ u'deployer_file_url': deployer_url,
130 })
131
132 def test_extracting_bundle_id_with_trailing_full_id(self):
133@@ -1572,10 +1579,7 @@
134 return names
135
136
137-# XXX: Rick Harding 2013-10-21:
138-# Odd bug requires these tests to be run last, hence the Z in the name to
139-# force it to be last.
140-class TestZAPI3(TestAPI, API3Mixin):
141+class TestAPI3(TestAPI, API3Mixin):
142 """Test API 3."""
143
144 def test_charms_path_notfound(self):
145@@ -1587,6 +1591,7 @@
146
147 def test_search_results_contain_charms_and_bundles(self):
148 self.use_index_client()
149+ self.enable_routes()
150 bundle = self.make_indexed_bundle(name='fan-stack-tic')
151 charm = self.make_indexed_charm()
152 result = self.get_response(self.search_endpoint).json_body['result']
153@@ -1605,6 +1610,7 @@
154
155 def test_search_result_bundles_includes_metadata(self):
156 self.use_index_client()
157+ self.enable_routes()
158 _id, charm = factory.makeCharm(self.db, promulgated=True)
159 services = {
160 u'charm': {
161@@ -1691,6 +1697,7 @@
162
163 def test_search_interesting_contains_charms_and_bundles(self):
164 self.use_index_client()
165+ self.enable_routes()
166 bundle = self.make_indexed_bundle(name='bat')
167 FeaturedSource.from_db(self.db).set_featured(
168 bundle._representation, BUNDLE)
169@@ -1705,10 +1712,7 @@
170 self.assertItemsEqual(expected, list_names(result['featured']))
171
172
173-# XXX: Rick Harding 2013-10-21:
174-# Odd bug requires these tests to be run last, hence the Z in the name to
175-# force it to be last.
176-class TestZAPI2(TestAPI, API2Mixin):
177+class TestAPI2(TestAPI, API2Mixin):
178 """Test API 2."""
179
180 def test_charms_passes_doctype(self):
181
182=== modified file 'charmworld/views/tests/test_bundles.py'
183--- charmworld/views/tests/test_bundles.py 2013-10-29 20:38:42 +0000
184+++ charmworld/views/tests/test_bundles.py 2013-11-05 15:01:02 +0000
185@@ -287,7 +287,7 @@
186 basket_with_rev=basket_with_rev, series='raring',
187 )
188 # Test that the route works.
189- path = '/~{owner}/bundle/{basket}/{bundle}'.format(
190+ path = '/bundle/~{owner}/{basket}/{bundle}'.format(
191 owner=owner, basket=basket, bundle=bundle_name)
192 resp = self.app.get(path, status=200)
193 self.assertIn(bundle.owner, resp.body)
194@@ -308,7 +308,7 @@
195 self.db, name='gigis', owner='ladonna',
196 basket_with_rev='basket/1', series='raring',
197 )
198- path = '/~ladonna/bundle/basket/1/gigis'
199+ path = '/bundle/~ladonna/basket/1/gigis'
200 response = self.app.get(path, status=200)
201 self.assertIn(
202 'lp:~ladonna/charms/bundles/basket/bundle', response.body)
203@@ -318,7 +318,7 @@
204 self.db, name='gigis', owner='ladonna',
205 basket_with_rev='basket/1', series='raring',
206 )
207- path = '/~ladonna/bundle/basket/1/XXX'
208+ path = '/bundle/~ladonna/basket/1/XXX'
209 self.app.get(path, status=404)
210
211 def test_personal_bundle_with_revision_json_route(self):
212@@ -328,7 +328,7 @@
213 self.db, name='gigis', owner='ladonna',
214 basket_with_rev='basket/1', series='raring',
215 )
216- path = '/~ladonna/bundle/basket/1/gigis/json'
217+ path = '/bundle/~ladonna/basket/1/gigis/json'
218 resp = self.app.get(path, status=200)
219 self.assertIn(bundle.data['series'], resp.body)
220 self.assertIn(str(bundle.data['relations']), resp.body)
221@@ -341,7 +341,7 @@
222 self.db, name='gigis', owner='lafawnda',
223 basket_with_rev='basket/1', series='raring',
224 )
225- path = '/~lafawnda/bundle/basket/gigis/json'
226+ path = '/bundle/~lafawnda/basket/gigis/json'
227 resp = self.app.get(path, status=200)
228 self.assertIn(bundle.data['series'], resp.body)
229 self.assertIn(str(bundle.data['relations']), resp.body)
230@@ -352,7 +352,7 @@
231 self.db, name='gigis', owner='ladonna',
232 basket_with_rev='basket/1', series='raring',
233 )
234- path = '/~ladonna/bundle/basket/1/XXX/json'
235+ path = '/bundle/~ladonna/basket/1/XXX/json'
236 self.app.get(path, status=404)
237
238 def test_official_bundle_route(self):
239
240=== modified file 'charmworld/views/tests/test_misc.py'
241--- charmworld/views/tests/test_misc.py 2013-10-30 13:20:01 +0000
242+++ charmworld/views/tests/test_misc.py 2013-11-05 15:01:02 +0000
243@@ -46,6 +46,12 @@
244
245 def test_homeview(self):
246 """Make sure the home view renders correctly."""
247+ # XXX: #1237025 Rick Harding 2013-10-21:
248+ # Unknown bug causes this test to fail if other tests enable the
249+ # self.enable_routes(). Skipping this test and leaving the others.
250+ # Leaving the bug as a reference to fix this failure. Passes when run
251+ # in single suite, but fails in global `make test`.
252+ self.skipTest("See bug #1237025")
253 resp = self.app.get(
254 '/',
255 status=200)

Subscribers

People subscribed via source and target branches

to all changes: