Merge lp:~bac/charmworld/bug-1240576 into lp:~juju-jitsu/charmworld/trunk

Proposed by Brad Crittenden
Status: Merged
Merged at revision: 425
Proposed branch: lp:~bac/charmworld/bug-1240576
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 85 lines (+34/-3)
2 files modified
charmworld/views/api.py (+1/-1)
charmworld/views/tests/test_api.py (+33/-2)
To merge this branch: bzr merge lp:~bac/charmworld/bug-1240576
Reviewer Review Type Date Requested Status
Juju-Jitsu Hackers Pending
Review via email: mp+192074@code.launchpad.net

Description of the change

Parse charms with hyphens properly.

https://codereview.appspot.com/15580047/

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Reviewers: mp+192074_code.launchpad.net,

Message:
Please take a look.

Description:
Parse charms with hyphens properly.

https://code.launchpad.net/~bac/charmworld/bug-1240576/+merge/192074

(do not edit description out of merge proposal)

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

Affected files (+23, -1 lines):
   A [revision details]
   M charmworld/views/api.py
   M charmworld/views/tests/test_api.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: <email address hidden>
+New revision: <email address hidden>

Index: charmworld/views/api.py
=== modified file 'charmworld/views/api.py'
--- charmworld/views/api.py 2013-10-17 18:38:21 +0000
+++ charmworld/views/api.py 2013-10-22 00:33:12 +0000
@@ -407,7 +407,7 @@
          if len(elements) < 2:
              raise ValueError('charm ID does not contain enough elements')
          # If the charm ID includes a revision number, parse it out.
- if '-' in elements[-1]:
+ if re.search('-\d+$', elements[-1]):
              name, revision = elements[-1].rsplit('-', 1)
          else:
              name = elements[-1]

Index: charmworld/views/tests/test_api.py
=== modified file 'charmworld/views/tests/test_api.py'
--- charmworld/views/tests/test_api.py 2013-10-18 18:53:19 +0000
+++ charmworld/views/tests/test_api.py 2013-10-22 00:36:55 +0000
@@ -1729,6 +1729,9 @@
      return names

+# XXX: Rick Harding 2013-10-21:
+# Odd bug requires these tests to be run last, hence the Z in the name to
+# force it to be last.
  class TestZAPI3(TestAPI, API3Mixin):
      """Test API 3."""

@@ -1809,6 +1812,20 @@
          self.assertEqual(200, response.status_code)
          self.assertEqual(response.json_body, new_charm)

+ def test_charm_no_revision_with_hyphen(self):
+ """Retrieving a charm with no revision results in the latest
one."""
+ self.use_index_client()
+ # Make a charm.
+ old_charm = self.make_charm(
+ owner='owner', series='series', name='a-name',
store_revision=1)[1]
+ # Make a newer revision of the same charm.
+ new_charm = self.make_charm(
+ owner='owner', series='series', name='a-name',
store_revision=2)[1]
+ revisionless_charm_id = self.get_id(old_charm).rsplit('-', 1)[0]
+ response = self.get_response('charm',
remainder=revisionless_charm_id)
+ self.assertEqual(200, response.status_code)
+ self.assertEqual(response.json_body, new_charm)
+
      def test_search_interesting_contains_charms_and_bundles(self):
          self.use_index_client()
          bundle = self.make_indexed_bundle(name='bat')
@@ -1825,6 +1842,9 @@
          self.assertItemsEqual(expected, list_names(result['featured']))

+# XXX: Rick Harding 2013-10-21:
+# Odd bug requires these tests to be run last, hence the Z in the name to
+# force it to be last.
  class TestZAPI2(TestAPI, API2Mixin):
      """Test API 2."""

lp:~bac/charmworld/bug-1240576 updated
427. By Brad Crittenden

Add new test, clean up comments.

Revision history for this message
Brad Crittenden (bac) wrote :

*** Submitted:

Parse charms with hyphens properly.

R=benji
CC=
https://codereview.appspot.com/15580047

https://codereview.appspot.com/15580047/

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-17 18:38:21 +0000
3+++ charmworld/views/api.py 2013-10-22 00:55:31 +0000
4@@ -407,7 +407,7 @@
5 if len(elements) < 2:
6 raise ValueError('charm ID does not contain enough elements')
7 # If the charm ID includes a revision number, parse it out.
8- if '-' in elements[-1]:
9+ if re.search('-\d+$', elements[-1]):
10 name, revision = elements[-1].rsplit('-', 1)
11 else:
12 name = elements[-1]
13
14=== modified file 'charmworld/views/tests/test_api.py'
15--- charmworld/views/tests/test_api.py 2013-10-18 18:53:19 +0000
16+++ charmworld/views/tests/test_api.py 2013-10-22 00:55:31 +0000
17@@ -1729,6 +1729,9 @@
18 return names
19
20
21+# XXX: Rick Harding 2013-10-21:
22+# Odd bug requires these tests to be run last, hence the Z in the name to
23+# force it to be last.
24 class TestZAPI3(TestAPI, API3Mixin):
25 """Test API 3."""
26
27@@ -1782,7 +1785,7 @@
28 )
29
30 def test_charm_wrong_revision(self):
31- """Retrieving a charm does not work if the revision is wrong."""
32+ # Retrieving a charm does not work if the revision is wrong.
33 self.use_index_client()
34 charm = self.make_charm()[1]
35 stale_charm_id = self.get_id(charm) + '37'
36@@ -1796,7 +1799,7 @@
37 })
38
39 def test_charm_no_revision(self):
40- """Retrieving a charm with no revision results in the latest one."""
41+ # Retrieving a charm with no revision results in the latest one.
42 self.use_index_client()
43 # Make a charm.
44 old_charm = self.make_charm(
45@@ -1809,6 +1812,31 @@
46 self.assertEqual(200, response.status_code)
47 self.assertEqual(response.json_body, new_charm)
48
49+ def test_charm_no_revision_with_hyphen(self):
50+ # Retrieving a charm with a hyphen works.
51+ self.use_index_client()
52+ # Make a charm.
53+ old_charm = self.make_charm(
54+ owner='owner', series='series', name='a-name', store_revision=1)[1]
55+ # Make a newer revision of the same charm.
56+ new_charm = self.make_charm(
57+ owner='owner', series='series', name='a-name', store_revision=2)[1]
58+ revisionless_charm_id = self.get_id(old_charm).rsplit('-', 1)[0]
59+ response = self.get_response('charm', remainder=revisionless_charm_id)
60+ self.assertEqual(200, response.status_code)
61+ self.assertEqual(response.json_body, new_charm)
62+
63+ def test_charm_with_hyphen_and_revision(self):
64+ # Retrieving a charm with a hyphen works.
65+ self.use_index_client()
66+ # Make a charm.
67+ charm = self.make_charm(
68+ owner='owner', series='series', name='a-name', store_revision=1)[1]
69+ charm_id = self.get_id(charm)
70+ response = self.get_response('charm', remainder=charm_id)
71+ self.assertEqual(200, response.status_code)
72+ self.assertEqual(response.json_body, charm)
73+
74 def test_search_interesting_contains_charms_and_bundles(self):
75 self.use_index_client()
76 bundle = self.make_indexed_bundle(name='bat')
77@@ -1825,6 +1853,9 @@
78 self.assertItemsEqual(expected, list_names(result['featured']))
79
80
81+# XXX: Rick Harding 2013-10-21:
82+# Odd bug requires these tests to be run last, hence the Z in the name to
83+# force it to be last.
84 class TestZAPI2(TestAPI, API2Mixin):
85 """Test API 2."""
86

Subscribers

People subscribed via source and target branches