Merge lp:~nataliabidart/ubuntu-webcatalog/law-and-order.3 into lp:ubuntu-webcatalog
- law-and-order.3
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Natalia Bidart | ||||
Approved revision: | 136 | ||||
Merged at revision: | 136 | ||||
Proposed branch: | lp:~nataliabidart/ubuntu-webcatalog/law-and-order.3 | ||||
Merge into: | lp:ubuntu-webcatalog | ||||
Prerequisite: | lp:~nataliabidart/ubuntu-webcatalog/law-and-order.2 | ||||
Diff against target: |
2711 lines (+567/-540) 16 files modified
src/webcatalog/tests/factory.py (+24/-20) src/webcatalog/tests/helpers.py (+2/-2) src/webcatalog/tests/test_api.py (+32/-31) src/webcatalog/tests/test_commands.py (+109/-97) src/webcatalog/tests/test_context_processors.py (+1/-1) src/webcatalog/tests/test_department_filters.py (+3/-3) src/webcatalog/tests/test_forms.py (+42/-43) src/webcatalog/tests/test_handlers.py (+9/-10) src/webcatalog/tests/test_managers.py (+9/-9) src/webcatalog/tests/test_models.py (+75/-65) src/webcatalog/tests/test_pep8.py (+14/-16) src/webcatalog/tests/test_preflight.py (+3/-3) src/webcatalog/tests/test_templatetags.py (+26/-35) src/webcatalog/tests/test_utilities.py (+27/-28) src/webcatalog/tests/test_views.py (+189/-175) src/webcatalog/views.py (+2/-2) |
||||
To merge this branch: | bzr merge lp:~nataliabidart/ubuntu-webcatalog/law-and-order.3 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Anthony Lenton (community) | Approve | ||
Review via email: mp+109008@code.launchpad.net |
Commit message
- Fixing pep8 issues (part 3 of LP: #1007626).
Description of the change
To post a comment you must log in.
Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote : | # |
The prerequisite lp:~nataliabidart/ubuntu-webcatalog/law-and-order.2 has not yet been merged into lp:ubuntu-webcatalog.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/webcatalog/tests/factory.py' | |||
2 | --- src/webcatalog/tests/factory.py 2012-05-03 12:13:00 +0000 | |||
3 | +++ src/webcatalog/tests/factory.py 2012-06-06 18:03:20 +0000 | |||
4 | @@ -20,7 +20,7 @@ | |||
5 | 20 | from __future__ import ( | 20 | from __future__ import ( |
6 | 21 | absolute_import, | 21 | absolute_import, |
7 | 22 | with_statement, | 22 | with_statement, |
9 | 23 | ) | 23 | ) |
10 | 24 | import os | 24 | import os |
11 | 25 | from datetime import ( | 25 | from datetime import ( |
12 | 26 | datetime, | 26 | datetime, |
13 | @@ -42,14 +42,14 @@ | |||
14 | 42 | Machine, | 42 | Machine, |
15 | 43 | Nonce, | 43 | Nonce, |
16 | 44 | Token, | 44 | Token, |
18 | 45 | ) | 45 | ) |
19 | 46 | from webcatalog.utilities import full_claimed_id | 46 | from webcatalog.utilities import full_claimed_id |
20 | 47 | 47 | ||
21 | 48 | __metaclass__ = type | 48 | __metaclass__ = type |
22 | 49 | __all__ = [ | 49 | __all__ = [ |
23 | 50 | 'TestCaseWithFactory', | 50 | 'TestCaseWithFactory', |
24 | 51 | 'WebCatalogObjectFactory', | 51 | 'WebCatalogObjectFactory', |
26 | 52 | ] | 52 | ] |
27 | 53 | 53 | ||
28 | 54 | 54 | ||
29 | 55 | class WebCatalogObjectFactory(object): | 55 | class WebCatalogObjectFactory(object): |
30 | @@ -66,7 +66,8 @@ | |||
31 | 66 | return prefix + str(self.get_unique_integer()) | 66 | return prefix + str(self.get_unique_integer()) |
32 | 67 | 67 | ||
33 | 68 | def make_user(self, username=None, email=None, password='test', | 68 | def make_user(self, username=None, email=None, password='test', |
35 | 69 | first_name=None, last_name=None, open_id=None, is_admin=False): | 69 | first_name=None, last_name=None, open_id=None, |
36 | 70 | is_admin=False): | ||
37 | 70 | if username is None: | 71 | if username is None: |
38 | 71 | username = self.get_unique_string(prefix='username') | 72 | username = self.get_unique_string(prefix='username') |
39 | 72 | if email is None: | 73 | if email is None: |
40 | @@ -97,11 +98,12 @@ | |||
41 | 97 | return user | 98 | return user |
42 | 98 | 99 | ||
43 | 99 | def make_application(self, package_name=None, name=None, | 100 | def make_application(self, package_name=None, name=None, |
49 | 100 | comment=None, description=None, icon_name='', icon=None, | 101 | comment=None, description=None, icon_name='', |
50 | 101 | distroseries=None, arch='i686', ratings_average=None, | 102 | icon=None, distroseries=None, arch='i686', |
51 | 102 | ratings_total=None, ratings_histogram='', screenshot_url='', | 103 | ratings_average=None, ratings_total=None, |
52 | 103 | archive_id=None, version='', is_latest=False, wilson_score=0.0, | 104 | ratings_histogram='', screenshot_url='', |
53 | 104 | debtags=[], application_id=None): | 105 | archive_id=None, version='', is_latest=False, |
54 | 106 | wilson_score=0.0, debtags=[], application_id=None): | ||
55 | 105 | if name is None: | 107 | if name is None: |
56 | 106 | name = self.get_unique_string(prefix='Readable Name') | 108 | name = self.get_unique_string(prefix='Readable Name') |
57 | 107 | if package_name is None: | 109 | if package_name is None: |
58 | @@ -136,7 +138,7 @@ | |||
59 | 136 | return Department.objects.create(name=name, parent=parent, slug=slug) | 138 | return Department.objects.create(name=name, parent=parent, slug=slug) |
60 | 137 | 139 | ||
61 | 138 | def make_exhibit(self, package_names=None, published=True, display=None, | 140 | def make_exhibit(self, package_names=None, published=True, display=None, |
63 | 139 | distroseries=None, weight=0): | 141 | distroseries=None, weight=0): |
64 | 140 | sca_id = self.get_unique_integer() | 142 | sca_id = self.get_unique_integer() |
65 | 141 | if package_names is None: | 143 | if package_names is None: |
66 | 142 | package_names = self.get_unique_string(prefix='package-') | 144 | package_names = self.get_unique_string(prefix='package-') |
67 | @@ -144,9 +146,9 @@ | |||
68 | 144 | html = self.get_unique_string(prefix='html-') | 146 | html = self.get_unique_string(prefix='html-') |
69 | 145 | if distroseries is None: | 147 | if distroseries is None: |
70 | 146 | distroseries = self.make_distroseries() | 148 | distroseries = self.make_distroseries() |
74 | 147 | xibit = Exhibit.objects.create(sca_id=sca_id, | 149 | xibit = Exhibit.objects.create( |
75 | 148 | package_names=package_names, banner_url=banner_url, html=html, | 150 | sca_id=sca_id, package_names=package_names, banner_url=banner_url, |
76 | 149 | published=published, display=display, weight=weight) | 151 | html=html, published=published, display=display, weight=weight) |
77 | 150 | xibit.distroseries.add(distroseries) | 152 | xibit.distroseries.add(distroseries) |
78 | 151 | return xibit | 153 | return xibit |
79 | 152 | 154 | ||
80 | @@ -164,7 +166,7 @@ | |||
81 | 164 | os.path.dirname(__file__), 'test_data', file_name) | 166 | os.path.dirname(__file__), 'test_data', file_name) |
82 | 165 | 167 | ||
83 | 166 | def make_machine(self, owner=None, uuid=None, hostname=None, | 168 | def make_machine(self, owner=None, uuid=None, hostname=None, |
85 | 167 | package_list=None): | 169 | package_list=None): |
86 | 168 | if owner is None: | 170 | if owner is None: |
87 | 169 | owner = self.make_user() | 171 | owner = self.make_user() |
88 | 170 | if hostname is None: | 172 | if hostname is None: |
89 | @@ -176,7 +178,8 @@ | |||
90 | 176 | packages_checksum = self.get_unique_string(prefix='package-checksum-') | 178 | packages_checksum = self.get_unique_string(prefix='package-checksum-') |
91 | 177 | logo_checksum = self.get_unique_string(prefix='logo-checksum-') | 179 | logo_checksum = self.get_unique_string(prefix='logo-checksum-') |
92 | 178 | 180 | ||
94 | 179 | return Machine.objects.create(owner=owner, hostname=hostname, | 181 | return Machine.objects.create( |
95 | 182 | owner=owner, hostname=hostname, | ||
96 | 180 | uuid=uuid, packages_checksum=packages_checksum, | 183 | uuid=uuid, packages_checksum=packages_checksum, |
97 | 181 | package_list=package_list, logo_checksum=logo_checksum) | 184 | package_list=package_list, logo_checksum=logo_checksum) |
98 | 182 | 185 | ||
99 | @@ -188,14 +191,14 @@ | |||
100 | 188 | consumer_key = user.useropenid_set.get().claimed_id.split('/')[-1] | 191 | consumer_key = user.useropenid_set.get().claimed_id.split('/')[-1] |
101 | 189 | consumer_secret = self.get_unique_string(prefix='consumer-secret-') | 192 | consumer_secret = self.get_unique_string(prefix='consumer-secret-') |
102 | 190 | consumer = Consumer(user=user, key=consumer_key, | 193 | consumer = Consumer(user=user, key=consumer_key, |
104 | 191 | secret=consumer_secret) | 194 | secret=consumer_secret) |
105 | 192 | if save: | 195 | if save: |
106 | 193 | consumer.save() | 196 | consumer.save() |
107 | 194 | token_string = self.get_unique_string(prefix='token-') | 197 | token_string = self.get_unique_string(prefix='token-') |
108 | 195 | token_secret = self.get_unique_string(prefix='token-secret-') | 198 | token_secret = self.get_unique_string(prefix='token-secret-') |
109 | 196 | token_name = self.get_unique_string(prefix='token-name-') | 199 | token_name = self.get_unique_string(prefix='token-name-') |
110 | 197 | token = Token(consumer=consumer, token=token_string, | 200 | token = Token(consumer=consumer, token=token_string, |
112 | 198 | token_secret=token_secret, name=token_name) | 201 | token_secret=token_secret, name=token_name) |
113 | 199 | if save: | 202 | if save: |
114 | 200 | token.save() | 203 | token.save() |
115 | 201 | return token, consumer | 204 | return token, consumer |
116 | @@ -204,7 +207,8 @@ | |||
117 | 204 | if token is None or consumer is None: | 207 | if token is None or consumer is None: |
118 | 205 | assert token is None and consumer is None | 208 | assert token is None and consumer is None |
119 | 206 | token, consumer = self.make_oauth_token_and_consumer() | 209 | token, consumer = self.make_oauth_token_and_consumer() |
121 | 207 | nonce = Nonce.objects.create(token=token, consumer=consumer, | 210 | nonce = Nonce.objects.create( |
122 | 211 | token=token, consumer=consumer, | ||
123 | 208 | nonce=self.get_unique_string(prefix='nonce-')) | 212 | nonce=self.get_unique_string(prefix='nonce-')) |
124 | 209 | if created_at: | 213 | if created_at: |
125 | 210 | nonce.created_at = created_at | 214 | nonce.created_at = created_at |
126 | @@ -213,8 +217,8 @@ | |||
127 | 213 | 217 | ||
128 | 214 | def make_session(self, expire_date=None): | 218 | def make_session(self, expire_date=None): |
129 | 215 | if expire_date is None: | 219 | if expire_date is None: |
132 | 216 | expire_date = datetime.now() + timedelta( | 220 | secs = self.get_unique_integer() |
133 | 217 | seconds=self.get_unique_integer()) | 221 | expire_date = datetime.now() + timedelta(seconds=secs) |
134 | 218 | return Session.objects.create( | 222 | return Session.objects.create( |
135 | 219 | session_key=self.get_unique_string(prefix='key-'), | 223 | session_key=self.get_unique_string(prefix='key-'), |
136 | 220 | session_data=self.get_unique_string(prefix='session-data-'), | 224 | session_data=self.get_unique_string(prefix='session-data-'), |
137 | 221 | 225 | ||
138 | === modified file 'src/webcatalog/tests/helpers.py' | |||
139 | --- src/webcatalog/tests/helpers.py 2011-09-12 13:37:24 +0000 | |||
140 | +++ src/webcatalog/tests/helpers.py 2012-06-06 18:03:20 +0000 | |||
141 | @@ -20,13 +20,13 @@ | |||
142 | 20 | from __future__ import ( | 20 | from __future__ import ( |
143 | 21 | absolute_import, | 21 | absolute_import, |
144 | 22 | with_statement, | 22 | with_statement, |
146 | 23 | ) | 23 | ) |
147 | 24 | 24 | ||
148 | 25 | __metaclass__ = type | 25 | __metaclass__ = type |
149 | 26 | __all__ = [ | 26 | __all__ = [ |
150 | 27 | 'patch_settings', | 27 | 'patch_settings', |
151 | 28 | 'SettingDoesNotExist', | 28 | 'SettingDoesNotExist', |
153 | 29 | ] | 29 | ] |
154 | 30 | 30 | ||
155 | 31 | from contextlib import contextmanager | 31 | from contextlib import contextmanager |
156 | 32 | from django.conf import settings | 32 | from django.conf import settings |
157 | 33 | 33 | ||
158 | === modified file 'src/webcatalog/tests/test_api.py' | |||
159 | --- src/webcatalog/tests/test_api.py 2012-01-06 17:54:47 +0000 | |||
160 | +++ src/webcatalog/tests/test_api.py 2012-06-06 18:03:20 +0000 | |||
161 | @@ -28,7 +28,7 @@ | |||
162 | 28 | 'ServerStatusTestCase', | 28 | 'ServerStatusTestCase', |
163 | 29 | 'UpdateMachineTestCase', | 29 | 'UpdateMachineTestCase', |
164 | 30 | 'UpdatePackageListTestCase', | 30 | 'UpdatePackageListTestCase', |
166 | 31 | ] | 31 | ] |
167 | 32 | 32 | ||
168 | 33 | from django.utils import simplejson | 33 | from django.utils import simplejson |
169 | 34 | 34 | ||
170 | @@ -38,7 +38,7 @@ | |||
171 | 38 | OAuthConsumer, | 38 | OAuthConsumer, |
172 | 39 | OAuthToken, | 39 | OAuthToken, |
173 | 40 | OAuthSignatureMethod_PLAINTEXT, | 40 | OAuthSignatureMethod_PLAINTEXT, |
175 | 41 | ) | 41 | ) |
176 | 42 | 42 | ||
177 | 43 | from .factory import TestCaseWithFactory | 43 | from .factory import TestCaseWithFactory |
178 | 44 | from webcatalog.models import Machine | 44 | from webcatalog.models import Machine |
179 | @@ -57,8 +57,8 @@ | |||
180 | 57 | oatoken = OAuthToken(token.token, token.token_secret) | 57 | oatoken = OAuthToken(token.token, token.token_secret) |
181 | 58 | oarequest = OAuthRequest.from_consumer_and_token( | 58 | oarequest = OAuthRequest.from_consumer_and_token( |
182 | 59 | oaconsumer, oatoken, http_url=url) | 59 | oaconsumer, oatoken, http_url=url) |
185 | 60 | oarequest.sign_request(OAuthSignatureMethod_PLAINTEXT(), | 60 | oarequest.sign_request( |
186 | 61 | oaconsumer, oatoken) | 61 | OAuthSignatureMethod_PLAINTEXT(), oaconsumer, oatoken) |
187 | 62 | header = oarequest.to_header(realm) | 62 | header = oarequest.to_header(realm) |
188 | 63 | return {'HTTP_AUTHORIZATION': header['Authorization']} | 63 | return {'HTTP_AUTHORIZATION': header['Authorization']} |
189 | 64 | 64 | ||
190 | @@ -72,16 +72,16 @@ | |||
191 | 72 | 72 | ||
192 | 73 | def test_read_no_machines(self): | 73 | def test_read_no_machines(self): |
193 | 74 | user = self.factory.make_user() | 74 | user = self.factory.make_user() |
196 | 75 | response = self.client.get(self.url, | 75 | response = self.client.get( |
197 | 76 | **self.auth_header_for_user(self.url, user=user)) | 76 | self.url, **self.auth_header_for_user(self.url, user=user)) |
198 | 77 | self.assertEqual('[]', response.content) | 77 | self.assertEqual('[]', response.content) |
199 | 78 | 78 | ||
200 | 79 | def test_read_multiple_machines(self): | 79 | def test_read_multiple_machines(self): |
201 | 80 | user = self.factory.make_user() | 80 | user = self.factory.make_user() |
202 | 81 | machine1 = self.factory.make_machine(owner=user) | 81 | machine1 = self.factory.make_machine(owner=user) |
203 | 82 | machine2 = self.factory.make_machine(owner=user) | 82 | machine2 = self.factory.make_machine(owner=user) |
206 | 83 | response = self.client.get(self.url, | 83 | response = self.client.get( |
207 | 84 | **self.auth_header_for_user(self.url, user=user)) | 84 | self.url, **self.auth_header_for_user(self.url, user=user)) |
208 | 85 | data = simplejson.loads(response.content) | 85 | data = simplejson.loads(response.content) |
209 | 86 | self.assertEqual(2, len(data)) | 86 | self.assertEqual(2, len(data)) |
210 | 87 | expected = set([machine1.uuid, machine2.uuid]) | 87 | expected = set([machine1.uuid, machine2.uuid]) |
211 | @@ -90,7 +90,8 @@ | |||
212 | 90 | def test_only_returns_machines_for_the_authenticated_user(self): | 90 | def test_only_returns_machines_for_the_authenticated_user(self): |
213 | 91 | mymachine = self.factory.make_machine() | 91 | mymachine = self.factory.make_machine() |
214 | 92 | othermachine = self.factory.make_machine() | 92 | othermachine = self.factory.make_machine() |
216 | 93 | response = self.client.get(self.url, | 93 | response = self.client.get( |
217 | 94 | self.url, | ||
218 | 94 | **self.auth_header_for_user(self.url, user=mymachine.owner)) | 95 | **self.auth_header_for_user(self.url, user=mymachine.owner)) |
219 | 95 | data = simplejson.loads(response.content) | 96 | data = simplejson.loads(response.content) |
220 | 96 | 97 | ||
221 | @@ -111,8 +112,8 @@ | |||
222 | 111 | data = simplejson.dumps({'hostname': machine.hostname + '-updated'}) | 112 | data = simplejson.dumps({'hostname': machine.hostname + '-updated'}) |
223 | 112 | url = self.url % machine.uuid | 113 | url = self.url % machine.uuid |
224 | 113 | 114 | ||
227 | 114 | response = self.client.post(url, data=data, | 115 | response = self.client.post( |
228 | 115 | content_type='application/json', | 116 | url, data=data, content_type='application/json', |
229 | 116 | **self.auth_header_for_user(url, user=machine.owner)) | 117 | **self.auth_header_for_user(url, user=machine.owner)) |
230 | 117 | 118 | ||
231 | 118 | data = simplejson.loads(response.content) | 119 | data = simplejson.loads(response.content) |
232 | @@ -124,8 +125,8 @@ | |||
233 | 124 | data = simplejson.dumps({'hostname': machine.hostname + '-updated'}) | 125 | data = simplejson.dumps({'hostname': machine.hostname + '-updated'}) |
234 | 125 | url = self.url % machine.uuid | 126 | url = self.url % machine.uuid |
235 | 126 | 127 | ||
238 | 127 | response = self.client.post(url, data=data, | 128 | response = self.client.post( |
239 | 128 | content_type='application/json', | 129 | url, data=data, content_type='application/json', |
240 | 129 | **self.auth_header_for_user(url, user=otheruser)) | 130 | **self.auth_header_for_user(url, user=otheruser)) |
241 | 130 | 131 | ||
242 | 131 | data = simplejson.loads(response.content) | 132 | data = simplejson.loads(response.content) |
243 | @@ -144,20 +145,20 @@ | |||
244 | 144 | machine = self.factory.make_machine() | 145 | machine = self.factory.make_machine() |
245 | 145 | url = self.url % machine.uuid | 146 | url = self.url % machine.uuid |
246 | 146 | 147 | ||
249 | 147 | response = self.client.delete(url, | 148 | response = self.client.delete( |
250 | 148 | **self.auth_header_for_user(url, user=machine.owner)) | 149 | url, **self.auth_header_for_user(url, user=machine.owner)) |
251 | 149 | 150 | ||
252 | 150 | self.assertEqual(204, response.status_code) | 151 | self.assertEqual(204, response.status_code) |
253 | 151 | self.assertRaises(Machine.DoesNotExist, Machine.objects.get, | 152 | self.assertRaises(Machine.DoesNotExist, Machine.objects.get, |
255 | 152 | uuid=machine.uuid, owner=machine.owner) | 153 | uuid=machine.uuid, owner=machine.owner) |
256 | 153 | 154 | ||
257 | 154 | def test_delete_other_users_machine_fails(self): | 155 | def test_delete_other_users_machine_fails(self): |
258 | 155 | machine = self.factory.make_machine() | 156 | machine = self.factory.make_machine() |
259 | 156 | otheruser = self.factory.make_user() | 157 | otheruser = self.factory.make_user() |
260 | 157 | url = self.url % machine.uuid | 158 | url = self.url % machine.uuid |
261 | 158 | 159 | ||
264 | 159 | response = self.client.delete(url, | 160 | response = self.client.delete( |
265 | 160 | **self.auth_header_for_user(url, user=otheruser)) | 161 | url, **self.auth_header_for_user(url, user=otheruser)) |
266 | 161 | 162 | ||
267 | 162 | self.assertEqual(404, response.status_code) | 163 | self.assertEqual(404, response.status_code) |
268 | 163 | 164 | ||
269 | @@ -174,8 +175,8 @@ | |||
270 | 174 | machine = self.factory.make_machine() | 175 | machine = self.factory.make_machine() |
271 | 175 | url = self.url % machine.uuid | 176 | url = self.url % machine.uuid |
272 | 176 | 177 | ||
275 | 177 | response = self.client.get(url, | 178 | response = self.client.get( |
276 | 178 | **self.auth_header_for_user(url, user=machine.owner)) | 179 | url, **self.auth_header_for_user(url, user=machine.owner)) |
277 | 179 | 180 | ||
278 | 180 | data = simplejson.loads(response.content) | 181 | data = simplejson.loads(response.content) |
279 | 181 | self.assertEqual(machine.hostname, data['hostname']) | 182 | self.assertEqual(machine.hostname, data['hostname']) |
280 | @@ -186,8 +187,8 @@ | |||
281 | 186 | otheruser = self.factory.make_user() | 187 | otheruser = self.factory.make_user() |
282 | 187 | url = self.url % machine.uuid | 188 | url = self.url % machine.uuid |
283 | 188 | 189 | ||
286 | 189 | response = self.client.get(url, | 190 | response = self.client.get( |
287 | 190 | **self.auth_header_for_user(url, user=otheruser)) | 191 | url, **self.auth_header_for_user(url, user=otheruser)) |
288 | 191 | 192 | ||
289 | 192 | self.assertEqual(404, response.status_code) | 193 | self.assertEqual(404, response.status_code) |
290 | 193 | 194 | ||
291 | @@ -205,8 +206,8 @@ | |||
292 | 205 | machine = self.factory.make_machine(package_list=expected) | 206 | machine = self.factory.make_machine(package_list=expected) |
293 | 206 | url = self.url % machine.uuid | 207 | url = self.url % machine.uuid |
294 | 207 | 208 | ||
297 | 208 | response = self.client.get(url, | 209 | response = self.client.get( |
298 | 209 | **self.auth_header_for_user(url, user=machine.owner)) | 210 | url, **self.auth_header_for_user(url, user=machine.owner)) |
299 | 210 | 211 | ||
300 | 211 | data = simplejson.loads(response.content) | 212 | data = simplejson.loads(response.content) |
301 | 212 | self.assertEqual(expected, data) | 213 | self.assertEqual(expected, data) |
302 | @@ -216,8 +217,8 @@ | |||
303 | 216 | otheruser = self.factory.make_user() | 217 | otheruser = self.factory.make_user() |
304 | 217 | url = self.url % machine.uuid | 218 | url = self.url % machine.uuid |
305 | 218 | 219 | ||
308 | 219 | response = self.client.get(url, | 220 | response = self.client.get( |
309 | 220 | **self.auth_header_for_user(url, user=otheruser)) | 221 | url, **self.auth_header_for_user(url, user=otheruser)) |
310 | 221 | 222 | ||
311 | 222 | self.assertEqual(404, response.status_code) | 223 | self.assertEqual(404, response.status_code) |
312 | 223 | 224 | ||
313 | @@ -235,10 +236,10 @@ | |||
314 | 235 | machine = self.factory.make_machine(package_list=expected) | 236 | machine = self.factory.make_machine(package_list=expected) |
315 | 236 | url = self.url % machine.uuid | 237 | url = self.url % machine.uuid |
316 | 237 | data = simplejson.dumps({'package_list': expected, | 238 | data = simplejson.dumps({'package_list': expected, |
318 | 238 | 'packages_checksum': 'foo'}) | 239 | 'packages_checksum': 'foo'}) |
319 | 239 | 240 | ||
322 | 240 | response = self.client.post(url, data=data, | 241 | response = self.client.post( |
323 | 241 | content_type='application/json', | 242 | url, data=data, content_type='application/json', |
324 | 242 | **self.auth_header_for_user(url, user=machine.owner)) | 243 | **self.auth_header_for_user(url, user=machine.owner)) |
325 | 243 | 244 | ||
326 | 244 | self.assertContains(response, 'Success') | 245 | self.assertContains(response, 'Success') |
327 | @@ -250,8 +251,8 @@ | |||
328 | 250 | otheruser = self.factory.make_user() | 251 | otheruser = self.factory.make_user() |
329 | 251 | url = self.url % machine.uuid | 252 | url = self.url % machine.uuid |
330 | 252 | 253 | ||
333 | 253 | response = self.client.post(url, data='"foo"', | 254 | response = self.client.post( |
334 | 254 | content_type='application/json', | 255 | url, data='"foo"', content_type='application/json', |
335 | 255 | **self.auth_header_for_user(url, user=otheruser)) | 256 | **self.auth_header_for_user(url, user=otheruser)) |
336 | 256 | 257 | ||
337 | 257 | self.assertEqual(404, response.status_code) | 258 | self.assertEqual(404, response.status_code) |
338 | 258 | 259 | ||
339 | === modified file 'src/webcatalog/tests/test_commands.py' | |||
340 | --- src/webcatalog/tests/test_commands.py 2012-05-09 08:43:11 +0000 | |||
341 | +++ src/webcatalog/tests/test_commands.py 2012-06-06 18:03:20 +0000 | |||
342 | @@ -20,7 +20,7 @@ | |||
343 | 20 | from __future__ import ( | 20 | from __future__ import ( |
344 | 21 | absolute_import, | 21 | absolute_import, |
345 | 22 | with_statement, | 22 | with_statement, |
347 | 23 | ) | 23 | ) |
348 | 24 | import apt | 24 | import apt |
349 | 25 | import json | 25 | import json |
350 | 26 | import os | 26 | import os |
351 | @@ -29,7 +29,7 @@ | |||
352 | 29 | from datetime import ( | 29 | from datetime import ( |
353 | 30 | datetime, | 30 | datetime, |
354 | 31 | timedelta, | 31 | timedelta, |
356 | 32 | ) | 32 | ) |
357 | 33 | from decimal import Decimal | 33 | from decimal import Decimal |
358 | 34 | 34 | ||
359 | 35 | from django.conf import settings | 35 | from django.conf import settings |
360 | @@ -43,7 +43,7 @@ | |||
361 | 43 | patch, | 43 | patch, |
362 | 44 | MagicMock, | 44 | MagicMock, |
363 | 45 | Mock, | 45 | Mock, |
365 | 46 | ) | 46 | ) |
366 | 47 | from rnrclient import ReviewsStats | 47 | from rnrclient import ReviewsStats |
367 | 48 | 48 | ||
368 | 49 | from webcatalog.models import ( | 49 | from webcatalog.models import ( |
369 | @@ -52,7 +52,7 @@ | |||
370 | 52 | Exhibit, | 52 | Exhibit, |
371 | 53 | Nonce, | 53 | Nonce, |
372 | 54 | ReviewStatsImport, | 54 | ReviewStatsImport, |
374 | 55 | ) | 55 | ) |
375 | 56 | from webcatalog.management.commands import ( | 56 | from webcatalog.management.commands import ( |
376 | 57 | import_app_install_data, | 57 | import_app_install_data, |
377 | 58 | import_ratings_stats, | 58 | import_ratings_stats, |
378 | @@ -71,7 +71,7 @@ | |||
379 | 71 | 'ImportExhibitsTestCase', | 71 | 'ImportExhibitsTestCase', |
380 | 72 | 'ImportForPurchaseAppsTestCase', | 72 | 'ImportForPurchaseAppsTestCase', |
381 | 73 | 'ImportRatingsTestCase', | 73 | 'ImportRatingsTestCase', |
383 | 74 | ] | 74 | ] |
384 | 75 | 75 | ||
385 | 76 | 76 | ||
386 | 77 | class ImportAppInstallTestCase(TestCaseWithFactory): | 77 | class ImportAppInstallTestCase(TestCaseWithFactory): |
387 | @@ -80,7 +80,8 @@ | |||
388 | 80 | u'Firefox delivers safe, easy web browsing. A familiar user ' | 80 | u'Firefox delivers safe, easy web browsing. A familiar user ' |
389 | 81 | u'interface, enhanced security features including protection ' | 81 | u'interface, enhanced security features including protection ' |
390 | 82 | u'from online identity theft, and integrated search let you ' | 82 | u'from online identity theft, and integrated search let you ' |
392 | 83 | u'get the most out of the web.') | 83 | u'get the most out of the web.' |
393 | 84 | ) | ||
394 | 84 | 85 | ||
395 | 85 | # If you want to run these tests against the real apt cache (which | 86 | # If you want to run these tests against the real apt cache (which |
396 | 86 | # is slower, but the real deal) you can update the following | 87 | # is slower, but the real deal) you can update the following |
397 | @@ -90,7 +91,7 @@ | |||
398 | 90 | use_mock_apt_cache = True | 91 | use_mock_apt_cache = True |
399 | 91 | 92 | ||
400 | 92 | def make_mock_apt_package(self, name, description, uri='', summary='', | 93 | def make_mock_apt_package(self, name, description, uri='', summary='', |
402 | 93 | screenshot_url=''): | 94 | screenshot_url=''): |
403 | 94 | """Helper to DRY up creating a mock apt package.""" | 95 | """Helper to DRY up creating a mock apt package.""" |
404 | 95 | mock_package = Mock(spec=apt.package.Package) | 96 | mock_package = Mock(spec=apt.package.Package) |
405 | 96 | mock_package.candidate.description = description | 97 | mock_package.candidate.description = description |
406 | @@ -111,23 +112,23 @@ | |||
407 | 111 | And keeping the setUp readable. | 112 | And keeping the setUp readable. |
408 | 112 | """ | 113 | """ |
409 | 113 | mock_cache = MagicMock() | 114 | mock_cache = MagicMock() |
416 | 114 | mock_apt_firefox = self.make_mock_apt_package('firefox', | 115 | mock_apt_firefox = self.make_mock_apt_package( |
417 | 115 | description=self.FIREFOX_DESCRIPTION) | 116 | 'firefox', description=self.FIREFOX_DESCRIPTION) |
418 | 116 | mock_apt_scribus = self.make_mock_apt_package('scribus', | 117 | mock_apt_scribus = self.make_mock_apt_package( |
419 | 117 | description="Scribus description") | 118 | 'scribus', description="Scribus description") |
420 | 118 | mock_other_app = self.make_mock_apt_package('otherapp', | 119 | mock_other_app = self.make_mock_apt_package( |
421 | 119 | description="Otherapp description", | 120 | 'otherapp', description="Otherapp description", |
422 | 120 | summary="Otherapp the Internet\nA tagline for Otherapp", | 121 | summary="Otherapp the Internet\nA tagline for Otherapp", |
423 | 121 | screenshot_url="http://example.com/screenshot_for_otherapp.png") | 122 | screenshot_url="http://example.com/screenshot_for_otherapp.png") |
426 | 122 | mock_app_install_data = self.make_mock_apt_package('app-install-data', | 123 | mock_app_install_data = self.make_mock_apt_package( |
427 | 123 | description="App install desc.", | 124 | 'app-install-data', description="App install desc.", |
428 | 124 | uri='http://example.com/app-install-1.01.deb') | 125 | uri='http://example.com/app-install-1.01.deb') |
429 | 125 | cache_dict = { | 126 | cache_dict = { |
430 | 126 | 'firefox': mock_apt_firefox, | 127 | 'firefox': mock_apt_firefox, |
431 | 127 | 'scribus': mock_apt_scribus, | 128 | 'scribus': mock_apt_scribus, |
432 | 128 | 'otherapp': mock_other_app, | 129 | 'otherapp': mock_other_app, |
433 | 129 | 'app-install-data': mock_app_install_data, | 130 | 'app-install-data': mock_app_install_data, |
435 | 130 | } | 131 | } |
436 | 131 | 132 | ||
437 | 132 | def getitem(self, key): | 133 | def getitem(self, key): |
438 | 133 | return cache_dict.get(key, None) | 134 | return cache_dict.get(key, None) |
439 | @@ -151,8 +152,8 @@ | |||
440 | 151 | # We use a temporary on-disk cache location for our | 152 | # We use a temporary on-disk cache location for our |
441 | 152 | # tests. | 153 | # tests. |
442 | 153 | self.tmp_apt_cache = tempfile.mkdtemp() | 154 | self.tmp_apt_cache = tempfile.mkdtemp() |
445 | 154 | self.patch_cache_setting = patch.object(settings, | 155 | self.patch_cache_setting = patch.object( |
446 | 155 | 'DISK_APT_CACHE_LOCATION', self.tmp_apt_cache) | 156 | settings, 'DISK_APT_CACHE_LOCATION', self.tmp_apt_cache) |
447 | 156 | self.patch_cache_setting.start() | 157 | self.patch_cache_setting.start() |
448 | 157 | 158 | ||
449 | 158 | if self.use_mock_apt_cache: | 159 | if self.use_mock_apt_cache: |
450 | @@ -180,10 +181,10 @@ | |||
451 | 180 | call_command('import_app_install_data', 'onion', verbosity=0) | 181 | call_command('import_app_install_data', 'onion', verbosity=0) |
452 | 181 | 182 | ||
453 | 182 | self.assertEqual(2, mock_get_data_fn.call_count) | 183 | self.assertEqual(2, mock_get_data_fn.call_count) |
456 | 183 | for call_args, package_name in zip(mock_get_data_fn.call_args_list, | 184 | calls = ('app-install-data', 'app-install-data-partner') |
457 | 184 | ('app-install-data', 'app-install-data-partner')): | 185 | for call_args, pkgname in zip(mock_get_data_fn.call_args_list, calls): |
458 | 185 | args = call_args[0] | 186 | args = call_args[0] |
460 | 186 | self.assertEqual(package_name, args[0]) | 187 | self.assertEqual(pkgname, args[0]) |
461 | 187 | self.assertEqual('onion', args[1]) | 188 | self.assertEqual('onion', args[1]) |
462 | 188 | self.assertTrue(args[2].startswith('/tmp/tmp')) | 189 | self.assertTrue(args[2].startswith('/tmp/tmp')) |
463 | 189 | 190 | ||
464 | @@ -206,7 +207,8 @@ | |||
465 | 206 | def test_local_app_install_data(self): | 207 | def test_local_app_install_data(self): |
466 | 207 | # We don't hit the network when provided a local app-install deb. | 208 | # We don't hit the network when provided a local app-install deb. |
467 | 208 | with patch('urllib.urlretrieve') as mock_urlretrieve: | 209 | with patch('urllib.urlretrieve') as mock_urlretrieve: |
469 | 209 | call_command('import_app_install_data', 'natty', | 210 | call_command( |
470 | 211 | 'import_app_install_data', 'natty', | ||
471 | 210 | local_app_install_data=self.deb_location, | 212 | local_app_install_data=self.deb_location, |
472 | 211 | local_app_install_data_partner=self.deb_location, | 213 | local_app_install_data_partner=self.deb_location, |
473 | 212 | verbosity=0) | 214 | verbosity=0) |
474 | @@ -232,8 +234,8 @@ | |||
475 | 232 | def test_applications_updated(self): | 234 | def test_applications_updated(self): |
476 | 233 | # If applications already exist for the same series, it is | 235 | # If applications already exist for the same series, it is |
477 | 234 | # updated. | 236 | # updated. |
480 | 235 | app = self.factory.make_application(package_name='scribus', | 237 | app = self.factory.make_application( |
481 | 236 | comment='old comment', | 238 | package_name='scribus', comment='old comment', |
482 | 237 | distroseries=self.factory.make_distroseries(code_name='natty')) | 239 | distroseries=self.factory.make_distroseries(code_name='natty')) |
483 | 238 | 240 | ||
484 | 239 | call_command( | 241 | call_command( |
485 | @@ -250,8 +252,8 @@ | |||
486 | 250 | def test_same_app_different_distroseries(self): | 252 | def test_same_app_different_distroseries(self): |
487 | 251 | # Importing the same app (package_name) as an existing app, but | 253 | # Importing the same app (package_name) as an existing app, but |
488 | 252 | # for a different distroseries creates a new record. | 254 | # for a different distroseries creates a new record. |
491 | 253 | app = self.factory.make_application(package_name='scribus', | 255 | app = self.factory.make_application( |
492 | 254 | comment='old comment', | 256 | package_name='scribus', comment='old comment', |
493 | 255 | distroseries=self.factory.make_distroseries(code_name='natty')) | 257 | distroseries=self.factory.make_distroseries(code_name='natty')) |
494 | 256 | 258 | ||
495 | 257 | call_command( | 259 | call_command( |
496 | @@ -330,7 +332,8 @@ | |||
497 | 330 | self.assertEqual("Browse the World Wide Web", firefox.comment) | 332 | self.assertEqual("Browse the World Wide Web", firefox.comment) |
498 | 331 | 333 | ||
499 | 332 | def test_description_updated_in_app(self): | 334 | def test_description_updated_in_app(self): |
501 | 333 | app = self.factory.make_application(package_name='scribus', | 335 | app = self.factory.make_application( |
502 | 336 | package_name='scribus', | ||
503 | 334 | distroseries=self.factory.make_distroseries(code_name='natty')) | 337 | distroseries=self.factory.make_distroseries(code_name='natty')) |
504 | 335 | 338 | ||
505 | 336 | call_command( | 339 | call_command( |
506 | @@ -355,18 +358,19 @@ | |||
507 | 355 | 358 | ||
508 | 356 | natty_cache = os.path.join(self.tmp_apt_cache, 'natty') | 359 | natty_cache = os.path.join(self.tmp_apt_cache, 'natty') |
509 | 357 | sources_list_path = os.path.join(natty_cache, 'etc', 'apt', | 360 | sources_list_path = os.path.join(natty_cache, 'etc', 'apt', |
511 | 358 | 'sources.list') | 361 | 'sources.list') |
512 | 359 | self.assertTrue(os.path.exists(os.path.join(sources_list_path))) | 362 | self.assertTrue(os.path.exists(os.path.join(sources_list_path))) |
513 | 360 | with open(sources_list_path) as content: | 363 | with open(sources_list_path) as content: |
514 | 361 | sources_list_content = content.read() | 364 | sources_list_content = content.read() |
523 | 362 | self.assertEqual(""" | 365 | sources = [ |
524 | 363 | deb http://archive.ubuntu.com/ubuntu natty main universe | 366 | '', # empty line |
525 | 364 | deb http://archive.ubuntu.com/ubuntu natty-updates main universe | 367 | 'http://archive.ubuntu.com/ubuntu natty main universe', |
526 | 365 | deb http://archive.ubuntu.com/ubuntu natty-backports main universe | 368 | 'http://archive.ubuntu.com/ubuntu natty-updates main universe', |
527 | 366 | deb http://archive.canonical.com/ubuntu natty partner | 369 | 'http://archive.ubuntu.com/ubuntu natty-backports main universe', |
528 | 367 | deb http://extras.ubuntu.com/ubuntu natty main | 370 | 'http://archive.canonical.com/ubuntu natty partner', |
529 | 368 | """, | 371 | 'http://extras.ubuntu.com/ubuntu natty main', |
530 | 369 | sources_list_content) | 372 | ] |
531 | 373 | self.assertEqual('\ndeb '.join(sources) + '\n', sources_list_content) | ||
532 | 370 | if self.use_mock_apt_cache: | 374 | if self.use_mock_apt_cache: |
533 | 371 | self.mock_cache_class.assert_called_with(rootdir=natty_cache) | 375 | self.mock_cache_class.assert_called_with(rootdir=natty_cache) |
534 | 372 | self.assertEqual(1, self.mock_cache.update.call_count) | 376 | self.assertEqual(1, self.mock_cache.update.call_count) |
535 | @@ -512,20 +516,19 @@ | |||
536 | 512 | 516 | ||
537 | 513 | def mock_urlopen_fn(url): | 517 | def mock_urlopen_fn(url): |
538 | 514 | """Return predetermined test_data content for given urls.""" | 518 | """Return predetermined test_data content for given urls.""" |
541 | 515 | available_apps_url = '%sapplications/any/ubuntu/any/any/' % ( | 519 | available_apps_url = (settings.SCA_API_URL + |
542 | 516 | settings.SCA_API_URL) | 520 | 'applications/any/ubuntu/any/any/') |
543 | 517 | icon_arb_url = ('http://sc.staging.ubuntu.com/' | 521 | icon_arb_url = ('http://sc.staging.ubuntu.com/' |
545 | 518 | 'site_media/appmedia/2012/04/ktip.png') | 522 | 'site_media/appmedia/2012/04/ktip.png') |
546 | 519 | icon_hello_url = ('http://localhost:8000/' | 523 | icon_hello_url = ('http://localhost:8000/' |
548 | 520 | 'site_media/icons/2011/06/eg_64x64.png') | 524 | 'site_media/icons/2011/06/eg_64x64.png') |
549 | 521 | filenames = { | 525 | filenames = { |
550 | 522 | available_apps_url: 'sca_apps.txt', | 526 | available_apps_url: 'sca_apps.txt', |
551 | 523 | icon_arb_url: 'ubuntu-cof.png', | 527 | icon_arb_url: 'ubuntu-cof.png', |
552 | 524 | icon_hello_url: 'ubuntu-cof.png', | 528 | icon_hello_url: 'ubuntu-cof.png', |
554 | 525 | } | 529 | } |
555 | 526 | curdir = os.path.dirname(__file__) | 530 | curdir = os.path.dirname(__file__) |
558 | 527 | sca_apps_file = os.path.join(curdir, 'test_data', | 531 | sca_apps_file = os.path.join(curdir, 'test_data', filenames[url]) |
557 | 528 | filenames[url]) | ||
559 | 529 | with open(sca_apps_file) as content: | 532 | with open(sca_apps_file) as content: |
560 | 530 | self.response_content = content.read() | 533 | self.response_content = content.read() |
561 | 531 | mock_response = Mock() | 534 | mock_response = Mock() |
562 | @@ -543,7 +546,7 @@ | |||
563 | 543 | call_command('import_for_purchase_apps') | 546 | call_command('import_for_purchase_apps') |
564 | 544 | 547 | ||
565 | 545 | app_for_purchase = Application.objects.get(name='MyApp', | 548 | app_for_purchase = Application.objects.get(name='MyApp', |
567 | 546 | distroseries=self.natty) | 549 | distroseries=self.natty) |
568 | 547 | self.assertEqual(True, app_for_purchase.for_purchase) | 550 | self.assertEqual(True, app_for_purchase.for_purchase) |
569 | 548 | self.assertTrue(app_for_purchase.description.find('hello') > -1) | 551 | self.assertTrue(app_for_purchase.description.find('hello') > -1) |
570 | 549 | 552 | ||
571 | @@ -551,30 +554,31 @@ | |||
572 | 551 | call_command('import_for_purchase_apps') | 554 | call_command('import_for_purchase_apps') |
573 | 552 | 555 | ||
574 | 553 | app = Application.objects.get(name='MyApp', | 556 | app = Application.objects.get(name='MyApp', |
576 | 554 | distroseries=self.natty) | 557 | distroseries=self.natty) |
577 | 555 | self.assertEqual(2, len(app.available_distroseries())) | 558 | self.assertEqual(2, len(app.available_distroseries())) |
578 | 556 | 559 | ||
579 | 557 | def test_app_gets_price(self): | 560 | def test_app_gets_price(self): |
580 | 558 | call_command('import_for_purchase_apps') | 561 | call_command('import_for_purchase_apps') |
581 | 559 | 562 | ||
582 | 560 | app = Application.objects.get(name='MyApp', | 563 | app = Application.objects.get(name='MyApp', |
584 | 561 | distroseries=self.natty) | 564 | distroseries=self.natty) |
585 | 562 | self.assertEqual(Decimal('2.50'), app.price) | 565 | self.assertEqual(Decimal('2.50'), app.price) |
586 | 563 | 566 | ||
587 | 564 | def test_existing_app_gets_updated_by_archive_id(self): | 567 | def test_existing_app_gets_updated_by_archive_id(self): |
589 | 565 | self.factory.make_application(archive_id='launchpad_zematynnad2/myppa', | 568 | self.factory.make_application( |
590 | 569 | archive_id='launchpad_zematynnad2/myppa', | ||
591 | 566 | package_name='somethingelse', distroseries=self.maverick) | 570 | package_name='somethingelse', distroseries=self.maverick) |
598 | 567 | self.factory.make_application(archive_id='launchpad_zematynnad2/myppa', | 571 | self.factory.make_application( |
599 | 568 | package_name='somethingelse', | 572 | archive_id='launchpad_zematynnad2/myppa', |
600 | 569 | distroseries=self.natty) | 573 | package_name='somethingelse', distroseries=self.natty) |
601 | 570 | self.assertEqual(2, | 574 | apps = Application.objects.filter( |
602 | 571 | Application.objects.filter( | 575 | distroseries__in=(self.natty, self.maverick)).count() |
603 | 572 | distroseries__in=(self.natty, self.maverick)).count()) | 576 | self.assertEqual(2, apps) |
604 | 573 | 577 | ||
605 | 574 | call_command('import_for_purchase_apps') | 578 | call_command('import_for_purchase_apps') |
606 | 575 | 579 | ||
607 | 576 | actual_apps = Application.objects.filter( | 580 | actual_apps = Application.objects.filter( |
609 | 577 | distroseries__in=(self.natty, self.maverick)) | 581 | distroseries__in=(self.natty, self.maverick)) |
610 | 578 | self.assertEqual(2, actual_apps.count()) | 582 | self.assertEqual(2, actual_apps.count()) |
611 | 579 | for app in actual_apps: | 583 | for app in actual_apps: |
612 | 580 | self.assertEqual('launchpad_zematynnad2/myppa', app.archive_id) | 584 | self.assertEqual('launchpad_zematynnad2/myppa', app.archive_id) |
613 | @@ -587,7 +591,7 @@ | |||
614 | 587 | 'http://sc.staging.ubuntu.com/' | 591 | 'http://sc.staging.ubuntu.com/' |
615 | 588 | 'site_media/appmedia/2012/04/ktip.png') | 592 | 'site_media/appmedia/2012/04/ktip.png') |
616 | 589 | app = Application.objects.get(name='MyApp', | 593 | app = Application.objects.get(name='MyApp', |
618 | 590 | distroseries=self.natty) | 594 | distroseries=self.natty) |
619 | 591 | # The urlopen double returns the test_data/ubuntu-cof.png which has | 595 | # The urlopen double returns the test_data/ubuntu-cof.png which has |
620 | 592 | # a size of 2438. | 596 | # a size of 2438. |
621 | 593 | self.assertEqual(2438, app.icon.size) | 597 | self.assertEqual(2438, app.icon.size) |
622 | @@ -596,21 +600,21 @@ | |||
623 | 596 | call_command('import_for_purchase_apps') | 600 | call_command('import_for_purchase_apps') |
624 | 597 | 601 | ||
625 | 598 | app = Application.objects.get(package_name='hello', | 602 | app = Application.objects.get(package_name='hello', |
627 | 599 | distroseries=self.natty) | 603 | distroseries=self.natty) |
628 | 600 | self.assertEqual('1.2.3', app.version) | 604 | self.assertEqual('1.2.3', app.version) |
629 | 601 | 605 | ||
630 | 602 | def test_checks_latest(self): | 606 | def test_checks_latest(self): |
631 | 603 | call_command('import_for_purchase_apps') | 607 | call_command('import_for_purchase_apps') |
632 | 604 | 608 | ||
633 | 605 | app = Application.objects.get(package_name='hello', | 609 | app = Application.objects.get(package_name='hello', |
635 | 606 | distroseries=self.natty) | 610 | distroseries=self.natty) |
636 | 607 | self.assertTrue(app.is_latest) | 611 | self.assertTrue(app.is_latest) |
637 | 608 | 612 | ||
638 | 609 | def test_app_gets_screenshots(self): | 613 | def test_app_gets_screenshots(self): |
639 | 610 | call_command('import_for_purchase_apps') | 614 | call_command('import_for_purchase_apps') |
640 | 611 | 615 | ||
641 | 612 | app = Application.objects.get(package_name='hello', | 616 | app = Application.objects.get(package_name='hello', |
643 | 613 | distroseries=self.natty) | 617 | distroseries=self.natty) |
644 | 614 | qs = app.applicationmedia_set.filter(media_type='screenshot') | 618 | qs = app.applicationmedia_set.filter(media_type='screenshot') |
645 | 615 | self.assertEqual(2, qs.count()) | 619 | self.assertEqual(2, qs.count()) |
646 | 616 | 620 | ||
647 | @@ -648,13 +652,13 @@ | |||
648 | 648 | 652 | ||
649 | 649 | def test_creates_last_import_record(self): | 653 | def test_creates_last_import_record(self): |
650 | 650 | onion = self.factory.make_distroseries(code_name='onion') | 654 | onion = self.factory.make_distroseries(code_name='onion') |
653 | 651 | self.assertEqual(0, | 655 | self.assertEqual( |
654 | 652 | ReviewStatsImport.objects.filter(distroseries=onion).count()) | 656 | 0, ReviewStatsImport.objects.filter(distroseries=onion).count()) |
655 | 653 | 657 | ||
656 | 654 | call_command('import_ratings_stats', 'onion') | 658 | call_command('import_ratings_stats', 'onion') |
657 | 655 | 659 | ||
660 | 656 | self.assertEqual(1, | 660 | self.assertEqual( |
661 | 657 | ReviewStatsImport.objects.filter(distroseries=onion).count()) | 661 | 1, ReviewStatsImport.objects.filter(distroseries=onion).count()) |
662 | 658 | 662 | ||
663 | 659 | def test_updates_last_import_record(self): | 663 | def test_updates_last_import_record(self): |
664 | 660 | onion = self.factory.make_distroseries(code_name='onion') | 664 | onion = self.factory.make_distroseries(code_name='onion') |
665 | @@ -696,13 +700,13 @@ | |||
666 | 696 | # apps in the db. | 700 | # apps in the db. |
667 | 697 | natty = self.factory.make_distroseries(code_name='natty') | 701 | natty = self.factory.make_distroseries(code_name='natty') |
668 | 698 | scribus = self.factory.make_application(package_name='scribus', | 702 | scribus = self.factory.make_application(package_name='scribus', |
670 | 699 | distroseries=natty) | 703 | distroseries=natty) |
671 | 700 | otherapp = self.factory.make_application(package_name='otherapp', | 704 | otherapp = self.factory.make_application(package_name='otherapp', |
673 | 701 | distroseries=natty) | 705 | distroseries=natty) |
674 | 702 | 706 | ||
678 | 703 | scribus_stats = ReviewsStats.from_dict(dict(package_name='scribus', | 707 | d = dict(package_name='scribus', ratings_average='4.00', |
679 | 704 | ratings_average='4.00', ratings_total=4, | 708 | ratings_total=4, histogram='[0, 1, 0, 1, 2]') |
680 | 705 | histogram='[0, 1, 0, 1, 2]')) | 709 | scribus_stats = ReviewsStats.from_dict(d) |
681 | 706 | self.mock_review_stats.return_value = [scribus_stats] | 710 | self.mock_review_stats.return_value = [scribus_stats] |
682 | 707 | call_command('import_ratings_stats', 'natty') | 711 | call_command('import_ratings_stats', 'natty') |
683 | 708 | 712 | ||
684 | @@ -717,10 +721,12 @@ | |||
685 | 717 | def test_update_works_with_many_stats(self): | 721 | def test_update_works_with_many_stats(self): |
686 | 718 | """Ensure update_apps_with_stats doesn't fail with many ratings.""" | 722 | """Ensure update_apps_with_stats doesn't fail with many ratings.""" |
687 | 719 | natty = self.factory.make_distroseries(code_name='natty') | 723 | natty = self.factory.make_distroseries(code_name='natty') |
689 | 720 | stats = [ReviewsStats.from_dict(dict( | 724 | d = dict( |
690 | 721 | package_name=self.factory.get_unique_string(prefix='package-'), | 725 | package_name=self.factory.get_unique_string(prefix='package-'), |
691 | 722 | ratings_average='5.00', ratings_total=1, | 726 | ratings_average='5.00', ratings_total=1, |
693 | 723 | histogram='[0, 0, 0, 0, 1]')) for x in range(3000)] | 727 | histogram='[0, 0, 0, 0, 1]', |
694 | 728 | ) | ||
695 | 729 | stats = [ReviewsStats.from_dict(d.copy()) for x in range(3000)] | ||
696 | 724 | command = import_ratings_stats.Command() | 730 | command = import_ratings_stats.Command() |
697 | 725 | 731 | ||
698 | 726 | # update_apps_with_stats returns None on success: | 732 | # update_apps_with_stats returns None on success: |
699 | @@ -730,11 +736,12 @@ | |||
700 | 730 | """Ensure update_apps_with_stats works with null histogram data""" | 736 | """Ensure update_apps_with_stats works with null histogram data""" |
701 | 731 | app = self.factory.make_application() | 737 | app = self.factory.make_application() |
702 | 732 | stats = [ReviewsStats.from_dict(dict(package_name=app.package_name, | 738 | stats = [ReviewsStats.from_dict(dict(package_name=app.package_name, |
704 | 733 | ratings_average='5.00', ratings_total=1, histogram=None))] | 739 | ratings_average='5.00', |
705 | 740 | ratings_total=1, histogram=None))] | ||
706 | 734 | command = import_ratings_stats.Command() | 741 | command = import_ratings_stats.Command() |
707 | 735 | 742 | ||
710 | 736 | self.assertIsNone(command.update_apps_with_stats(app.distroseries, | 743 | result = command.update_apps_with_stats(app.distroseries, stats) |
711 | 737 | stats)) | 744 | self.assertIsNone(result) |
712 | 738 | 745 | ||
713 | 739 | 746 | ||
714 | 740 | class ImportExhibitsTestCase(TestCaseWithFactory): | 747 | class ImportExhibitsTestCase(TestCaseWithFactory): |
715 | @@ -744,20 +751,22 @@ | |||
716 | 744 | data = [] | 751 | data = [] |
717 | 745 | for exhibit in exhibits: | 752 | for exhibit in exhibits: |
718 | 746 | ds = exhibit.distroseries.get() | 753 | ds = exhibit.distroseries.get() |
720 | 747 | data.append({'package_names': exhibit.package_names, | 754 | data.append({ |
721 | 755 | 'package_names': exhibit.package_names, | ||
722 | 748 | 'banner_url': exhibit.banner_url, | 756 | 'banner_url': exhibit.banner_url, |
723 | 749 | 'version': ds.version, | 757 | 'version': ds.version, |
724 | 750 | 'code_name': ds.code_name, | 758 | 'code_name': ds.code_name, |
725 | 751 | 'html': exhibit.html, | 759 | 'html': exhibit.html, |
726 | 752 | 'date_created': str(exhibit.date_created), | 760 | 'date_created': str(exhibit.date_created), |
727 | 753 | 'weight': str(exhibit.weight), | 761 | 'weight': str(exhibit.weight), |
729 | 754 | 'id': exhibit.sca_id}) | 762 | 'id': exhibit.sca_id, |
730 | 763 | }) | ||
731 | 755 | if changes: | 764 | if changes: |
732 | 756 | for atts, change in zip(data, changes): | 765 | for atts, change in zip(data, changes): |
733 | 757 | atts.update(change) | 766 | atts.update(change) |
734 | 758 | for xibit in data: | 767 | for xibit in data: |
735 | 759 | xibit['distroseries'] = [{'code_name': xibit.pop('code_name'), | 768 | xibit['distroseries'] = [{'code_name': xibit.pop('code_name'), |
737 | 760 | 'version': xibit.pop('version')}] | 769 | 'version': xibit.pop('version')}] |
738 | 761 | return_value = json.dumps(data) | 770 | return_value = json.dumps(data) |
739 | 762 | response.read.return_value = return_value | 771 | response.read.return_value = return_value |
740 | 763 | return response | 772 | return response |
741 | @@ -778,10 +787,10 @@ | |||
742 | 778 | new_package_names = self.factory.get_unique_string(prefix='new-') | 787 | new_package_names = self.factory.get_unique_string(prefix='new-') |
743 | 779 | new_banner_url = self.factory.get_unique_string(prefix='new-') | 788 | new_banner_url = self.factory.get_unique_string(prefix='new-') |
744 | 780 | new_html = self.factory.get_unique_string(prefix='new-') | 789 | new_html = self.factory.get_unique_string(prefix='new-') |
749 | 781 | mock_urlopen.return_value = self.mock_response([xibit], changes=[ | 790 | mock_urlopen.return_value = self.mock_response( |
750 | 782 | {'package_names': new_package_names, 'banner_url': new_banner_url, | 791 | [xibit], changes=[{'package_names': new_package_names, |
751 | 783 | 'html': new_html, 'weight': 3}]) | 792 | 'banner_url': new_banner_url, |
752 | 784 | 793 | 'html': new_html, 'weight': 3}]) | |
753 | 785 | call_command('import_exhibits') | 794 | call_command('import_exhibits') |
754 | 786 | 795 | ||
755 | 787 | retrieved = Exhibit.objects.get() | 796 | retrieved = Exhibit.objects.get() |
756 | @@ -795,8 +804,8 @@ | |||
757 | 795 | def test_creates_exhibit_if_scaid_does_not_match(self, mock_urlopen): | 804 | def test_creates_exhibit_if_scaid_does_not_match(self, mock_urlopen): |
758 | 796 | xibit = self.factory.make_exhibit(published=False) | 805 | xibit = self.factory.make_exhibit(published=False) |
759 | 797 | new_id = xibit.sca_id + 20 | 806 | new_id = xibit.sca_id + 20 |
762 | 798 | mock_urlopen.return_value = self.mock_response([xibit], changes=[ | 807 | mock_urlopen.return_value = self.mock_response( |
763 | 799 | {'id': new_id}]) | 808 | [xibit], changes=[{'id': new_id}]) |
764 | 800 | 809 | ||
765 | 801 | call_command('import_exhibits') | 810 | call_command('import_exhibits') |
766 | 802 | 811 | ||
767 | @@ -807,7 +816,7 @@ | |||
768 | 807 | @patch('urllib.urlopen') | 816 | @patch('urllib.urlopen') |
769 | 808 | def test_display_is_left_untouched(self, mock_urlopen): | 817 | def test_display_is_left_untouched(self, mock_urlopen): |
770 | 809 | xibits = [self.factory.make_exhibit(display=d) | 818 | xibits = [self.factory.make_exhibit(display=d) |
772 | 810 | for d in [False, True, None]] | 819 | for d in [False, True, None]] |
773 | 811 | 820 | ||
774 | 812 | mock_urlopen.return_value = self.mock_response(xibits) | 821 | mock_urlopen.return_value = self.mock_response(xibits) |
775 | 813 | 822 | ||
776 | @@ -826,8 +835,8 @@ | |||
777 | 826 | banner_url = 'http://example.com/foo/bar/baz.png' | 835 | banner_url = 'http://example.com/foo/bar/baz.png' |
778 | 827 | expected = '<img src="http://example.com/foo/bar/baz.png">' | 836 | expected = '<img src="http://example.com/foo/bar/baz.png">' |
779 | 828 | 837 | ||
782 | 829 | mock_urlopen.return_value = self.mock_response([xibit], | 838 | mock_urlopen.return_value = self.mock_response( |
783 | 830 | changes=[{'banner_url': banner_url, 'html': html}]) | 839 | [xibit], changes=[{'banner_url': banner_url, 'html': html}]) |
784 | 831 | 840 | ||
785 | 832 | call_command('import_exhibits') | 841 | call_command('import_exhibits') |
786 | 833 | 842 | ||
787 | @@ -838,13 +847,13 @@ | |||
788 | 838 | class CheckAllLatestTestCase(TestCaseWithFactory): | 847 | class CheckAllLatestTestCase(TestCaseWithFactory): |
789 | 839 | def test_updates_all(self): | 848 | def test_updates_all(self): |
790 | 840 | natty = self.factory.make_distroseries(code_name='natty', | 849 | natty = self.factory.make_distroseries(code_name='natty', |
792 | 841 | version='11.04') | 850 | version='11.04') |
793 | 842 | oneiric = self.factory.make_distroseries(code_name='oneiric', | 851 | oneiric = self.factory.make_distroseries(code_name='oneiric', |
795 | 843 | version='11.10') | 852 | version='11.10') |
796 | 844 | self.factory.make_application(package_name='foo', distroseries=natty) | 853 | self.factory.make_application(package_name='foo', distroseries=natty) |
797 | 845 | self.factory.make_application(package_name='foo', distroseries=oneiric) | 854 | self.factory.make_application(package_name='foo', distroseries=oneiric) |
798 | 846 | self.factory.make_application(package_name='bar', distroseries=natty, | 855 | self.factory.make_application(package_name='bar', distroseries=natty, |
800 | 847 | is_latest=True) | 856 | is_latest=True) |
801 | 848 | self.factory.make_application(package_name='baz', distroseries=oneiric) | 857 | self.factory.make_application(package_name='baz', distroseries=oneiric) |
802 | 849 | 858 | ||
803 | 850 | call_command('check_all_latest') | 859 | call_command('check_all_latest') |
804 | @@ -857,13 +866,14 @@ | |||
805 | 857 | 866 | ||
806 | 858 | 867 | ||
807 | 859 | class CleanupTestCase(TestCaseWithFactory): | 868 | class CleanupTestCase(TestCaseWithFactory): |
808 | 869 | |||
809 | 860 | @patch('webcatalog.management.commands.cleanup.connection') | 870 | @patch('webcatalog.management.commands.cleanup.connection') |
810 | 861 | @patch('sys.stdout') | 871 | @patch('sys.stdout') |
811 | 862 | def run_and_check_output_and_sql(self, func, output, sql, mock_stdout, | 872 | def run_and_check_output_and_sql(self, func, output, sql, mock_stdout, |
813 | 863 | mock_connection): | 873 | mock_connection): |
814 | 864 | func() | 874 | func() |
815 | 865 | actual_output = ''.join(str(call[0][0]) | 875 | actual_output = ''.join(str(call[0][0]) |
817 | 866 | for call in mock_stdout.write.call_args_list) | 876 | for call in mock_stdout.write.call_args_list) |
818 | 867 | self.assertEqual(output, actual_output.split('\n')) | 877 | self.assertEqual(output, actual_output.split('\n')) |
819 | 868 | call_list = mock_connection.cursor.return_value.execute.call_args_list | 878 | call_list = mock_connection.cursor.return_value.execute.call_args_list |
820 | 869 | for expected, call in zip(sql, call_list): | 879 | for expected, call in zip(sql, call_list): |
821 | @@ -875,15 +885,16 @@ | |||
822 | 875 | def cleanup(): | 885 | def cleanup(): |
823 | 876 | call_command('cleanup', 'webcatalog_nonce') | 886 | call_command('cleanup', 'webcatalog_nonce') |
824 | 877 | output = ['Opening cursor', | 887 | output = ['Opening cursor', |
827 | 878 | 'Removed 0 rows (0 total removed). Batch size 1', | 888 | 'Removed 0 rows (0 total removed). Batch size 1', |
828 | 879 | 'All done.', ''] | 889 | 'All done.', ''] |
829 | 880 | sql = [ | 890 | sql = [ |
830 | 881 | ('CLOSE ALL',), | 891 | ('CLOSE ALL',), |
831 | 882 | ('DECLARE _oauth_nonce_clean NO SCROLL CURSOR WITH HOLD FOR ' | 892 | ('DECLARE _oauth_nonce_clean NO SCROLL CURSOR WITH HOLD FOR ' |
832 | 883 | 'SELECT id FROM webcatalog_nonce ' | 893 | 'SELECT id FROM webcatalog_nonce ' |
833 | 884 | "WHERE created_at < (CURRENT_TIMESTAMP - INTERVAL '5' HOUR) " | 894 | "WHERE created_at < (CURRENT_TIMESTAMP - INTERVAL '5' HOUR) " |
834 | 885 | 'ORDER BY created_at',), | 895 | 'ORDER BY created_at',), |
836 | 886 | ('FETCH %s FROM _oauth_nonce_clean', [1])] | 896 | ('FETCH %s FROM _oauth_nonce_clean', [1]), |
837 | 897 | ] | ||
838 | 887 | self.run_and_check_output_and_sql(cleanup, output, sql) | 898 | self.run_and_check_output_and_sql(cleanup, output, sql) |
839 | 888 | 899 | ||
840 | 889 | @skipUnless(connection.vendor == 'postgresql', "Requires postgresql") | 900 | @skipUnless(connection.vendor == 'postgresql', "Requires postgresql") |
841 | @@ -891,14 +902,15 @@ | |||
842 | 891 | def cleanup(): | 902 | def cleanup(): |
843 | 892 | call_command('cleanup', 'django_session') | 903 | call_command('cleanup', 'django_session') |
844 | 893 | output = ['Opening cursor', | 904 | output = ['Opening cursor', |
847 | 894 | 'Removed 0 rows (0 total removed). Batch size 1', | 905 | 'Removed 0 rows (0 total removed). Batch size 1', |
848 | 895 | 'All done.', ''] | 906 | 'All done.', ''] |
849 | 896 | sql = [ | 907 | sql = [ |
850 | 897 | ('CLOSE ALL',), | 908 | ('CLOSE ALL',), |
851 | 898 | ('DECLARE _django_session_clean NO SCROLL CURSOR WITH HOLD FOR ' | 909 | ('DECLARE _django_session_clean NO SCROLL CURSOR WITH HOLD FOR ' |
852 | 899 | 'SELECT session_key FROM django_session WHERE expire_date < ' | 910 | 'SELECT session_key FROM django_session WHERE expire_date < ' |
853 | 900 | 'CURRENT_TIMESTAMP ORDER BY expire_date',), | 911 | 'CURRENT_TIMESTAMP ORDER BY expire_date',), |
855 | 901 | ('FETCH %s FROM _django_session_clean', [1])] | 912 | ('FETCH %s FROM _django_session_clean', [1]), |
856 | 913 | ] | ||
857 | 902 | self.run_and_check_output_and_sql(cleanup, output, sql) | 914 | self.run_and_check_output_and_sql(cleanup, output, sql) |
858 | 903 | 915 | ||
859 | 904 | 916 | ||
860 | @@ -917,8 +929,8 @@ | |||
861 | 917 | Removed 0 rows (4 total removed). Batch size 4 | 929 | Removed 0 rows (4 total removed). Batch size 4 |
862 | 918 | All done. | 930 | All done. |
863 | 919 | ''' | 931 | ''' |
866 | 920 | actual_output = ''.join(str(call[0][0]) | 932 | actual_output = ''.join( |
867 | 921 | for call in self.mock_stdout.write.call_args_list) | 933 | str(call[0][0]) for call in self.mock_stdout.write.call_args_list) |
868 | 922 | self.assertEqual(expected_output, actual_output) | 934 | self.assertEqual(expected_output, actual_output) |
869 | 923 | 935 | ||
870 | 924 | @skipUnless(connection.vendor == 'postgresql', "Requires postgresql") | 936 | @skipUnless(connection.vendor == 'postgresql', "Requires postgresql") |
871 | 925 | 937 | ||
872 | === modified file 'src/webcatalog/tests/test_context_processors.py' | |||
873 | --- src/webcatalog/tests/test_context_processors.py 2012-01-06 14:24:49 +0000 | |||
874 | +++ src/webcatalog/tests/test_context_processors.py 2012-06-06 18:03:20 +0000 | |||
875 | @@ -22,7 +22,7 @@ | |||
876 | 22 | __metaclass__ = type | 22 | __metaclass__ = type |
877 | 23 | __all__ = [ | 23 | __all__ = [ |
878 | 24 | 'GoogleAnalyticsTestCase', | 24 | 'GoogleAnalyticsTestCase', |
880 | 25 | ] | 25 | ] |
881 | 26 | 26 | ||
882 | 27 | from django.core.urlresolvers import reverse | 27 | from django.core.urlresolvers import reverse |
883 | 28 | from django.test import TestCase | 28 | from django.test import TestCase |
884 | 29 | 29 | ||
885 | === modified file 'src/webcatalog/tests/test_department_filters.py' | |||
886 | --- src/webcatalog/tests/test_department_filters.py 2011-09-12 13:37:24 +0000 | |||
887 | +++ src/webcatalog/tests/test_department_filters.py 2012-06-06 18:03:20 +0000 | |||
888 | @@ -20,7 +20,7 @@ | |||
889 | 20 | from __future__ import ( | 20 | from __future__ import ( |
890 | 21 | absolute_import, | 21 | absolute_import, |
891 | 22 | with_statement, | 22 | with_statement, |
893 | 23 | ) | 23 | ) |
894 | 24 | 24 | ||
895 | 25 | 25 | ||
896 | 26 | from webcatalog.tests.factory import TestCaseWithFactory | 26 | from webcatalog.tests.factory import TestCaseWithFactory |
897 | @@ -28,12 +28,12 @@ | |||
898 | 28 | category_filter, | 28 | category_filter, |
899 | 29 | package_name_filter, | 29 | package_name_filter, |
900 | 30 | section_filter | 30 | section_filter |
902 | 31 | ) | 31 | ) |
903 | 32 | 32 | ||
904 | 33 | __metaclass__ = type | 33 | __metaclass__ = type |
905 | 34 | __all__ = [ | 34 | __all__ = [ |
906 | 35 | 'DepartmentFilterTestCase', | 35 | 'DepartmentFilterTestCase', |
908 | 36 | ] | 36 | ] |
909 | 37 | 37 | ||
910 | 38 | 38 | ||
911 | 39 | class DepartmentFilterTestCase(TestCaseWithFactory): | 39 | class DepartmentFilterTestCase(TestCaseWithFactory): |
912 | 40 | 40 | ||
913 | === modified file 'src/webcatalog/tests/test_forms.py' | |||
914 | --- src/webcatalog/tests/test_forms.py 2012-05-03 13:06:53 +0000 | |||
915 | +++ src/webcatalog/tests/test_forms.py 2012-06-06 18:03:20 +0000 | |||
916 | @@ -20,7 +20,7 @@ | |||
917 | 20 | from __future__ import ( | 20 | from __future__ import ( |
918 | 21 | absolute_import, | 21 | absolute_import, |
919 | 22 | with_statement, | 22 | with_statement, |
921 | 23 | ) | 23 | ) |
922 | 24 | 24 | ||
923 | 25 | from django.forms import ValidationError | 25 | from django.forms import ValidationError |
924 | 26 | from django.test import TestCase | 26 | from django.test import TestCase |
925 | @@ -32,7 +32,7 @@ | |||
926 | 32 | desktop_field_mappings, | 32 | desktop_field_mappings, |
927 | 33 | ForPurchaseApplicationForm, | 33 | ForPurchaseApplicationForm, |
928 | 34 | MultiURLField, | 34 | MultiURLField, |
930 | 35 | ) | 35 | ) |
931 | 36 | from webcatalog.models import Application, ApplicationMedia | 36 | from webcatalog.models import Application, ApplicationMedia |
932 | 37 | from webcatalog.tests.factory import TestCaseWithFactory | 37 | from webcatalog.tests.factory import TestCaseWithFactory |
933 | 38 | 38 | ||
934 | @@ -41,15 +41,14 @@ | |||
935 | 41 | 'ApplicationFormTestCase', | 41 | 'ApplicationFormTestCase', |
936 | 42 | 'ForPurchaseApplicationFormTestCase', | 42 | 'ForPurchaseApplicationFormTestCase', |
937 | 43 | 'MultiURLFieldTestCase', | 43 | 'MultiURLFieldTestCase', |
939 | 44 | ] | 44 | ] |
940 | 45 | 45 | ||
941 | 46 | 46 | ||
942 | 47 | class ApplicationFormTestCase(TestCaseWithFactory): | 47 | class ApplicationFormTestCase(TestCaseWithFactory): |
943 | 48 | 48 | ||
944 | 49 | def get_desktop_data(self, overrides): | 49 | def get_desktop_data(self, overrides): |
945 | 50 | data = { | 50 | data = { |
948 | 51 | 'Name': self.factory.get_unique_string( | 51 | 'Name': self.factory.get_unique_string(prefix='App Name'), |
947 | 52 | prefix='App Name'), | ||
949 | 53 | 'X-AppInstall-Package': self.factory.get_unique_string( | 52 | 'X-AppInstall-Package': self.factory.get_unique_string( |
950 | 54 | prefix='pkg_name'), | 53 | prefix='pkg_name'), |
951 | 55 | 'X-AppInstall-Popcon': self.factory.get_unique_integer(), | 54 | 'X-AppInstall-Popcon': self.factory.get_unique_integer(), |
952 | @@ -57,7 +56,7 @@ | |||
953 | 57 | prefix='section'), | 56 | prefix='section'), |
954 | 58 | 'Type': 'Application', | 57 | 'Type': 'Application', |
955 | 59 | 'Categories': 'cat1;cat2', | 58 | 'Categories': 'cat1;cat2', |
957 | 60 | } | 59 | } |
958 | 61 | data.update(overrides) | 60 | data.update(overrides) |
959 | 62 | return data | 61 | return data |
960 | 63 | 62 | ||
961 | @@ -85,11 +84,11 @@ | |||
962 | 85 | data = { | 84 | data = { |
963 | 86 | 'Name': 'My Package', | 85 | 'Name': 'My Package', |
964 | 87 | 'X-AppInstall-Package': 'mypkg', | 86 | 'X-AppInstall-Package': 'mypkg', |
966 | 88 | } | 87 | } |
967 | 89 | desktop_entry = self.get_desktop_entry(self.get_desktop_data(data)) | 88 | desktop_entry = self.get_desktop_entry(self.get_desktop_data(data)) |
968 | 90 | 89 | ||
971 | 91 | form = ApplicationForm.get_form_from_desktop_data(desktop_entry, | 90 | form = ApplicationForm.get_form_from_desktop_data( |
972 | 92 | distroseries=self.factory.make_distroseries()) | 91 | desktop_entry, distroseries=self.factory.make_distroseries()) |
973 | 93 | 92 | ||
974 | 94 | self.assertTrue(form.is_valid()) | 93 | self.assertTrue(form.is_valid()) |
975 | 95 | self.assertEqual('My Package', form.cleaned_data['name']) | 94 | self.assertEqual('My Package', form.cleaned_data['name']) |
976 | @@ -99,15 +98,15 @@ | |||
977 | 99 | # If the desktop data contains some blanks, then the initial | 98 | # If the desktop data contains some blanks, then the initial |
978 | 100 | # data from any existing instance should be used instead. | 99 | # data from any existing instance should be used instead. |
979 | 101 | app = self.factory.make_application(package_name='mypkg', | 100 | app = self.factory.make_application(package_name='mypkg', |
981 | 102 | description='MyPkg description') | 101 | description='MyPkg description') |
982 | 103 | data = { | 102 | data = { |
983 | 104 | 'Name': 'My Package', | 103 | 'Name': 'My Package', |
984 | 105 | 'X-AppInstall-Package': 'mypkg', | 104 | 'X-AppInstall-Package': 'mypkg', |
986 | 106 | } | 105 | } |
987 | 107 | desktop_entry = self.get_desktop_entry(self.get_desktop_data(data)) | 106 | desktop_entry = self.get_desktop_entry(self.get_desktop_data(data)) |
988 | 108 | 107 | ||
991 | 109 | form = ApplicationForm.get_form_from_desktop_data(desktop_entry, | 108 | form = ApplicationForm.get_form_from_desktop_data( |
992 | 110 | distroseries=app.distroseries) | 109 | desktop_entry, distroseries=app.distroseries) |
993 | 111 | 110 | ||
994 | 112 | self.assertTrue(form.is_valid()) | 111 | self.assertTrue(form.is_valid()) |
995 | 113 | self.assertEqual('MyPkg description', form.cleaned_data['description']) | 112 | self.assertEqual('MyPkg description', form.cleaned_data['description']) |
996 | @@ -126,12 +125,12 @@ | |||
997 | 126 | 'X-AppInstall-Keywords': 'jazz,rock,country', | 125 | 'X-AppInstall-Keywords': 'jazz,rock,country', |
998 | 127 | 'Categories': 'Graphics;Jazz;Publishing', | 126 | 'Categories': 'Graphics;Jazz;Publishing', |
999 | 128 | 'MimeType': 'application/vnd.scribus;text/javascript;' | 127 | 'MimeType': 'application/vnd.scribus;text/javascript;' |
1003 | 129 | } | 128 | } |
1004 | 130 | desktop_entry = self.get_desktop_entry(self.get_desktop_data( | 129 | info = self.get_desktop_data(extra_desktop_info) |
1005 | 131 | extra_desktop_info)) | 130 | desktop_entry = self.get_desktop_entry(info) |
1006 | 132 | 131 | ||
1009 | 133 | form = ApplicationForm.get_form_from_desktop_data(desktop_entry, | 132 | form = ApplicationForm.get_form_from_desktop_data( |
1010 | 134 | distroseries=self.factory.make_distroseries()) | 133 | desktop_entry, distroseries=self.factory.make_distroseries()) |
1011 | 135 | 134 | ||
1012 | 136 | self.assertTrue(form.is_valid()) | 135 | self.assertTrue(form.is_valid()) |
1013 | 137 | for key, value in extra_desktop_info.items(): | 136 | for key, value in extra_desktop_info.items(): |
1014 | @@ -144,12 +143,12 @@ | |||
1015 | 144 | extra_desktop_info = { | 143 | extra_desktop_info = { |
1016 | 145 | 'X-AppInstall-Screenshot-Url': 'http://example.com/screenshot', | 144 | 'X-AppInstall-Screenshot-Url': 'http://example.com/screenshot', |
1017 | 146 | 'X-AppInstall-Package': app.package_name, | 145 | 'X-AppInstall-Package': app.package_name, |
1021 | 147 | } | 146 | } |
1022 | 148 | desktop_entry = self.get_desktop_entry(self.get_desktop_data( | 147 | info = self.get_desktop_data(extra_desktop_info) |
1023 | 149 | extra_desktop_info)) | 148 | desktop_entry = self.get_desktop_entry(info) |
1024 | 150 | 149 | ||
1027 | 151 | form = ApplicationForm.get_form_from_desktop_data(desktop_entry, | 150 | form = ApplicationForm.get_form_from_desktop_data( |
1028 | 152 | distroseries=app.distroseries) | 151 | desktop_entry, distroseries=app.distroseries) |
1029 | 153 | form.save() | 152 | form.save() |
1030 | 154 | 153 | ||
1031 | 155 | app = Application.objects.get(pk=app.pk) | 154 | app = Application.objects.get(pk=app.pk) |
1032 | @@ -166,9 +165,10 @@ | |||
1033 | 166 | # - It doesn't provide a real benefit as 99% of the time the field | 165 | # - It doesn't provide a real benefit as 99% of the time the field |
1034 | 167 | # is populated by a script that doesn't have typo issues. | 166 | # is populated by a script that doesn't have typo issues. |
1035 | 168 | distroseries = self.factory.make_distroseries() | 167 | distroseries = self.factory.make_distroseries() |
1039 | 169 | form = ApplicationForm(dict(screenshot_url='http://foo.com:42/broken', | 168 | d = dict(screenshot_url='http://foo.com:42/broken', |
1040 | 170 | section='required', name='required', package_name='required', | 169 | section='required', name='required', package_name='required', |
1041 | 171 | distroseries=distroseries.id)) | 170 | distroseries=distroseries.id) |
1042 | 171 | form = ApplicationForm(d) | ||
1043 | 172 | self.assertTrue(form.is_valid()) | 172 | self.assertTrue(form.is_valid()) |
1044 | 173 | 173 | ||
1045 | 174 | 174 | ||
1046 | @@ -190,29 +190,32 @@ | |||
1047 | 190 | 'screenshot_urls': [ | 190 | 'screenshot_urls': [ |
1048 | 191 | 'http://example.com/screenshot1.png', | 191 | 'http://example.com/screenshot1.png', |
1049 | 192 | 'http://example.com/screenshot2.png', | 192 | 'http://example.com/screenshot2.png', |
1051 | 193 | ], | 193 | ], |
1052 | 194 | 'video_embedded_html_urls': [ | 194 | 'video_embedded_html_urls': [ |
1053 | 195 | 'http://example.com/video1.mp4', | 195 | 'http://example.com/video1.mp4', |
1055 | 196 | ], | 196 | ], |
1056 | 197 | 'archive_id': app.archive_id, | 197 | 'archive_id': app.archive_id, |
1057 | 198 | 'package_name': app.package_name, | 198 | 'package_name': app.package_name, |
1058 | 199 | 'name': app.name, | 199 | 'name': app.name, |
1060 | 200 | } | 200 | } |
1061 | 201 | 201 | ||
1062 | 202 | form = ForPurchaseApplicationForm.from_api_data(data, | 202 | form = ForPurchaseApplicationForm.from_api_data(data, |
1064 | 203 | app.distroseries) | 203 | app.distroseries) |
1065 | 204 | self.assertTrue(form.is_valid()) | 204 | self.assertTrue(form.is_valid()) |
1066 | 205 | form.save_media_urls() | 205 | form.save_media_urls() |
1067 | 206 | 206 | ||
1068 | 207 | self.assertEqual(3, app.applicationmedia_set.count()) | 207 | self.assertEqual(3, app.applicationmedia_set.count()) |
1071 | 208 | actual_urls = [media.url for media in app.applicationmedia_set.all()] | 208 | actual_urls = [media.url for media in |
1072 | 209 | self.assertEqual([ | 209 | app.applicationmedia_set.all().order_by('url')] |
1073 | 210 | expected = [ | ||
1074 | 210 | 'http://example.com/screenshot1.png', | 211 | 'http://example.com/screenshot1.png', |
1075 | 211 | 'http://example.com/screenshot2.png', | 212 | 'http://example.com/screenshot2.png', |
1076 | 212 | 'http://example.com/video1.mp4', | 213 | 'http://example.com/video1.mp4', |
1078 | 213 | ], actual_urls) | 214 | ] |
1079 | 215 | self.assertEqual(expected, actual_urls) | ||
1080 | 214 | 216 | ||
1081 | 215 | def make_valid_data(self, **kwargs): | 217 | def make_valid_data(self, **kwargs): |
1082 | 218 | media_url = u'http://sc.staging.ubuntu.com/site_media/appmedia/' | ||
1083 | 216 | data = { | 219 | data = { |
1084 | 217 | u'status': u'Published', | 220 | u'status': u'Published', |
1085 | 218 | u'signing_key_id': u'', | 221 | u'signing_key_id': u'', |
1086 | @@ -222,34 +225,30 @@ | |||
1087 | 222 | u'series': { | 225 | u'series': { |
1088 | 223 | u'precise': [u'amd64', u'i386'], | 226 | u'precise': [u'amd64', u'i386'], |
1089 | 224 | u'oneiric': [u'i386', u'amd64'] | 227 | u'oneiric': [u'i386', u'amd64'] |
1091 | 225 | }, | 228 | }, |
1092 | 226 | u'price': u'0.00', | 229 | u'price': u'0.00', |
1093 | 227 | u'debtags': '["mouse"]', | 230 | u'debtags': '["mouse"]', |
1094 | 228 | u'date_published': u'2012-04-30 19:34:08.011454', | 231 | u'date_published': u'2012-04-30 19:34:08.011454', |
1095 | 229 | u'video_urls': [], | 232 | u'video_urls': [], |
1099 | 230 | u'screenshot_url': u'http://sc.staging.ubuntu.com/' | 233 | u'screenshot_url': media_url + u'2012/04/IMG_20120401_144332.jpg', |
1097 | 231 | 'site_media/appmedia/2012/04/' | ||
1098 | 232 | 'IMG_20120401_144332.jpg', | ||
1100 | 233 | u'id': 595, | 234 | u'id': 595, |
1101 | 234 | u'categories': u'Utility', | 235 | u'categories': u'Utility', |
1102 | 235 | u'archive_id': self.factory.get_unique_string(prefix='archid/'), | 236 | u'archive_id': self.factory.get_unique_string(prefix='archid/'), |
1103 | 236 | u'name': u'Test App', | 237 | u'name': u'Test App', |
1104 | 237 | u'license': u'GNU GPL v3', | 238 | u'license': u'GNU GPL v3', |
1105 | 238 | u'support_url': u'http://example.com/foo', | 239 | u'support_url': u'http://example.com/foo', |
1108 | 239 | u'icon_url': u'http://sc.staging.ubuntu.com/' | 240 | u'icon_url': media_url + u'2012/04/ktip.png', |
1107 | 240 | 'site_media/appmedia/2012/04/ktip.png', | ||
1109 | 241 | u'comment': u'This is a test app', | 241 | u'comment': u'This is a test app', |
1110 | 242 | u'version': u'1.2', | 242 | u'version': u'1.2', |
1111 | 243 | u'screenshot_urls': [ | 243 | u'screenshot_urls': [ |
1115 | 244 | u'http://sc.staging.ubuntu.com/' | 244 | media_url + u'2012/04/IMG_20120401_144332.jpg', |
1116 | 245 | 'site_media/appmedia/2012/04/IMG_20120401_144332.jpg', | 245 | ], |
1114 | 246 | ], | ||
1117 | 247 | u'demo': None, | 246 | u'demo': None, |
1118 | 248 | u'department': [u'Accessories'], | 247 | u'department': [u'Accessories'], |
1119 | 249 | u'archive_root': u'http://extras.ubuntu.com/', | 248 | u'archive_root': u'http://extras.ubuntu.com/', |
1120 | 250 | u'tos_url': u'', | 249 | u'tos_url': u'', |
1121 | 251 | u'channel': u'Independent', | 250 | u'channel': u'Independent', |
1123 | 252 | } | 251 | } |
1124 | 253 | data.update(**kwargs) | 252 | data.update(**kwargs) |
1125 | 254 | return data | 253 | return data |
1126 | 255 | 254 | ||
1127 | 256 | 255 | ||
1128 | === modified file 'src/webcatalog/tests/test_handlers.py' | |||
1129 | --- src/webcatalog/tests/test_handlers.py 2011-09-12 13:37:24 +0000 | |||
1130 | +++ src/webcatalog/tests/test_handlers.py 2012-06-06 18:03:20 +0000 | |||
1131 | @@ -25,8 +25,7 @@ | |||
1132 | 25 | 'MachineHandlerTestCase', | 25 | 'MachineHandlerTestCase', |
1133 | 26 | 'PackagesHandlerTestCase', | 26 | 'PackagesHandlerTestCase', |
1134 | 27 | 'ServerStatusHandlerTestCase', | 27 | 'ServerStatusHandlerTestCase', |
1137 | 28 | ] | 28 | ] |
1136 | 29 | |||
1138 | 30 | 29 | ||
1139 | 31 | from django.http import HttpRequest | 30 | from django.http import HttpRequest |
1140 | 32 | from django.test import TestCase | 31 | from django.test import TestCase |
1141 | @@ -108,15 +107,15 @@ | |||
1142 | 108 | handler = MachineHandler() | 107 | handler = MachineHandler() |
1143 | 109 | response = handler.create(request, uuid='foo') | 108 | response = handler.create(request, uuid='foo') |
1144 | 110 | self.assertContains(response, "Unable to deserialize request", | 109 | self.assertContains(response, "Unable to deserialize request", |
1146 | 111 | status_code=400) | 110 | status_code=400) |
1147 | 112 | 111 | ||
1148 | 113 | def test_create_missing_hostname(self): | 112 | def test_create_missing_hostname(self): |
1149 | 114 | request = HttpRequest() | 113 | request = HttpRequest() |
1150 | 115 | request.data = {'logo_checksum': 'bar'} | 114 | request.data = {'logo_checksum': 'bar'} |
1151 | 116 | handler = MachineHandler() | 115 | handler = MachineHandler() |
1152 | 117 | response = handler.create(request, 'uuid') | 116 | response = handler.create(request, 'uuid') |
1155 | 118 | expected = {'status': 'error', 'errors': | 117 | expected = {'status': 'error', |
1156 | 119 | {'hostname': [u'This field is required.']}} | 118 | 'errors': {'hostname': [u'This field is required.']}} |
1157 | 120 | self.assertEqual(expected, response) | 119 | self.assertEqual(expected, response) |
1158 | 121 | 120 | ||
1159 | 122 | def test_create_blank_logo_checksum(self): | 121 | def test_create_blank_logo_checksum(self): |
1160 | @@ -149,7 +148,7 @@ | |||
1161 | 149 | def test_delete_invalid_uuid_returns_404(self): | 148 | def test_delete_invalid_uuid_returns_404(self): |
1162 | 150 | handler = MachineHandler() | 149 | handler = MachineHandler() |
1163 | 151 | response = handler.delete(self.request, | 150 | response = handler.delete(self.request, |
1165 | 152 | self.factory.get_unique_string()) | 151 | self.factory.get_unique_string()) |
1166 | 153 | self.assertEqual(404, response.status_code) | 152 | self.assertEqual(404, response.status_code) |
1167 | 154 | 153 | ||
1168 | 155 | def test_delete(self): | 154 | def test_delete(self): |
1169 | @@ -161,7 +160,7 @@ | |||
1170 | 161 | self.assertEqual(204, response.status_code) | 160 | self.assertEqual(204, response.status_code) |
1171 | 162 | self.assertEqual('', response.content) | 161 | self.assertEqual('', response.content) |
1172 | 163 | self.assertRaises(Machine.DoesNotExist, Machine.objects.get, | 162 | self.assertRaises(Machine.DoesNotExist, Machine.objects.get, |
1174 | 164 | uuid=machine.uuid) | 163 | uuid=machine.uuid) |
1175 | 165 | 164 | ||
1176 | 166 | 165 | ||
1177 | 167 | class PackagesHandlerTestCase(HandlerTestCase): | 166 | class PackagesHandlerTestCase(HandlerTestCase): |
1178 | @@ -173,7 +172,7 @@ | |||
1179 | 173 | def test_read(self): | 172 | def test_read(self): |
1180 | 174 | expected = 'some-package-list' | 173 | expected = 'some-package-list' |
1181 | 175 | machine = self.factory.make_machine(owner=self.user, | 174 | machine = self.factory.make_machine(owner=self.user, |
1183 | 176 | package_list=expected) | 175 | package_list=expected) |
1184 | 177 | handler = PackagesHandler() | 176 | handler = PackagesHandler() |
1185 | 178 | 177 | ||
1186 | 179 | response = handler.read(self.request, machine.uuid) | 178 | response = handler.read(self.request, machine.uuid) |
1187 | @@ -182,7 +181,7 @@ | |||
1188 | 182 | def test_create_invalid_uuid_returns_404(self): | 181 | def test_create_invalid_uuid_returns_404(self): |
1189 | 183 | handler = PackagesHandler() | 182 | handler = PackagesHandler() |
1190 | 184 | response = handler.create(self.request, | 183 | response = handler.create(self.request, |
1192 | 185 | self.factory.get_unique_string()) | 184 | self.factory.get_unique_string()) |
1193 | 186 | self.assertEqual(404, response.status_code) | 185 | self.assertEqual(404, response.status_code) |
1194 | 187 | 186 | ||
1195 | 188 | def test_create_missing_data(self): | 187 | def test_create_missing_data(self): |
1196 | @@ -221,4 +220,4 @@ | |||
1197 | 221 | handler = PackagesHandler() | 220 | handler = PackagesHandler() |
1198 | 222 | response = handler.create(request, uuid=machine.uuid) | 221 | response = handler.create(request, uuid=machine.uuid) |
1199 | 223 | self.assertContains(response, "Unable to deserialize request", | 222 | self.assertContains(response, "Unable to deserialize request", |
1201 | 224 | status_code=400) | 223 | status_code=400) |
1202 | 225 | 224 | ||
1203 | === modified file 'src/webcatalog/tests/test_managers.py' | |||
1204 | --- src/webcatalog/tests/test_managers.py 2012-03-16 01:42:36 +0000 | |||
1205 | +++ src/webcatalog/tests/test_managers.py 2012-06-06 18:03:20 +0000 | |||
1206 | @@ -20,8 +20,7 @@ | |||
1207 | 20 | from __future__ import ( | 20 | from __future__ import ( |
1208 | 21 | absolute_import, | 21 | absolute_import, |
1209 | 22 | with_statement, | 22 | with_statement, |
1212 | 23 | ) | 23 | ) |
1211 | 24 | |||
1213 | 25 | 24 | ||
1214 | 26 | from webcatalog.tests.factory import TestCaseWithFactory | 25 | from webcatalog.tests.factory import TestCaseWithFactory |
1215 | 27 | from webcatalog.models import Application | 26 | from webcatalog.models import Application |
1216 | @@ -29,10 +28,11 @@ | |||
1217 | 29 | __metaclass__ = type | 28 | __metaclass__ = type |
1218 | 30 | __all__ = [ | 29 | __all__ = [ |
1219 | 31 | 'ApplicationManagerTestCase', | 30 | 'ApplicationManagerTestCase', |
1221 | 32 | ] | 31 | ] |
1222 | 33 | 32 | ||
1223 | 34 | 33 | ||
1224 | 35 | class ApplicationManagerTestCase(TestCaseWithFactory): | 34 | class ApplicationManagerTestCase(TestCaseWithFactory): |
1225 | 35 | |||
1226 | 36 | def test_find_best_returns_none(self): | 36 | def test_find_best_returns_none(self): |
1227 | 37 | self.assertIsNone(Application.objects.find_best(package_name='foo')) | 37 | self.assertIsNone(Application.objects.find_best(package_name='foo')) |
1228 | 38 | 38 | ||
1229 | @@ -41,8 +41,8 @@ | |||
1230 | 41 | older = self.factory.make_distroseries(version='14.04') | 41 | older = self.factory.make_distroseries(version='14.04') |
1231 | 42 | 42 | ||
1232 | 43 | expected = self.factory.make_application(distroseries=latest) | 43 | expected = self.factory.make_application(distroseries=latest) |
1235 | 44 | self.factory.make_application(package_name=expected.package_name, | 44 | self.factory.make_application( |
1236 | 45 | distroseries=older) | 45 | package_name=expected.package_name, distroseries=older) |
1237 | 46 | 46 | ||
1238 | 47 | retrieved = Application.objects.find_best( | 47 | retrieved = Application.objects.find_best( |
1239 | 48 | package_name=expected.package_name) | 48 | package_name=expected.package_name) |
1240 | @@ -52,12 +52,12 @@ | |||
1241 | 52 | def test_check_latest(self): | 52 | def test_check_latest(self): |
1242 | 53 | for code_name in ['lucid', 'maverick', 'natty', 'oneiric']: | 53 | for code_name in ['lucid', 'maverick', 'natty', 'oneiric']: |
1243 | 54 | dseries = self.factory.make_distroseries(code_name=code_name) | 54 | dseries = self.factory.make_distroseries(code_name=code_name) |
1246 | 55 | self.factory.make_application(package_name='foobar', | 55 | self.factory.make_application( |
1247 | 56 | distroseries=dseries) | 56 | package_name='foobar', distroseries=dseries) |
1248 | 57 | 57 | ||
1249 | 58 | Application.objects.check_latest('foobar') | 58 | Application.objects.check_latest('foobar') |
1250 | 59 | 59 | ||
1251 | 60 | retrieved = Application.objects.filter(package_name='foobar').order_by( | 60 | retrieved = Application.objects.filter(package_name='foobar').order_by( |
1252 | 61 | '-distroseries__code_name') | 61 | '-distroseries__code_name') |
1255 | 62 | self.assertEqual([True, False, False, False], [app.is_latest | 62 | self.assertEqual([True, False, False, False], |
1256 | 63 | for app in retrieved]) | 63 | [app.is_latest for app in retrieved]) |
1257 | 64 | 64 | ||
1258 | === modified file 'src/webcatalog/tests/test_models.py' | |||
1259 | --- src/webcatalog/tests/test_models.py 2012-05-07 15:49:12 +0000 | |||
1260 | +++ src/webcatalog/tests/test_models.py 2012-06-06 18:03:20 +0000 | |||
1261 | @@ -20,7 +20,7 @@ | |||
1262 | 20 | from __future__ import ( | 20 | from __future__ import ( |
1263 | 21 | absolute_import, | 21 | absolute_import, |
1264 | 22 | with_statement, | 22 | with_statement, |
1266 | 23 | ) | 23 | ) |
1267 | 24 | 24 | ||
1268 | 25 | from django.core.urlresolvers import reverse | 25 | from django.core.urlresolvers import reverse |
1269 | 26 | from django.core.files.images import ImageFile | 26 | from django.core.files.images import ImageFile |
1270 | @@ -33,7 +33,7 @@ | |||
1271 | 33 | 'ApplicationTestCase', | 33 | 'ApplicationTestCase', |
1272 | 34 | 'DepartmentTestCase', | 34 | 'DepartmentTestCase', |
1273 | 35 | 'ExhibitTestCase', | 35 | 'ExhibitTestCase', |
1275 | 36 | ] | 36 | ] |
1276 | 37 | 37 | ||
1277 | 38 | 38 | ||
1278 | 39 | class ApplicationTestCase(TestCaseWithFactory): | 39 | class ApplicationTestCase(TestCaseWithFactory): |
1279 | @@ -65,43 +65,52 @@ | |||
1280 | 65 | 65 | ||
1281 | 66 | def test_crumbs_no_department(self): | 66 | def test_crumbs_no_department(self): |
1282 | 67 | app = self.factory.make_application() | 67 | app = self.factory.make_application() |
1289 | 68 | self.assertEquals([], list(app.departments.all())) | 68 | app_url = reverse('wc-package-detail', |
1290 | 69 | expected = [{'name': 'All Apps', 'url': reverse('wc-index')}, | 69 | args=[app.distroseries.code_name, app.package_name]) |
1291 | 70 | {'name': app.name, 'url': reverse('wc-package-detail', | 70 | self.assertEqual([], list(app.departments.all())) |
1292 | 71 | args=[app.distroseries.code_name, app.package_name])}] | 71 | expected = [ |
1293 | 72 | 72 | {'name': 'All Apps', 'url': reverse('wc-index')}, | |
1294 | 73 | self.assertEquals(expected, app.crumbs()) | 73 | {'name': app.name, 'url': app_url}, |
1295 | 74 | ] | ||
1296 | 75 | self.assertEqual(expected, app.crumbs()) | ||
1297 | 74 | 76 | ||
1298 | 75 | def test_crumbs_department_without_parent(self): | 77 | def test_crumbs_department_without_parent(self): |
1299 | 76 | app = self.factory.make_application() | 78 | app = self.factory.make_application() |
1300 | 77 | app.categories = 'Game;' | 79 | app.categories = 'Game;' |
1301 | 78 | app.update_departments() | 80 | app.update_departments() |
1302 | 79 | dept = app.departments.get() | 81 | dept = app.departments.get() |
1311 | 80 | expected = [{'name': 'All Apps', 'url': reverse('wc-index')}, | 82 | app_url = reverse('wc-package-detail', |
1312 | 81 | {'name': dept.name, 'url': reverse('wc-department', | 83 | args=[app.distroseries.code_name, app.package_name]) |
1313 | 82 | kwargs={'distro': app.distroseries.code_name, | 84 | dept_url = reverse('wc-department', |
1314 | 83 | 'dept_slug_or_id': dept.slug})}, | 85 | kwargs={'distro': app.distroseries.code_name, |
1315 | 84 | {'name': app.name, 'url': reverse('wc-package-detail', | 86 | 'dept_slug_or_id': dept.slug}) |
1316 | 85 | args=[app.distroseries.code_name, app.package_name])}] | 87 | expected = [ |
1317 | 86 | 88 | {'name': 'All Apps', 'url': reverse('wc-index')}, | |
1318 | 87 | self.assertEquals(expected, app.crumbs()) | 89 | {'name': dept.name, 'url': dept_url}, |
1319 | 90 | {'name': app.name, 'url': app_url}, | ||
1320 | 91 | ] | ||
1321 | 92 | self.assertEqual(expected, app.crumbs()) | ||
1322 | 88 | 93 | ||
1323 | 89 | def test_crumbs_department_with_parent(self): | 94 | def test_crumbs_department_with_parent(self): |
1324 | 90 | app = self.factory.make_application() | 95 | app = self.factory.make_application() |
1325 | 91 | app.categories = 'RolePlaying;' | 96 | app.categories = 'RolePlaying;' |
1326 | 92 | app.update_departments() | 97 | app.update_departments() |
1327 | 93 | dept = app.departments.get() | 98 | dept = app.departments.get() |
1339 | 94 | expected = [{'name': 'All Apps', 'url': reverse('wc-index')}, | 99 | app_url = reverse('wc-package-detail', |
1340 | 95 | {'name': dept.parent.name, 'url': reverse('wc-department', | 100 | args=[app.distroseries.code_name, app.package_name]) |
1341 | 96 | kwargs={'distro': app.distroseries.code_name, | 101 | dept_url = reverse('wc-department', |
1342 | 97 | 'dept_slug_or_id': dept.parent.slug})}, | 102 | kwargs={'distro': app.distroseries.code_name, |
1343 | 98 | {'name': dept.name, 'url': reverse('wc-department', | 103 | 'dept_slug_or_id': dept.slug}) |
1344 | 99 | kwargs={'distro': app.distroseries.code_name, | 104 | parent_url = reverse('wc-department', |
1345 | 100 | 'dept_slug_or_id': dept.slug})}, | 105 | kwargs={'distro': app.distroseries.code_name, |
1346 | 101 | {'name': app.name, 'url': reverse('wc-package-detail', | 106 | 'dept_slug_or_id': dept.parent.slug}) |
1347 | 102 | args=[app.distroseries.code_name, app.package_name])}] | 107 | expected = [ |
1348 | 103 | 108 | {'name': 'All Apps', 'url': reverse('wc-index')}, | |
1349 | 104 | self.assertEquals(expected, app.crumbs()) | 109 | {'name': dept.parent.name, 'url': parent_url}, |
1350 | 110 | {'name': dept.name, 'url': dept_url}, | ||
1351 | 111 | {'name': app.name, 'url': app_url}, | ||
1352 | 112 | ] | ||
1353 | 113 | self.assertEqual(expected, app.crumbs()) | ||
1354 | 105 | 114 | ||
1355 | 106 | def test_icon_url_or_default_no_icon(self): | 115 | def test_icon_url_or_default_no_icon(self): |
1356 | 107 | app = self.factory.make_application() | 116 | app = self.factory.make_application() |
1357 | @@ -134,12 +143,11 @@ | |||
1358 | 134 | url='http://example.com/video.m4v') | 143 | url='http://example.com/video.m4v') |
1359 | 135 | 144 | ||
1360 | 136 | urls = app.screenshots | 145 | urls = app.screenshots |
1363 | 137 | 146 | expected = [ | |
1362 | 138 | self.assertEqual([ | ||
1364 | 139 | 'http://example.com/screenshot1.png', | 147 | 'http://example.com/screenshot1.png', |
1365 | 140 | 'http://example.com/screenshot2.png', | 148 | 'http://example.com/screenshot2.png', |
1368 | 141 | ], | 149 | ] |
1369 | 142 | urls) | 150 | self.assertEqual(expected, urls) |
1370 | 143 | 151 | ||
1371 | 144 | def test_screenshots_cached(self): | 152 | def test_screenshots_cached(self): |
1372 | 145 | # The db isn't hit if _screenshots is already | 153 | # The db isn't hit if _screenshots is already |
1373 | @@ -153,9 +161,8 @@ | |||
1374 | 153 | media_type='screenshot', | 161 | media_type='screenshot', |
1375 | 154 | url='http://example.com/screenshot2.png') | 162 | url='http://example.com/screenshot2.png') |
1376 | 155 | 163 | ||
1380 | 156 | self.assertEqual([ | 164 | self.assertEqual(['http://example.com/screenshot1.png'], |
1381 | 157 | 'http://example.com/screenshot1.png', | 165 | app.screenshots) |
1379 | 158 | ], app.screenshots) | ||
1382 | 159 | 166 | ||
1383 | 160 | def test_video_iframes_urls(self): | 167 | def test_video_iframes_urls(self): |
1384 | 161 | app = self.factory.make_application() | 168 | app = self.factory.make_application() |
1385 | @@ -170,12 +177,11 @@ | |||
1386 | 170 | url='http://example.com/screenshot.png') | 177 | url='http://example.com/screenshot.png') |
1387 | 171 | 178 | ||
1388 | 172 | urls = app.video_iframe_urls | 179 | urls = app.video_iframe_urls |
1391 | 173 | 180 | expected = [ | |
1390 | 174 | self.assertEqual([ | ||
1392 | 175 | 'http://example.com/video1.m4v', | 181 | 'http://example.com/video1.m4v', |
1393 | 176 | 'http://example.com/video2.m4v', | 182 | 'http://example.com/video2.m4v', |
1396 | 177 | ], | 183 | ] |
1397 | 178 | urls) | 184 | self.assertEqual(expected, urls) |
1398 | 179 | 185 | ||
1399 | 180 | def test_video_iframes_urls_cached(self): | 186 | def test_video_iframes_urls_cached(self): |
1400 | 181 | app = self.factory.make_application() | 187 | app = self.factory.make_application() |
1401 | @@ -189,44 +195,49 @@ | |||
1402 | 189 | 195 | ||
1403 | 190 | urls = app.video_iframe_urls | 196 | urls = app.video_iframe_urls |
1404 | 191 | 197 | ||
1409 | 192 | self.assertEqual([ | 198 | self.assertEqual(['http://example.com/video1.m4v'], urls) |
1406 | 193 | 'http://example.com/video1.m4v', | ||
1407 | 194 | ], | ||
1408 | 195 | urls) | ||
1410 | 196 | 199 | ||
1411 | 197 | 200 | ||
1412 | 198 | class DepartmentTestCase(TestCaseWithFactory): | 201 | class DepartmentTestCase(TestCaseWithFactory): |
1413 | 199 | def test_crumbs_no_parent(self): | 202 | def test_crumbs_no_parent(self): |
1414 | 200 | dept = self.factory.make_department('Foo') | 203 | dept = self.factory.make_department('Foo') |
1420 | 201 | expected = [{'name': 'All Apps', 'url': reverse('wc-index')}, | 204 | expected = [ |
1421 | 202 | {'name': dept.name, 'url': reverse('wc-department', | 205 | {'name': 'All Apps', 'url': reverse('wc-index')}, |
1422 | 203 | kwargs={'dept_slug_or_id': dept.slug})}] | 206 | {'name': dept.name, |
1423 | 204 | 207 | 'url': reverse('wc-department', | |
1424 | 205 | self.assertEquals(expected, dept.crumbs()) | 208 | kwargs={'dept_slug_or_id': dept.slug})} |
1425 | 209 | ] | ||
1426 | 210 | self.assertEqual(expected, dept.crumbs()) | ||
1427 | 206 | 211 | ||
1428 | 207 | def test_crumbs_with_parent(self): | 212 | def test_crumbs_with_parent(self): |
1429 | 208 | parent = self.factory.make_department('Foo') | 213 | parent = self.factory.make_department('Foo') |
1430 | 209 | dept = self.factory.make_department('Bar', parent=parent) | 214 | dept = self.factory.make_department('Bar', parent=parent) |
1438 | 210 | expected = [{'name': 'All Apps', 'url': reverse('wc-index')}, | 215 | expected = [ |
1439 | 211 | {'name': dept.parent.name, 'url': reverse('wc-department', | 216 | {'name': 'All Apps', 'url': reverse('wc-index')}, |
1440 | 212 | kwargs={'dept_slug_or_id': dept.parent.slug})}, | 217 | {'name': dept.parent.name, |
1441 | 213 | {'name': dept.name, 'url': reverse('wc-department', | 218 | 'url': reverse('wc-department', |
1442 | 214 | kwargs={'dept_slug_or_id': dept.slug})}] | 219 | kwargs={'dept_slug_or_id': dept.parent.slug})}, |
1443 | 215 | 220 | {'name': dept.name, | |
1444 | 216 | self.assertEquals(expected, dept.crumbs()) | 221 | 'url': reverse('wc-department', |
1445 | 222 | kwargs={'dept_slug_or_id': dept.slug})} | ||
1446 | 223 | ] | ||
1447 | 224 | self.assertEqual(expected, dept.crumbs()) | ||
1448 | 217 | 225 | ||
1449 | 218 | def test_crumbs_with_distroseries(self): | 226 | def test_crumbs_with_distroseries(self): |
1450 | 219 | parent = self.factory.make_department('Foo') | 227 | parent = self.factory.make_department('Foo') |
1451 | 220 | dept = self.factory.make_department('Bar', parent=parent) | 228 | dept = self.factory.make_department('Bar', parent=parent) |
1461 | 221 | expected = [{'name': 'All Apps', 'url': reverse('wc-index')}, | 229 | parent_url = reverse('wc-department', |
1462 | 222 | {'name': dept.parent.name, 'url': reverse('wc-department', | 230 | kwargs={'distro': 'frobbly', |
1463 | 223 | kwargs={'distro': 'frobbly', | 231 | 'dept_slug_or_id': parent.slug}) |
1464 | 224 | 'dept_slug_or_id': dept.parent.slug})}, | 232 | dept_url = reverse('wc-department', |
1465 | 225 | {'name': dept.name, 'url': reverse('wc-department', | 233 | kwargs={'distro': 'frobbly', |
1466 | 226 | kwargs={'distro': 'frobbly', | 234 | 'dept_slug_or_id': dept.slug}) |
1467 | 227 | 'dept_slug_or_id': dept.slug})}] | 235 | expected = [ |
1468 | 228 | 236 | {'name': 'All Apps', 'url': reverse('wc-index')}, | |
1469 | 229 | self.assertEquals(expected, dept.crumbs(distro='frobbly')) | 237 | {'name': dept.parent.name, 'url': parent_url}, |
1470 | 238 | {'name': dept.name, 'url': dept_url} | ||
1471 | 239 | ] | ||
1472 | 240 | self.assertEqual(expected, dept.crumbs(distro='frobbly')) | ||
1473 | 230 | 241 | ||
1474 | 231 | 242 | ||
1475 | 232 | class ExhibitTestCase(TestCaseWithFactory): | 243 | class ExhibitTestCase(TestCaseWithFactory): |
1476 | @@ -237,8 +248,7 @@ | |||
1477 | 237 | 248 | ||
1478 | 238 | def test_destination_url_multiple_packages(self): | 249 | def test_destination_url_multiple_packages(self): |
1479 | 239 | exhibit = self.factory.make_exhibit(package_names='foobar,baz') | 250 | exhibit = self.factory.make_exhibit(package_names='foobar,baz') |
1482 | 240 | expected = reverse('wc-package-list') + ( | 251 | expected = reverse('wc-package-list') + '?pkg_name=foobar&pkg_name=baz' |
1481 | 241 | '?pkg_name=foobar&pkg_name=baz') | ||
1483 | 242 | self.assertEqual(expected, exhibit.destination_url()) | 252 | self.assertEqual(expected, exhibit.destination_url()) |
1484 | 243 | 253 | ||
1485 | 244 | def test_destination_url_blank_packages(self): | 254 | def test_destination_url_blank_packages(self): |
1486 | 245 | 255 | ||
1487 | === modified file 'src/webcatalog/tests/test_pep8.py' | |||
1488 | --- src/webcatalog/tests/test_pep8.py 2012-03-27 15:46:44 +0000 | |||
1489 | +++ src/webcatalog/tests/test_pep8.py 2012-06-06 18:03:20 +0000 | |||
1490 | @@ -22,7 +22,7 @@ | |||
1491 | 22 | __metaclass__ = type | 22 | __metaclass__ = type |
1492 | 23 | __all__ = [ | 23 | __all__ = [ |
1493 | 24 | 'WebCatalogPep8TestCase', | 24 | 'WebCatalogPep8TestCase', |
1495 | 25 | ] | 25 | ] |
1496 | 26 | 26 | ||
1497 | 27 | import os | 27 | import os |
1498 | 28 | import pep8 | 28 | import pep8 |
1499 | @@ -37,36 +37,34 @@ | |||
1500 | 37 | packages = [] | 37 | packages = [] |
1501 | 38 | exclude = ['migrations'] | 38 | exclude = ['migrations'] |
1502 | 39 | 39 | ||
1503 | 40 | def message(self, text): | ||
1504 | 41 | self.errors.append(text) | ||
1505 | 42 | |||
1506 | 43 | def setUp(self): | 40 | def setUp(self): |
1508 | 44 | self.errors = [] | 41 | self.errors = {} |
1509 | 45 | 42 | ||
1510 | 46 | class Options(object): | 43 | class Options(object): |
1511 | 44 | counters = defaultdict(int) | ||
1512 | 45 | doctest = '' | ||
1513 | 47 | exclude = self.exclude | 46 | exclude = self.exclude |
1514 | 48 | filename = ['*.py'] | 47 | filename = ['*.py'] |
1521 | 49 | testsuite = '' | 48 | ignore = [] |
1522 | 50 | doctest = '' | 49 | messages = self.errors |
1517 | 51 | counters = defaultdict(int) | ||
1518 | 52 | messages = {} | ||
1519 | 53 | verbose = 0 | ||
1520 | 54 | quiet = 0 | ||
1523 | 55 | repeat = True | 50 | repeat = True |
1524 | 51 | select = [] | ||
1525 | 52 | show_pep8 = False | ||
1526 | 56 | show_source = False | 53 | show_source = False |
1527 | 57 | show_pep8 = False | ||
1528 | 58 | select = [] | ||
1529 | 59 | ignore = [] | ||
1530 | 60 | max_line_length = 79 | 54 | max_line_length = 79 |
1531 | 55 | quiet = 0 | ||
1532 | 56 | statistics = False | ||
1533 | 57 | testsuite = '' | ||
1534 | 58 | verbose = 0 | ||
1535 | 59 | |||
1536 | 61 | pep8.options = Options() | 60 | pep8.options = Options() |
1537 | 62 | pep8.message = self.message | ||
1538 | 63 | Options.physical_checks = pep8.find_checks('physical_line') | 61 | Options.physical_checks = pep8.find_checks('physical_line') |
1539 | 64 | Options.logical_checks = pep8.find_checks('logical_line') | 62 | Options.logical_checks = pep8.find_checks('logical_line') |
1540 | 65 | 63 | ||
1541 | 66 | def test_all_code(self): | 64 | def test_all_code(self): |
1542 | 67 | for package in self.packages: | 65 | for package in self.packages: |
1543 | 68 | pep8.input_dir(os.path.dirname(package.__file__)) | 66 | pep8.input_dir(os.path.dirname(package.__file__)) |
1545 | 69 | self.assertEqual([], self.errors) | 67 | self.assertEqual(self.errors, {}) |
1546 | 70 | 68 | ||
1547 | 71 | 69 | ||
1548 | 72 | class WebCatalogPep8TestCase(PackagePep8TestCase): | 70 | class WebCatalogPep8TestCase(PackagePep8TestCase): |
1549 | 73 | 71 | ||
1550 | === modified file 'src/webcatalog/tests/test_preflight.py' | |||
1551 | --- src/webcatalog/tests/test_preflight.py 2012-05-30 22:39:39 +0000 | |||
1552 | +++ src/webcatalog/tests/test_preflight.py 2012-06-06 18:03:20 +0000 | |||
1553 | @@ -18,7 +18,7 @@ | |||
1554 | 18 | from django.contrib.auth.models import ( | 18 | from django.contrib.auth.models import ( |
1555 | 19 | Group, | 19 | Group, |
1556 | 20 | User, | 20 | User, |
1558 | 21 | ) | 21 | ) |
1559 | 22 | from mock import patch | 22 | from mock import patch |
1560 | 23 | 23 | ||
1561 | 24 | from webcatalog.tests.factory import TestCaseWithFactory | 24 | from webcatalog.tests.factory import TestCaseWithFactory |
1562 | @@ -93,7 +93,7 @@ | |||
1563 | 93 | 'piston', | 93 | 'piston', |
1564 | 94 | 'Django', | 94 | 'Django', |
1565 | 95 | 'preflight', | 95 | 'preflight', |
1567 | 96 | ]) | 96 | ]) |
1568 | 97 | expected_checks = set([ | 97 | expected_checks = set([ |
1569 | 98 | ('validate_config', True), | 98 | ('validate_config', True), |
1570 | 99 | ('database', True), | 99 | ('database', True), |
1571 | @@ -102,6 +102,6 @@ | |||
1572 | 102 | ('recommender_available', True), | 102 | ('recommender_available', True), |
1573 | 103 | ('rnr_available', True), | 103 | ('rnr_available', True), |
1574 | 104 | ('screenshots_available', True), | 104 | ('screenshots_available', True), |
1576 | 105 | ]) | 105 | ]) |
1577 | 106 | self.assertEqual(expected_libs, libs) | 106 | self.assertEqual(expected_libs, libs) |
1578 | 107 | self.assertEqual(expected_checks, checks) | 107 | self.assertEqual(expected_checks, checks) |
1579 | 108 | 108 | ||
1580 | === modified file 'src/webcatalog/tests/test_templatetags.py' | |||
1581 | --- src/webcatalog/tests/test_templatetags.py 2012-06-04 10:54:02 +0000 | |||
1582 | +++ src/webcatalog/tests/test_templatetags.py 2012-06-06 18:03:20 +0000 | |||
1583 | @@ -20,7 +20,7 @@ | |||
1584 | 20 | from __future__ import ( | 20 | from __future__ import ( |
1585 | 21 | absolute_import, | 21 | absolute_import, |
1586 | 22 | with_statement, | 22 | with_statement, |
1588 | 23 | ) | 23 | ) |
1589 | 24 | 24 | ||
1590 | 25 | import unittest | 25 | import unittest |
1591 | 26 | from decimal import Decimal | 26 | from decimal import Decimal |
1592 | @@ -34,7 +34,7 @@ | |||
1593 | 34 | install_options, | 34 | install_options, |
1594 | 35 | rating_summary, | 35 | rating_summary, |
1595 | 36 | visible_page_range, | 36 | visible_page_range, |
1597 | 37 | ) | 37 | ) |
1598 | 38 | from webcatalog.tests.factory import TestCaseWithFactory | 38 | from webcatalog.tests.factory import TestCaseWithFactory |
1599 | 39 | from webcatalog.tests.helpers import patch_settings | 39 | from webcatalog.tests.helpers import patch_settings |
1600 | 40 | 40 | ||
1601 | @@ -44,7 +44,7 @@ | |||
1602 | 44 | 'HtmlizePackageDescriptionTestCase', | 44 | 'HtmlizePackageDescriptionTestCase', |
1603 | 45 | 'RatingSummaryTestCase', | 45 | 'RatingSummaryTestCase', |
1604 | 46 | 'VisiblePageRangeTestCase', | 46 | 'VisiblePageRangeTestCase', |
1606 | 47 | ] | 47 | ] |
1607 | 48 | 48 | ||
1608 | 49 | 49 | ||
1609 | 50 | class InstallOptionsTestCase(TestCaseWithFactory): | 50 | class InstallOptionsTestCase(TestCaseWithFactory): |
1610 | @@ -52,9 +52,9 @@ | |||
1611 | 52 | def setUp(self): | 52 | def setUp(self): |
1612 | 53 | super(InstallOptionsTestCase, self).setUp() | 53 | super(InstallOptionsTestCase, self).setUp() |
1613 | 54 | self.natty = self.factory.make_distroseries(code_name='natty', | 54 | self.natty = self.factory.make_distroseries(code_name='natty', |
1615 | 55 | version='11.04') | 55 | version='11.04') |
1616 | 56 | self.lucid = self.factory.make_distroseries(code_name='lucid', | 56 | self.lucid = self.factory.make_distroseries(code_name='lucid', |
1618 | 57 | version='10.04') | 57 | version='10.04') |
1619 | 58 | 58 | ||
1620 | 59 | def make_useragent(self, linux=True, arch='x86_64', ubuntu_version=None): | 59 | def make_useragent(self, linux=True, arch='x86_64', ubuntu_version=None): |
1621 | 60 | os = 'X11; Linux' if linux else 'Windows NT 5.1' | 60 | os = 'X11; Linux' if linux else 'Windows NT 5.1' |
1622 | @@ -78,12 +78,11 @@ | |||
1623 | 78 | application = self.factory.make_application( | 78 | application = self.factory.make_application( |
1624 | 79 | package_name='pkgfoo', distroseries=self.natty, | 79 | package_name='pkgfoo', distroseries=self.natty, |
1625 | 80 | arch='amd64') | 80 | arch='amd64') |
1629 | 81 | context = Context( | 81 | user_agent = self.make_useragent(ubuntu_version='11.04', arch='x86_64') |
1630 | 82 | dict(user_agent=self.make_useragent( | 82 | context = Context(dict(user_agent=user_agent)) |
1628 | 83 | ubuntu_version='11.04', arch='x86_64'))) | ||
1631 | 84 | 83 | ||
1632 | 85 | expected = dict(application=application, display_install_button=True, | 84 | expected = dict(application=application, display_install_button=True, |
1634 | 86 | message_text='', display_ubuntu_download=False) | 85 | message_text='', display_ubuntu_download=False) |
1635 | 87 | self.assert_context_values(context, application, expected) | 86 | self.assert_context_values(context, application, expected) |
1636 | 88 | 87 | ||
1637 | 89 | def test_matching_series_arch_not_supported(self): | 88 | def test_matching_series_arch_not_supported(self): |
1638 | @@ -92,14 +91,13 @@ | |||
1639 | 92 | application = self.factory.make_application( | 91 | application = self.factory.make_application( |
1640 | 93 | name="Package Foo", package_name='pkgfoo', | 92 | name="Package Foo", package_name='pkgfoo', |
1641 | 94 | distroseries=self.natty, arch='i686') | 93 | distroseries=self.natty, arch='i686') |
1645 | 95 | context = Context( | 94 | user_agent = self.make_useragent(ubuntu_version='11.04', |
1646 | 96 | dict(user_agent=self.make_useragent( | 95 | arch='solaris') |
1647 | 97 | ubuntu_version='11.04', arch='solaris'))) | 96 | context = Context(dict(user_agent=user_agent)) |
1648 | 98 | 97 | ||
1649 | 99 | expected = dict(application=application, display_install_button=False, | 98 | expected = dict(application=application, display_install_button=False, |
1650 | 100 | message_text='Package Foo is not available for your ' | 99 | message_text='Package Foo is not available for your ' |
1653 | 101 | 'computer.', | 100 | 'computer.', display_ubuntu_download=False) |
1652 | 102 | display_ubuntu_download=False) | ||
1654 | 103 | self.assert_context_values(context, application, expected) | 101 | self.assert_context_values(context, application, expected) |
1655 | 104 | 102 | ||
1656 | 105 | def test_different_series_with_available(self): | 103 | def test_different_series_with_available(self): |
1657 | @@ -107,21 +105,19 @@ | |||
1658 | 107 | # available for their series, then we display a link to the app | 105 | # available for their series, then we display a link to the app |
1659 | 108 | # for their series. | 106 | # for their series. |
1660 | 109 | natty_application = self.factory.make_application( | 107 | natty_application = self.factory.make_application( |
1663 | 110 | name="Package Foo", package_name='pkgfoo', | 108 | name="Package Foo", package_name='pkgfoo', distroseries=self.natty) |
1662 | 111 | distroseries=self.natty) | ||
1664 | 112 | self.factory.make_application( | 109 | self.factory.make_application( |
1667 | 113 | name="Package Foo", package_name='pkgfoo', | 110 | name="Package Foo", package_name='pkgfoo', distroseries=self.lucid) |
1666 | 114 | distroseries=self.lucid) | ||
1668 | 115 | context = Context( | 111 | context = Context( |
1669 | 116 | dict(user_agent=self.make_useragent(ubuntu_version='10.04'))) | 112 | dict(user_agent=self.make_useragent(ubuntu_version='10.04'))) |
1670 | 117 | 113 | ||
1671 | 118 | lucid_app_url = reverse('wc-package-detail', args=['lucid', 'pkgfoo']) | 114 | lucid_app_url = reverse('wc-package-detail', args=['lucid', 'pkgfoo']) |
1672 | 115 | msg = ('Package Foo is also available for ' | ||
1673 | 116 | '<a href="{lucid_app_url}">your version of Ubuntu' | ||
1674 | 117 | '</a>.'.format(lucid_app_url=lucid_app_url)) | ||
1675 | 119 | expected = dict(application=natty_application, | 118 | expected = dict(application=natty_application, |
1676 | 120 | display_install_button=False, | 119 | display_install_button=False, |
1681 | 121 | message_text='Package Foo is also available for ' | 120 | message_text=msg, display_ubuntu_download=False) |
1678 | 122 | '<a href="{lucid_app_url}">your version of Ubuntu' | ||
1679 | 123 | '</a>.'.format(lucid_app_url=lucid_app_url), | ||
1680 | 124 | display_ubuntu_download=False) | ||
1682 | 125 | self.assert_context_values(context, natty_application, expected) | 121 | self.assert_context_values(context, natty_application, expected) |
1683 | 126 | 122 | ||
1684 | 127 | def test_different_series_without_available(self): | 123 | def test_different_series_without_available(self): |
1685 | @@ -136,8 +132,7 @@ | |||
1686 | 136 | expected = dict(application=natty_application, | 132 | expected = dict(application=natty_application, |
1687 | 137 | display_install_button=False, | 133 | display_install_button=False, |
1688 | 138 | message_text='Package Foo is not available for your ' | 134 | message_text='Package Foo is not available for your ' |
1691 | 139 | 'version of Ubuntu.', | 135 | 'version of Ubuntu.', display_ubuntu_download=False) |
1690 | 140 | display_ubuntu_download=False) | ||
1692 | 141 | self.assert_context_values(context, natty_application, expected) | 136 | self.assert_context_values(context, natty_application, expected) |
1693 | 142 | 137 | ||
1694 | 143 | def test_linux_only_displays_install_button(self): | 138 | def test_linux_only_displays_install_button(self): |
1695 | @@ -152,31 +147,27 @@ | |||
1696 | 152 | user_agent=self.make_useragent(ubuntu_version=''))) | 147 | user_agent=self.make_useragent(ubuntu_version=''))) |
1697 | 153 | 148 | ||
1698 | 154 | expected = dict(application=application, display_install_button=True, | 149 | expected = dict(application=application, display_install_button=True, |
1700 | 155 | message_text='', display_ubuntu_download=False) | 150 | message_text='', display_ubuntu_download=False) |
1701 | 156 | self.assert_context_values(context, application, expected) | 151 | self.assert_context_values(context, application, expected) |
1702 | 157 | 152 | ||
1703 | 158 | def test_non_linux_displays_download_ubuntu(self): | 153 | def test_non_linux_displays_download_ubuntu(self): |
1704 | 159 | # A non-linux client is provided a link to download ubuntu. | 154 | # A non-linux client is provided a link to download ubuntu. |
1705 | 160 | application = self.factory.make_application( | 155 | application = self.factory.make_application( |
1706 | 161 | package_name='pkgfoo', name="Package Foo") | 156 | package_name='pkgfoo', name="Package Foo") |
1709 | 162 | context = Context(dict( | 157 | user_agent = self.make_useragent(linux=False) |
1710 | 163 | user_agent=self.make_useragent(linux=False))) | 158 | context = Context(dict(user_agent=user_agent)) |
1711 | 164 | 159 | ||
1712 | 165 | expected = dict(application=application, display_install_button=False, | 160 | expected = dict(application=application, display_install_button=False, |
1715 | 166 | message_text='', | 161 | message_text='', display_ubuntu_download=True) |
1714 | 167 | display_ubuntu_download=True) | ||
1716 | 168 | self.assert_context_values(context, application, expected) | 162 | self.assert_context_values(context, application, expected) |
1717 | 169 | 163 | ||
1718 | 170 | def test_template_tag_uses_config_for_ubuntu_versions(self): | 164 | def test_template_tag_uses_config_for_ubuntu_versions(self): |
1719 | 171 | application = self.factory.make_application( | 165 | application = self.factory.make_application( |
1720 | 172 | name="Fame", distroseries=self.natty, arch='amd64') | 166 | name="Fame", distroseries=self.natty, arch='amd64') |
1724 | 173 | context = Context( | 167 | user_agent = self.make_useragent(ubuntu_version='20.04', arch='x86_64') |
1725 | 174 | dict(user_agent=self.make_useragent( | 168 | context = Context(dict(user_agent=user_agent)) |
1723 | 175 | ubuntu_version='20.04', arch='x86_64'))) | ||
1726 | 176 | 169 | ||
1730 | 177 | with patch_settings(UBUNTU_SERIES_FOR_VERSIONS={ | 170 | with patch_settings(UBUNTU_SERIES_FOR_VERSIONS={'20.04': 'fancy'}): |
1728 | 178 | '20.04': 'fancy', | ||
1729 | 179 | }): | ||
1731 | 180 | install_options(context, application) | 171 | install_options(context, application) |
1732 | 181 | 172 | ||
1733 | 182 | self.assertFalse(context['display_install_button']) | 173 | self.assertFalse(context['display_install_button']) |
1734 | 183 | 174 | ||
1735 | === modified file 'src/webcatalog/tests/test_utilities.py' | |||
1736 | --- src/webcatalog/tests/test_utilities.py 2012-04-20 19:15:00 +0000 | |||
1737 | +++ src/webcatalog/tests/test_utilities.py 2012-06-06 18:03:20 +0000 | |||
1738 | @@ -22,7 +22,7 @@ | |||
1739 | 22 | 'IdentityProviderTestCase', | 22 | 'IdentityProviderTestCase', |
1740 | 23 | 'ScreenshotGetterTestCase', | 23 | 'ScreenshotGetterTestCase', |
1741 | 24 | 'WebServicesRecommenderTestCase', | 24 | 'WebServicesRecommenderTestCase', |
1743 | 25 | ] | 25 | ] |
1744 | 26 | 26 | ||
1745 | 27 | import json | 27 | import json |
1746 | 28 | import os | 28 | import os |
1747 | @@ -31,7 +31,7 @@ | |||
1748 | 31 | from webcatalog.utilities import ( | 31 | from webcatalog.utilities import ( |
1749 | 32 | create_png_from_file, | 32 | create_png_from_file, |
1750 | 33 | WebServices, | 33 | WebServices, |
1752 | 34 | ) | 34 | ) |
1753 | 35 | 35 | ||
1754 | 36 | from django.conf import settings | 36 | from django.conf import settings |
1755 | 37 | from django.core.cache import cache | 37 | from django.core.cache import cache |
1756 | @@ -49,13 +49,10 @@ | |||
1757 | 49 | self.factory.get_test_path('access.svg'), # SVG file | 49 | self.factory.get_test_path('access.svg'), # SVG file |
1758 | 50 | ] | 50 | ] |
1759 | 51 | pngpath = 'test_file_DELETEME.png' | 51 | pngpath = 'test_file_DELETEME.png' |
1760 | 52 | self.addCleanup(lambda: os.path.exists(pngpath) and os.unlink(pngpath)) | ||
1761 | 52 | for f in filenames: | 53 | for f in filenames: |
1768 | 53 | try: | 54 | self.assertTrue(create_png_from_file(pngpath, f, 32, 32)) |
1769 | 54 | self.assertTrue(create_png_from_file(pngpath, f, 32, 32)) | 55 | self.assertTrue(os.path.exists(pngpath)) |
1764 | 55 | self.assertTrue(os.path.exists(pngpath)) | ||
1765 | 56 | finally: | ||
1766 | 57 | if os.path.exists(pngpath): | ||
1767 | 58 | os.unlink(pngpath) | ||
1770 | 59 | 56 | ||
1771 | 60 | def test_invalid_files(self): | 57 | def test_invalid_files(self): |
1772 | 61 | filenames = [ | 58 | filenames = [ |
1773 | @@ -64,13 +61,10 @@ | |||
1774 | 64 | self.factory.get_test_path('junk.svg'), | 61 | self.factory.get_test_path('junk.svg'), |
1775 | 65 | ] | 62 | ] |
1776 | 66 | pngpath = 'test_file_DELETEME.png' | 63 | pngpath = 'test_file_DELETEME.png' |
1777 | 64 | self.addCleanup(lambda: os.path.exists(pngpath) and os.unlink(pngpath)) | ||
1778 | 67 | for f in filenames: | 65 | for f in filenames: |
1785 | 68 | try: | 66 | self.assertFalse(create_png_from_file(pngpath, f, 32, 32)) |
1786 | 69 | self.assertFalse(create_png_from_file(pngpath, f, 32, 32)) | 67 | self.assertFalse(os.path.exists(pngpath)) |
1781 | 70 | self.assertFalse(os.path.exists(pngpath)) | ||
1782 | 71 | finally: | ||
1783 | 72 | if os.path.exists(pngpath): | ||
1784 | 73 | os.unlink(pngpath) | ||
1787 | 74 | 68 | ||
1788 | 75 | 69 | ||
1789 | 76 | class IdentityProviderTestCase(TestCase): | 70 | class IdentityProviderTestCase(TestCase): |
1790 | @@ -83,8 +77,9 @@ | |||
1791 | 83 | self.assertTrue(url.startswith(self.service_root)) | 77 | self.assertTrue(url.startswith(self.service_root)) |
1792 | 84 | if 'ws.op=validate_token' in url: | 78 | if 'ws.op=validate_token' in url: |
1793 | 85 | body = ('{"consumer_secret": "foobarconsumersecret", ' | 79 | body = ('{"consumer_secret": "foobarconsumersecret", ' |
1796 | 86 | '"token": "foo", "consumer_key": "foobar", ' | 80 | '"token": "foo", "consumer_key": "foobar", ' |
1797 | 87 | '"name": "test-token", "token_secret": "foobartokensecret"}') | 81 | '"name": "test-token", ' |
1798 | 82 | '"token_secret": "foobartokensecret"}') | ||
1799 | 88 | elif 'ws.op=me' in url: | 83 | elif 'ws.op=me' in url: |
1800 | 89 | body = ('{"username": "username", "preferred_email": null, ' | 84 | body = ('{"username": "username", "preferred_email": null, ' |
1801 | 90 | '"displayname": "Foo", "unverified_emails": ["f@o.com"], ' | 85 | '"displayname": "Foo", "unverified_emails": ["f@o.com"], ' |
1802 | @@ -113,7 +108,8 @@ | |||
1803 | 113 | mock_request.side_effect = ServerNotFoundError | 108 | mock_request.side_effect = ServerNotFoundError |
1804 | 114 | settings.SSO_AUTH_MODE_NO_UBUNTU_SSO_PLAINTEXT_ONLY = False | 109 | settings.SSO_AUTH_MODE_NO_UBUNTU_SSO_PLAINTEXT_ONLY = False |
1805 | 115 | 110 | ||
1807 | 116 | self.assertRaises(ServerNotFoundError, | 111 | self.assertRaises( |
1808 | 112 | ServerNotFoundError, | ||
1809 | 117 | WebServices().get_data_for_account, 'eg_token', 'eg_ident') | 113 | WebServices().get_data_for_account, 'eg_token', 'eg_ident') |
1810 | 118 | 114 | ||
1811 | 119 | @patch('httplib2.Http.request') | 115 | @patch('httplib2.Http.request') |
1812 | @@ -125,10 +121,12 @@ | |||
1813 | 125 | 121 | ||
1814 | 126 | data = web_services.get_data_for_account('eg_token', 'eg_ident') | 122 | data = web_services.get_data_for_account('eg_token', 'eg_ident') |
1815 | 127 | 123 | ||
1820 | 128 | self.assertEquals(set([u'username', u'preferred_email', | 124 | expected = [ |
1821 | 129 | u'displayname', u'name', u'unverified_emails', u'verified_emails', | 125 | u'username', u'preferred_email', u'displayname', u'name', |
1822 | 130 | u'consumer_secret', u'token', u'openid_identifier', | 126 | u'unverified_emails', u'verified_emails', u'consumer_secret', |
1823 | 131 | u'consumer_key', u'token_secret']), set(data)) | 127 | u'token', u'openid_identifier', u'consumer_key', u'token_secret', |
1824 | 128 | ] | ||
1825 | 129 | self.assertEqual(set(expected), set(data)) | ||
1826 | 132 | 130 | ||
1827 | 133 | 131 | ||
1828 | 134 | class WebServicesRecommenderTestCase(TestCaseWithFactory): | 132 | class WebServicesRecommenderTestCase(TestCaseWithFactory): |
1829 | @@ -147,10 +145,10 @@ | |||
1830 | 147 | {u'rating': 4.0, u'package_name': u'tribaltrouble2'}, | 145 | {u'rating': 4.0, u'package_name': u'tribaltrouble2'}, |
1831 | 148 | {u'rating': 4.0, u'package_name': u'acm'}, | 146 | {u'rating': 4.0, u'package_name': u'acm'}, |
1832 | 149 | {u'rating': 4.0, u'package_name': u'zgv'}, | 147 | {u'rating': 4.0, u'package_name': u'zgv'}, |
1835 | 150 | {u'rating': 3.0, u'package_name': u'nautilus-wallpaper'} | 148 | {u'rating': 3.0, u'package_name': u'nautilus-wallpaper'}, |
1836 | 151 | ], | 149 | ], |
1837 | 152 | u'app': u'firefox', | 150 | u'app': u'firefox', |
1839 | 153 | } | 151 | } |
1840 | 154 | self.mock_recommend_app.return_value = self.eg_recommends | 152 | self.mock_recommend_app.return_value = self.eg_recommends |
1841 | 155 | cache.clear() | 153 | cache.clear() |
1842 | 156 | 154 | ||
1843 | @@ -188,15 +186,16 @@ | |||
1844 | 188 | class ScreenshotGetterTestCase(TestCase): | 186 | class ScreenshotGetterTestCase(TestCase): |
1845 | 189 | @patch('webcatalog.utilities.urllib.urlopen') | 187 | @patch('webcatalog.utilities.urllib.urlopen') |
1846 | 190 | def test_valid_response_returns_list_of_urls(self, mock_urlopen): | 188 | def test_valid_response_returns_list_of_urls(self, mock_urlopen): |
1848 | 191 | response = json.dumps({'package': 'digikam', 'screenshots': [ | 189 | shots = [ |
1849 | 192 | {'version': '1.0', 'large_image_url': 'http://example.com/foo'}, | 190 | {'version': '1.0', 'large_image_url': 'http://example.com/foo'}, |
1850 | 193 | {'version': '1.1', 'large_image_url': 'http://example.com/bar'}, | 191 | {'version': '1.1', 'large_image_url': 'http://example.com/bar'}, |
1852 | 194 | ]}) | 192 | ] |
1853 | 193 | response = json.dumps({'package': 'digikam', 'screenshots': shots}) | ||
1854 | 195 | mock_urlopen.return_value.getcode.return_value = 200 | 194 | mock_urlopen.return_value.getcode.return_value = 200 |
1855 | 196 | mock_urlopen.return_value.read.return_value = response | 195 | mock_urlopen.return_value.read.return_value = response |
1856 | 197 | expected = ['http://example.com/foo', 'http://example.com/bar'] | 196 | expected = ['http://example.com/foo', 'http://example.com/bar'] |
1859 | 198 | self.assertEqual(expected, | 197 | self.assertEqual( |
1860 | 199 | WebServices().get_screenshots_for_package('digikam')) | 198 | expected, WebServices().get_screenshots_for_package('digikam')) |
1861 | 200 | 199 | ||
1862 | 201 | @patch('webcatalog.utilities.urllib.urlopen') | 200 | @patch('webcatalog.utilities.urllib.urlopen') |
1863 | 202 | def test_not_found_response_returns_empty_list(self, mock_urlopen): | 201 | def test_not_found_response_returns_empty_list(self, mock_urlopen): |
1864 | 203 | 202 | ||
1865 | === modified file 'src/webcatalog/tests/test_views.py' | |||
1866 | --- src/webcatalog/tests/test_views.py 2012-06-06 13:03:45 +0000 | |||
1867 | +++ src/webcatalog/tests/test_views.py 2012-06-06 18:03:20 +0000 | |||
1868 | @@ -20,7 +20,7 @@ | |||
1869 | 20 | from __future__ import ( | 20 | from __future__ import ( |
1870 | 21 | absolute_import, | 21 | absolute_import, |
1871 | 22 | with_statement, | 22 | with_statement, |
1873 | 23 | ) | 23 | ) |
1874 | 24 | 24 | ||
1875 | 25 | import json | 25 | import json |
1876 | 26 | import re | 26 | import re |
1877 | @@ -40,7 +40,7 @@ | |||
1878 | 40 | from webcatalog.models import ( | 40 | from webcatalog.models import ( |
1879 | 41 | Department, | 41 | Department, |
1880 | 42 | DistroSeries, | 42 | DistroSeries, |
1882 | 43 | ) | 43 | ) |
1883 | 44 | from webcatalog.tests.factory import TestCaseWithFactory | 44 | from webcatalog.tests.factory import TestCaseWithFactory |
1884 | 45 | from webcatalog.tests.helpers import patch_settings | 45 | from webcatalog.tests.helpers import patch_settings |
1885 | 46 | 46 | ||
1886 | @@ -57,11 +57,11 @@ | |||
1887 | 57 | 'OverviewTestCase', | 57 | 'OverviewTestCase', |
1888 | 58 | 'SearchTestCase', | 58 | 'SearchTestCase', |
1889 | 59 | 'ComboViewTestCase', | 59 | 'ComboViewTestCase', |
1891 | 60 | ] | 60 | ] |
1892 | 61 | 61 | ||
1893 | 62 | 62 | ||
1894 | 63 | WINDOWS_USERAGENT = ('Mozilla/5.0 (Windows NT 5.1; rv:2.0) ' | 63 | WINDOWS_USERAGENT = ('Mozilla/5.0 (Windows NT 5.1; rv:2.0) ' |
1896 | 64 | 'Gecko/20100101 Firefox/4.0') | 64 | 'Gecko/20100101 Firefox/4.0') |
1897 | 65 | 65 | ||
1898 | 66 | UBUNTU_USERAGENT = ('Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) ' | 66 | UBUNTU_USERAGENT = ('Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) ' |
1899 | 67 | 'Gecko/20100101 Firefox/4.0.1') | 67 | 'Gecko/20100101 Firefox/4.0.1') |
1900 | @@ -96,8 +96,8 @@ | |||
1901 | 96 | if not detail_package: | 96 | if not detail_package: |
1902 | 97 | detail_package = app.package_name | 97 | detail_package = app.package_name |
1903 | 98 | 98 | ||
1906 | 99 | url = reverse('wc-package-detail', args=[detail_distro, | 99 | url = reverse('wc-package-detail', |
1907 | 100 | detail_package]) | 100 | args=[detail_distro, detail_package]) |
1908 | 101 | 101 | ||
1909 | 102 | if useragent: | 102 | if useragent: |
1910 | 103 | response = self.client.get(url, HTTP_USER_AGENT=useragent) | 103 | response = self.client.get(url, HTTP_USER_AGENT=useragent) |
1911 | @@ -112,9 +112,9 @@ | |||
1912 | 112 | 112 | ||
1913 | 113 | def test_includes_application_details(self): | 113 | def test_includes_application_details(self): |
1914 | 114 | # The details of an application are included in the rendered html. | 114 | # The details of an application are included in the rendered html. |
1918 | 115 | response, app = self.get_app_and_response(name='My app foo', | 115 | response, app = self.get_app_and_response( |
1919 | 116 | comment='The best app eva.', | 116 | name='My app foo', comment='The best app eva.', |
1920 | 117 | description='A long description.') | 117 | description='A long description.') |
1921 | 118 | 118 | ||
1922 | 119 | self.assertContains(response, "My app foo") | 119 | self.assertContains(response, "My app foo") |
1923 | 120 | self.assertContains(response, "The best app eva.") | 120 | self.assertContains(response, "The best app eva.") |
1924 | @@ -142,20 +142,16 @@ | |||
1925 | 142 | def test_link_to_package_reviews(self): | 142 | def test_link_to_package_reviews(self): |
1926 | 143 | response, app = self.get_app_and_response() | 143 | response, app = self.get_app_and_response() |
1927 | 144 | 144 | ||
1933 | 145 | self.assertContains(response, '<a href="{0}"'.format( | 145 | url = reverse('wc-package-reviews', |
1934 | 146 | reverse('wc-package-reviews', args=[ | 146 | args=[app.distroseries.code_name, app.package_name]) |
1935 | 147 | app.distroseries.code_name, | 147 | self.assertContains(response, '<a href="{0}"'.format(url)) |
1931 | 148 | app.package_name, | ||
1932 | 149 | ]))) | ||
1936 | 150 | 148 | ||
1937 | 151 | def test_link_to_reviews_snippet(self): | 149 | def test_link_to_reviews_snippet(self): |
1938 | 152 | response, app = self.get_app_and_response() | 150 | response, app = self.get_app_and_response() |
1939 | 153 | 151 | ||
1945 | 154 | self.assertContains(response, 'var reviews_uri = "{0}"'.format( | 152 | url = reverse('wc-package-reviews-ajax', |
1946 | 155 | reverse('wc-package-reviews-ajax', args=[ | 153 | args=[app.distroseries.code_name, app.package_name]) |
1947 | 156 | app.distroseries.code_name, | 154 | self.assertContains(response, 'var reviews_uri = "{0}"'.format(url)) |
1943 | 157 | app.package_name, | ||
1944 | 158 | ]))) | ||
1948 | 159 | 155 | ||
1949 | 160 | def test_link_to_recommended_apps_not_present(self): | 156 | def test_link_to_recommended_apps_not_present(self): |
1950 | 161 | with patch_settings(NUM_RECOMMENDED_APPS=0): | 157 | with patch_settings(NUM_RECOMMENDED_APPS=0): |
1951 | @@ -211,8 +207,8 @@ | |||
1952 | 211 | def test_twitter_link_does_not_contain_none(self): | 207 | def test_twitter_link_does_not_contain_none(self): |
1953 | 212 | app = self.factory.make_application() | 208 | app = self.factory.make_application() |
1954 | 213 | 209 | ||
1957 | 214 | response = self.client.get( | 210 | response = self.client.get(reverse('wc-package-detail', |
1958 | 215 | reverse('wc-package-detail', args=[app.package_name])) | 211 | args=[app.package_name])) |
1959 | 216 | 212 | ||
1960 | 217 | self.assertContains( | 213 | self.assertContains( |
1961 | 218 | response, | 214 | response, |
1962 | @@ -234,28 +230,29 @@ | |||
1963 | 234 | # available for their series, then we display a link to the app | 230 | # available for their series, then we display a link to the app |
1964 | 235 | # for their series. | 231 | # for their series. |
1965 | 236 | lucid = self.factory.make_distroseries(code_name='lucid', | 232 | lucid = self.factory.make_distroseries(code_name='lucid', |
1967 | 237 | version='10.04') | 233 | version='10.04') |
1968 | 238 | lucid_app = self.factory.make_application(package_name='pkgfoo', | 234 | lucid_app = self.factory.make_application(package_name='pkgfoo', |
1970 | 239 | distroseries=lucid) | 235 | distroseries=lucid) |
1971 | 240 | 236 | ||
1974 | 241 | response, app = self.get_app_and_response(name="<a>Escape me", | 237 | response, app = self.get_app_and_response( |
1975 | 242 | useragent="blah Ubuntu/10.04 blah") | 238 | name="<a>Escape me", useragent="blah Ubuntu/10.04 blah") |
1976 | 243 | 239 | ||
1977 | 244 | lucid_app_url = reverse('wc-package-detail', args=['lucid', 'pkgfoo']) | 240 | lucid_app_url = reverse('wc-package-detail', args=['lucid', 'pkgfoo']) |
1979 | 245 | self.assertContains(response, | 241 | self.assertContains( |
1980 | 242 | response, | ||
1981 | 246 | '<a>Escape me is also available for ' | 243 | '<a>Escape me is also available for ' |
1982 | 247 | '<a href="{lucid_app_url}">your version of Ubuntu</a>.'.format( | 244 | '<a href="{lucid_app_url}">your version of Ubuntu</a>.'.format( |
1983 | 248 | lucid_app_url=lucid_app_url)) | 245 | lucid_app_url=lucid_app_url)) |
1984 | 249 | 246 | ||
1985 | 250 | def test_includes_right_navigation(self): | 247 | def test_includes_right_navigation(self): |
1986 | 251 | lucid = self.factory.make_distroseries(code_name='lucid', | 248 | lucid = self.factory.make_distroseries(code_name='lucid', |
1988 | 252 | version='10.04') | 249 | version='10.04') |
1989 | 253 | maverick = self.factory.make_distroseries(code_name='maverick', | 250 | maverick = self.factory.make_distroseries(code_name='maverick', |
1991 | 254 | version='10.10') | 251 | version='10.10') |
1992 | 255 | lucid_app = self.factory.make_application(package_name='pkgfoo', | 252 | lucid_app = self.factory.make_application(package_name='pkgfoo', |
1994 | 256 | distroseries=lucid) | 253 | distroseries=lucid) |
1995 | 257 | maverick_app = self.factory.make_application(package_name='pkgfoo', | 254 | maverick_app = self.factory.make_application(package_name='pkgfoo', |
1997 | 258 | distroseries=maverick) | 255 | distroseries=maverick) |
1998 | 259 | 256 | ||
1999 | 260 | response, app = self.get_app_and_response(name="Foobar") | 257 | response, app = self.get_app_and_response(name="Foobar") |
2000 | 261 | 258 | ||
2001 | @@ -276,7 +273,8 @@ | |||
2002 | 276 | 273 | ||
2003 | 277 | def test_response_includes_rating_summary(self): | 274 | def test_response_includes_rating_summary(self): |
2004 | 278 | distro = self.factory.make_distroseries(code_name='lucid') | 275 | distro = self.factory.make_distroseries(code_name='lucid') |
2006 | 279 | self.factory.make_application(package_name='foo', distroseries=distro, | 276 | self.factory.make_application( |
2007 | 277 | package_name='foo', distroseries=distro, | ||
2008 | 280 | ratings_average=Decimal('3.5'), ratings_total=23) | 278 | ratings_average=Decimal('3.5'), ratings_total=23) |
2009 | 281 | 279 | ||
2010 | 282 | url = reverse('wc-package-detail', args=['lucid', 'foo']) | 280 | url = reverse('wc-package-detail', args=['lucid', 'foo']) |
2011 | @@ -297,7 +295,7 @@ | |||
2012 | 297 | 295 | ||
2013 | 298 | self.client.post(url, data=data, follow=True) | 296 | self.client.post(url, data=data, follow=True) |
2014 | 299 | 297 | ||
2016 | 300 | self.assertEquals(1, len(mail.outbox)) | 298 | self.assertEqual(1, len(mail.outbox)) |
2017 | 301 | email = mail.outbox[0] | 299 | email = mail.outbox[0] |
2018 | 302 | self.assertIn(app.name, email.body) | 300 | self.assertIn(app.name, email.body) |
2019 | 303 | self.assertIn(url, email.body) | 301 | self.assertIn(url, email.body) |
2020 | @@ -319,8 +317,8 @@ | |||
2021 | 319 | 317 | ||
2022 | 320 | response = self.client.post(url, data=data, follow=True) | 318 | response = self.client.post(url, data=data, follow=True) |
2023 | 321 | 319 | ||
2026 | 322 | self.assertNotContains(response, 'Success. Your download link ' | 320 | self.assertNotContains(response, |
2027 | 323 | 'has been sent.') | 321 | 'Success. Your download link has been sent.') |
2028 | 324 | self.assertContains(response, 'This field is required.') | 322 | self.assertContains(response, 'This field is required.') |
2029 | 325 | 323 | ||
2030 | 326 | def test_email_error_bogus(self): | 324 | def test_email_error_bogus(self): |
2031 | @@ -330,13 +328,13 @@ | |||
2032 | 330 | 328 | ||
2033 | 331 | response = self.client.post(url, data=data, follow=True) | 329 | response = self.client.post(url, data=data, follow=True) |
2034 | 332 | 330 | ||
2037 | 333 | self.assertNotContains(response, 'Success. Your download link ' | 331 | self.assertNotContains(response, |
2038 | 334 | 'has been sent.') | 332 | 'Success. Your download link has been sent.') |
2039 | 335 | self.assertContains(response, 'Enter a valid e-mail address.') | 333 | self.assertContains(response, 'Enter a valid e-mail address.') |
2040 | 336 | 334 | ||
2041 | 337 | def test_version_and_label_displayed(self): | 335 | def test_version_and_label_displayed(self): |
2044 | 338 | app = self.factory.make_application(version='1.2.3', | 336 | app = self.factory.make_application( |
2045 | 339 | distroseries=self.factory.make_distroseries()) | 337 | version='1.2.3', distroseries=self.factory.make_distroseries()) |
2046 | 340 | 338 | ||
2047 | 341 | response = self.client.get(self.get_app_details_url(app)) | 339 | response = self.client.get(self.get_app_details_url(app)) |
2048 | 342 | 340 | ||
2049 | @@ -344,8 +342,8 @@ | |||
2050 | 344 | self.assertContains(response, '<td>1.2.3</td>') | 342 | self.assertContains(response, '<td>1.2.3</td>') |
2051 | 345 | 343 | ||
2052 | 346 | def test_version_label_not_displayed(self): | 344 | def test_version_label_not_displayed(self): |
2055 | 347 | app = self.factory.make_application(version='', | 345 | app = self.factory.make_application( |
2056 | 348 | distroseries=self.factory.make_distroseries()) | 346 | version='', distroseries=self.factory.make_distroseries()) |
2057 | 349 | 347 | ||
2058 | 350 | response = self.client.get(self.get_app_details_url(app)) | 348 | response = self.client.get(self.get_app_details_url(app)) |
2059 | 351 | 349 | ||
2060 | @@ -374,7 +372,8 @@ | |||
2061 | 374 | 372 | ||
2062 | 375 | response = self.client.get(self.get_app_details_url(app)) | 373 | response = self.client.get(self.get_app_details_url(app)) |
2063 | 376 | 374 | ||
2065 | 377 | self.assertContains(response, | 375 | self.assertContains( |
2066 | 376 | response, | ||
2067 | 378 | '<iframe src="http://example.com/video_iframe.html"') | 377 | '<iframe src="http://example.com/video_iframe.html"') |
2068 | 379 | 378 | ||
2069 | 380 | def test_double_entry_in_the_db_is_displayed_sainely(self): | 379 | def test_double_entry_in_the_db_is_displayed_sainely(self): |
2070 | @@ -408,12 +407,12 @@ | |||
2071 | 408 | # If a distroseries is not included in the url, we always render the | 407 | # If a distroseries is not included in the url, we always render the |
2072 | 409 | # latest available app | 408 | # latest available app |
2073 | 410 | natty = self.factory.make_distroseries(code_name='natty', | 409 | natty = self.factory.make_distroseries(code_name='natty', |
2075 | 411 | version='11.04') | 410 | version='11.04') |
2076 | 412 | lucid = self.factory.make_distroseries(code_name='lucid', | 411 | lucid = self.factory.make_distroseries(code_name='lucid', |
2078 | 413 | version='10.04') | 412 | version='10.04') |
2079 | 414 | for dseries in [natty, lucid]: | 413 | for dseries in [natty, lucid]: |
2080 | 415 | self.factory.make_application(package_name='pkgfoo', | 414 | self.factory.make_application(package_name='pkgfoo', |
2082 | 416 | distroseries=dseries) | 415 | distroseries=dseries) |
2083 | 417 | 416 | ||
2084 | 418 | url = reverse('wc-package-detail', args=['pkgfoo']) | 417 | url = reverse('wc-package-detail', args=['pkgfoo']) |
2085 | 419 | response = self.client.get(url) | 418 | response = self.client.get(url) |
2086 | @@ -434,11 +433,10 @@ | |||
2087 | 434 | self.factory.make_application(), | 433 | self.factory.make_application(), |
2088 | 435 | self.factory.make_application(), | 434 | self.factory.make_application(), |
2089 | 436 | self.factory.make_application(), | 435 | self.factory.make_application(), |
2091 | 437 | ] | 436 | ] |
2092 | 438 | 437 | ||
2096 | 439 | response = self.client.get( | 438 | pkgs = "&".join('pkg_name=%s' % app.package_name for app in apps) |
2097 | 440 | reverse('wc-package-list') + '?' + "&".join( | 439 | response = self.client.get(reverse('wc-package-list') + '?' + pkgs) |
2095 | 441 | ['pkg_name=%s' % app.package_name for app in apps])) | ||
2098 | 442 | 440 | ||
2099 | 443 | self.assertEqual(200, response.status_code) | 441 | self.assertEqual(200, response.status_code) |
2100 | 444 | self.assertEqual(apps, response.context['applications']) | 442 | self.assertEqual(apps, response.context['applications']) |
2101 | @@ -446,8 +444,8 @@ | |||
2102 | 446 | def test_includes_depts_in_context(self): | 444 | def test_includes_depts_in_context(self): |
2103 | 447 | depts = Department.objects.filter(parent=None).order_by('name') | 445 | depts = Department.objects.filter(parent=None).order_by('name') |
2104 | 448 | 446 | ||
2107 | 449 | response = self.client.get( | 447 | pkgs = 'pkg_name=firefox' |
2108 | 450 | reverse('wc-package-list') + '?pkg_name=firefox') | 448 | response = self.client.get(reverse('wc-package-list') + '?' + pkgs) |
2109 | 451 | 449 | ||
2110 | 452 | self.assertEqual(200, response.status_code) | 450 | self.assertEqual(200, response.status_code) |
2111 | 453 | self.assertEqual(list(depts), list(response.context['depts'])) | 451 | self.assertEqual(list(depts), list(response.context['depts'])) |
2112 | @@ -467,53 +465,50 @@ | |||
2113 | 467 | 465 | ||
2114 | 468 | response = self.client.get(url, data=data) | 466 | response = self.client.get(url, data=data) |
2115 | 469 | 467 | ||
2117 | 470 | self.assertEquals(response.context['page'].object_list, []) | 468 | self.assertEqual(response.context['page'].object_list, []) |
2118 | 471 | self.assertContains(response, "You didn't search for anything") | 469 | self.assertContains(response, "You didn't search for anything") |
2119 | 472 | 470 | ||
2120 | 473 | def test_search_searches_package_name(self): | 471 | def test_search_searches_package_name(self): |
2121 | 474 | distro = self.factory.make_distroseries(code_name='lucid') | 472 | distro = self.factory.make_distroseries(code_name='lucid') |
2122 | 475 | app1 = self.factory.make_application(package_name='foo', | 473 | app1 = self.factory.make_application(package_name='foo', |
2124 | 476 | distroseries=distro) | 474 | distroseries=distro) |
2125 | 477 | app2 = self.factory.make_application(package_name='bar', | 475 | app2 = self.factory.make_application(package_name='bar', |
2127 | 478 | distroseries=distro) | 476 | distroseries=distro) |
2128 | 479 | app3 = self.factory.make_application(package_name='foobar', | 477 | app3 = self.factory.make_application(package_name='foobar', |
2130 | 480 | distroseries=distro) | 478 | distroseries=distro) |
2131 | 481 | url = reverse('wc-search', args=[distro.code_name]) | 479 | url = reverse('wc-search', args=[distro.code_name]) |
2132 | 482 | expected = {'foo': set([app1, app3]), 'bar': set([app2, app3])} | 480 | expected = {'foo': set([app1, app3]), 'bar': set([app2, app3])} |
2133 | 483 | for q in expected: | 481 | for q in expected: |
2134 | 484 | |||
2135 | 485 | response = self.client.get(url, data={'q': q}) | 482 | response = self.client.get(url, data={'q': q}) |
2138 | 486 | 483 | self.assertEqual( | |
2137 | 487 | self.assertEquals( | ||
2139 | 488 | expected[q], set(response.context['page'].object_list)) | 484 | expected[q], set(response.context['page'].object_list)) |
2140 | 489 | 485 | ||
2141 | 490 | def test_search_searches_name(self): | 486 | def test_search_searches_name(self): |
2142 | 491 | distro = self.factory.make_distroseries(code_name='lucid') | 487 | distro = self.factory.make_distroseries(code_name='lucid') |
2143 | 492 | app1 = self.factory.make_application(name='foo', | 488 | app1 = self.factory.make_application(name='foo', |
2145 | 493 | distroseries=distro) | 489 | distroseries=distro) |
2146 | 494 | app2 = self.factory.make_application(name='bar', | 490 | app2 = self.factory.make_application(name='bar', |
2148 | 495 | distroseries=distro) | 491 | distroseries=distro) |
2149 | 496 | app3 = self.factory.make_application(name='foobar', | 492 | app3 = self.factory.make_application(name='foobar', |
2151 | 497 | distroseries=distro) | 493 | distroseries=distro) |
2152 | 498 | url = reverse('wc-search', args=[distro.code_name]) | 494 | url = reverse('wc-search', args=[distro.code_name]) |
2153 | 499 | expected = {'foo': set([app1, app3]), 'bar': set([app2, app3])} | 495 | expected = {'foo': set([app1, app3]), 'bar': set([app2, app3])} |
2154 | 500 | for q in expected: | 496 | for q in expected: |
2155 | 501 | |||
2156 | 502 | response = self.client.get(url, data={'q': q}) | 497 | response = self.client.get(url, data={'q': q}) |
2159 | 503 | 498 | self.assertEqual( | |
2158 | 504 | self.assertEquals( | ||
2160 | 505 | expected[q], set(response.context['page'].object_list)) | 499 | expected[q], set(response.context['page'].object_list)) |
2161 | 506 | 500 | ||
2162 | 507 | def test_search_includes_link_to_app(self): | 501 | def test_search_includes_link_to_app(self): |
2163 | 508 | distro = self.factory.make_distroseries(code_name='lucid') | 502 | distro = self.factory.make_distroseries(code_name='lucid') |
2164 | 509 | app = self.factory.make_application(name='foo', | 503 | app = self.factory.make_application(name='foo', |
2166 | 510 | distroseries=distro) | 504 | distroseries=distro) |
2167 | 511 | url = reverse('wc-search', args=[distro.code_name]) | 505 | url = reverse('wc-search', args=[distro.code_name]) |
2168 | 512 | 506 | ||
2169 | 513 | response = self.client.get(url, data={'q': 'foo'}) | 507 | response = self.client.get(url, data={'q': 'foo'}) |
2170 | 514 | 508 | ||
2173 | 515 | self.assertContains(response, reverse('wc-package-detail', | 509 | url = reverse('wc-package-detail', |
2174 | 516 | args=[app.distroseries.code_name, app.package_name]), count=2) | 510 | args=[app.distroseries.code_name, app.package_name]) |
2175 | 511 | self.assertContains(response, url, count=2) | ||
2176 | 517 | 512 | ||
2177 | 518 | def test_search_includes_link_to_app_without_distro(self): | 513 | def test_search_includes_link_to_app_without_distro(self): |
2178 | 519 | app = self.factory.make_application(name='foo', is_latest=True) | 514 | app = self.factory.make_application(name='foo', is_latest=True) |
2179 | @@ -521,8 +516,8 @@ | |||
2180 | 521 | 516 | ||
2181 | 522 | response = self.client.get(url, data={'q': 'foo'}) | 517 | response = self.client.get(url, data={'q': 'foo'}) |
2182 | 523 | 518 | ||
2185 | 524 | self.assertContains(response, reverse('wc-package-detail', | 519 | url = reverse('wc-package-detail', args=[app.package_name]) |
2186 | 525 | args=[app.package_name]), count=2) | 520 | self.assertContains(response, url, count=2) |
2187 | 526 | 521 | ||
2188 | 527 | def test_search_no_apps_found_says_so(self): | 522 | def test_search_no_apps_found_says_so(self): |
2189 | 528 | distro = self.factory.make_distroseries(code_name='lucid') | 523 | distro = self.factory.make_distroseries(code_name='lucid') |
2190 | @@ -554,7 +549,8 @@ | |||
2191 | 554 | def test_response_includes_rating_summary(self): | 549 | def test_response_includes_rating_summary(self): |
2192 | 555 | distro = self.factory.make_distroseries(code_name='lucid') | 550 | distro = self.factory.make_distroseries(code_name='lucid') |
2193 | 556 | query = 'someimprobablequery' | 551 | query = 'someimprobablequery' |
2195 | 557 | self.factory.make_application(package_name=query, distroseries=distro, | 552 | self.factory.make_application( |
2196 | 553 | package_name=query, distroseries=distro, | ||
2197 | 558 | ratings_average=Decimal('3.5'), ratings_total=23) | 554 | ratings_average=Decimal('3.5'), ratings_total=23) |
2198 | 559 | 555 | ||
2199 | 560 | url = reverse('wc-search', args=[distro.code_name]) | 556 | url = reverse('wc-search', args=[distro.code_name]) |
2200 | @@ -566,10 +562,10 @@ | |||
2201 | 566 | 562 | ||
2202 | 567 | def test_response_shows_number_of_apps_found(self): | 563 | def test_response_shows_number_of_apps_found(self): |
2203 | 568 | distro = self.factory.make_distroseries(code_name='lucid') | 564 | distro = self.factory.make_distroseries(code_name='lucid') |
2208 | 569 | self.factory.make_application(package_name='foo', | 565 | self.factory.make_application( |
2209 | 570 | distroseries=distro) | 566 | package_name='foo', distroseries=distro) |
2210 | 571 | self.factory.make_application(package_name='foobar', | 567 | self.factory.make_application( |
2211 | 572 | distroseries=distro) | 568 | package_name='foobar', distroseries=distro) |
2212 | 573 | url = reverse('wc-search', args=[distro.code_name]) | 569 | url = reverse('wc-search', args=[distro.code_name]) |
2213 | 574 | 570 | ||
2214 | 575 | response = self.client.get(url, data={'q': 'foo'}) | 571 | response = self.client.get(url, data={'q': 'foo'}) |
2215 | @@ -578,12 +574,12 @@ | |||
2216 | 578 | 574 | ||
2217 | 579 | def test_response_shows_paginated_results(self): | 575 | def test_response_shows_paginated_results(self): |
2218 | 580 | distro = self.factory.make_distroseries(code_name='lucid') | 576 | distro = self.factory.make_distroseries(code_name='lucid') |
2225 | 581 | app1 = self.factory.make_application(name='foo', | 577 | app1 = self.factory.make_application( |
2226 | 582 | distroseries=distro) | 578 | name='foo', distroseries=distro) |
2227 | 583 | app2 = self.factory.make_application(name='fobar', | 579 | app2 = self.factory.make_application( |
2228 | 584 | distroseries=distro) | 580 | name='fobar', distroseries=distro) |
2229 | 585 | app3 = self.factory.make_application(name='foobar', | 581 | app3 = self.factory.make_application( |
2230 | 586 | distroseries=distro) | 582 | name='foobar', distroseries=distro) |
2231 | 587 | url = reverse('wc-search', args=[distro.code_name]) | 583 | url = reverse('wc-search', args=[distro.code_name]) |
2232 | 588 | 584 | ||
2233 | 589 | with patch_settings(PAGE_BATCH_SIZE=2): | 585 | with patch_settings(PAGE_BATCH_SIZE=2): |
2234 | @@ -637,8 +633,8 @@ | |||
2235 | 637 | 633 | ||
2236 | 638 | response = self.client.get(reverse('wc-index')) | 634 | response = self.client.get(reverse('wc-index')) |
2237 | 639 | 635 | ||
2240 | 640 | self.assertContains(response, reverse('wc-department', | 636 | url = reverse('wc-department', kwargs={'dept_slug_or_id': dept.slug}) |
2241 | 641 | kwargs={'dept_slug_or_id': dept.slug})) | 637 | self.assertContains(response, url) |
2242 | 642 | 638 | ||
2243 | 643 | def test_exhibits_widget_doesnt_display_if_no_exhibits_published(self): | 639 | def test_exhibits_widget_doesnt_display_if_no_exhibits_published(self): |
2244 | 644 | self.factory.make_exhibit(published=False) | 640 | self.factory.make_exhibit(published=False) |
2245 | @@ -698,7 +694,8 @@ | |||
2246 | 698 | def test_link_to_dev_site(self): | 694 | def test_link_to_dev_site(self): |
2247 | 699 | response = self.client.get(reverse('wc-index')) | 695 | response = self.client.get(reverse('wc-index')) |
2248 | 700 | 696 | ||
2250 | 701 | self.assertContains(response, | 697 | self.assertContains( |
2251 | 698 | response, | ||
2252 | 702 | '<a href="http://developer.ubuntu.com">' | 699 | '<a href="http://developer.ubuntu.com">' |
2253 | 703 | 'Add your own application</a>') | 700 | 'Add your own application</a>') |
2254 | 704 | 701 | ||
2255 | @@ -713,22 +710,22 @@ | |||
2256 | 713 | "https://launchpad.net/ubuntu-webcatalog", | 710 | "https://launchpad.net/ubuntu-webcatalog", |
2257 | 714 | "http://www.ubuntu.com", | 711 | "http://www.ubuntu.com", |
2258 | 715 | "http://www.canonical.com", | 712 | "http://www.canonical.com", |
2260 | 716 | ] | 713 | ] |
2261 | 717 | response = self.client.get(reverse('wc-index')) | 714 | response = self.client.get(reverse('wc-index')) |
2262 | 718 | for link in links: | 715 | for link in links: |
2263 | 719 | self.assertContains(response, link) | 716 | self.assertContains(response, link) |
2264 | 720 | 717 | ||
2265 | 721 | def make_high_medium_and_low_apps(self, score_high=5.0, score_mid=4.0, | 718 | def make_high_medium_and_low_apps(self, score_high=5.0, score_mid=4.0, |
2266 | 722 | score_low=1.0): | 719 | score_low=1.0): |
2276 | 723 | high = self.factory.make_application(package_name='high', | 720 | high = self.factory.make_application( |
2277 | 724 | wilson_score=score_high, ratings_average=5, | 721 | package_name='high', wilson_score=score_high, ratings_average=5, |
2278 | 725 | ratings_total=500) | 722 | ratings_total=500) |
2279 | 726 | mid = self.factory.make_application(package_name='mid', | 723 | mid = self.factory.make_application( |
2280 | 727 | wilson_score=score_mid, ratings_average=4, | 724 | package_name='mid', wilson_score=score_mid, ratings_average=4, |
2281 | 728 | ratings_total=400) | 725 | ratings_total=400) |
2282 | 729 | low = self.factory.make_application(package_name='low', | 726 | low = self.factory.make_application( |
2283 | 730 | wilson_score=score_low, ratings_average=1, | 727 | package_name='low', wilson_score=score_low, ratings_average=1, |
2284 | 731 | ratings_total=100) | 728 | ratings_total=100) |
2285 | 732 | return (high, mid, low) | 729 | return (high, mid, low) |
2286 | 733 | 730 | ||
2287 | 734 | def test_top_rated_apps_in_response(self): | 731 | def test_top_rated_apps_in_response(self): |
2288 | @@ -821,47 +818,54 @@ | |||
2289 | 821 | response = self.client.get(reverse('wc-department', kwargs={ | 818 | response = self.client.get(reverse('wc-department', kwargs={ |
2290 | 822 | 'distro': 'lucid', 'dept_slug_or_id': dept.id})) | 819 | 'distro': 'lucid', 'dept_slug_or_id': dept.id})) |
2291 | 823 | 820 | ||
2294 | 824 | self.assertContains(response, reverse('wc-department', | 821 | url = reverse('wc-department', |
2295 | 825 | kwargs={'dept_slug_or_id': subdept.slug})) | 822 | kwargs={'dept_slug_or_id': subdept.slug}) |
2296 | 823 | self.assertContains(response, url) | ||
2297 | 826 | 824 | ||
2298 | 827 | def test_department_contains_links_to_subdepartments_no_distro(self): | 825 | def test_department_contains_links_to_subdepartments_no_distro(self): |
2299 | 828 | dept = self.factory.make_department('foo') | 826 | dept = self.factory.make_department('foo') |
2300 | 829 | subdept = self.factory.make_department('bar', parent=dept) | 827 | subdept = self.factory.make_department('bar', parent=dept) |
2301 | 830 | 828 | ||
2304 | 831 | response = self.client.get(reverse('wc-department', | 829 | url = reverse('wc-department', |
2305 | 832 | kwargs={'dept_slug_or_id': dept.id})) | 830 | kwargs={'dept_slug_or_id': dept.id}) |
2306 | 831 | response = self.client.get(url) | ||
2307 | 833 | 832 | ||
2310 | 834 | self.assertContains(response, reverse('wc-department', | 833 | url = reverse('wc-department', |
2311 | 835 | kwargs={'dept_slug_or_id': subdept.slug})) | 834 | kwargs={'dept_slug_or_id': subdept.slug}) |
2312 | 835 | self.assertContains(response, url) | ||
2313 | 836 | 836 | ||
2314 | 837 | def test_department_contains_links_to_apps(self): | 837 | def test_department_contains_links_to_apps(self): |
2315 | 838 | app = self.factory.make_application(package_name='foo') | 838 | app = self.factory.make_application(package_name='foo') |
2316 | 839 | dept = self.factory.make_department('bar') | 839 | dept = self.factory.make_department('bar') |
2317 | 840 | app.departments.add(dept) | 840 | app.departments.add(dept) |
2318 | 841 | 841 | ||
2321 | 842 | response = self.client.get(reverse('wc-department', kwargs={ | 842 | url = reverse('wc-department', |
2322 | 843 | 'distro': app.distroseries.code_name, 'dept_slug_or_id': dept.id})) | 843 | kwargs={'distro': app.distroseries.code_name, |
2323 | 844 | 'dept_slug_or_id': dept.id}) | ||
2324 | 845 | response = self.client.get(url) | ||
2325 | 844 | 846 | ||
2328 | 845 | self.assertContains(response, reverse('wc-package-detail', | 847 | url = reverse('wc-package-detail', |
2329 | 846 | args=[app.distroseries.code_name, app.package_name]), count=2) | 848 | args=[app.distroseries.code_name, app.package_name]) |
2330 | 849 | self.assertContains(response, url, count=2) | ||
2331 | 847 | 850 | ||
2332 | 848 | def test_department_contains_links_to_apps_with_no_distro(self): | 851 | def test_department_contains_links_to_apps_with_no_distro(self): |
2333 | 849 | app = self.factory.make_application(package_name='foo', is_latest=True) | 852 | app = self.factory.make_application(package_name='foo', is_latest=True) |
2334 | 850 | dept = self.factory.make_department('bar') | 853 | dept = self.factory.make_department('bar') |
2335 | 851 | app.departments.add(dept) | 854 | app.departments.add(dept) |
2336 | 852 | 855 | ||
2339 | 853 | response = self.client.get(reverse('wc-department', | 856 | url = reverse('wc-department', kwargs={'dept_slug_or_id': dept.id}) |
2340 | 854 | kwargs={'dept_slug_or_id': dept.id})) | 857 | response = self.client.get(url) |
2341 | 855 | 858 | ||
2344 | 856 | self.assertContains(response, reverse('wc-package-detail', | 859 | url = reverse('wc-package-detail', args=[app.package_name]) |
2345 | 857 | args=[app.package_name]), count=2) | 860 | self.assertContains(response, url, count=2) |
2346 | 858 | 861 | ||
2347 | 859 | def test_department_with_no_subdepts_doesnt_contain_header(self): | 862 | def test_department_with_no_subdepts_doesnt_contain_header(self): |
2348 | 860 | dept = self.factory.make_department('bar') | 863 | dept = self.factory.make_department('bar') |
2349 | 861 | distro = self.factory.make_distroseries(code_name='lucid') | 864 | distro = self.factory.make_distroseries(code_name='lucid') |
2350 | 862 | 865 | ||
2353 | 863 | response = self.client.get(reverse('wc-department', kwargs={ | 866 | url = reverse('wc-department', |
2354 | 864 | 'distro': 'lucid', 'dept_slug_or_id': dept.id})) | 867 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.id}) |
2355 | 868 | response = self.client.get(url) | ||
2356 | 865 | 869 | ||
2357 | 866 | self.assertNotContains(response, 'Subsections') | 870 | self.assertNotContains(response, 'Subsections') |
2358 | 867 | 871 | ||
2359 | @@ -873,7 +877,7 @@ | |||
2360 | 873 | app.departments.add(dept) | 877 | app.departments.add(dept) |
2361 | 874 | 878 | ||
2362 | 875 | url = reverse('wc-department', | 879 | url = reverse('wc-department', |
2364 | 876 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.id}) | 880 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.id}) |
2365 | 877 | with patch_settings(PAGE_BATCH_SIZE=2): | 881 | with patch_settings(PAGE_BATCH_SIZE=2): |
2366 | 878 | response = self.client.get(url) | 882 | response = self.client.get(url) |
2367 | 879 | 883 | ||
2368 | @@ -891,7 +895,7 @@ | |||
2369 | 891 | dept = self.factory.make_department('bar') | 895 | dept = self.factory.make_department('bar') |
2370 | 892 | distro = self.factory.make_distroseries(code_name='lucid') | 896 | distro = self.factory.make_distroseries(code_name='lucid') |
2371 | 893 | url = reverse('wc-department', | 897 | url = reverse('wc-department', |
2373 | 894 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.id}) | 898 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.id}) |
2374 | 895 | response = self.client.get(url, data={'page': 'aef8'}) | 899 | response = self.client.get(url, data={'page': 'aef8'}) |
2375 | 896 | page = response.context['page'] | 900 | page = response.context['page'] |
2376 | 897 | self.assertEqual(1, page.number) | 901 | self.assertEqual(1, page.number) |
2377 | @@ -908,31 +912,31 @@ | |||
2378 | 908 | dept = self.factory.make_department('bar') | 912 | dept = self.factory.make_department('bar') |
2379 | 909 | default = self.factory.make_distroseries( | 913 | default = self.factory.make_distroseries( |
2380 | 910 | code_name=settings.DEFAULT_DISTRO, version='11.04') | 914 | code_name=settings.DEFAULT_DISTRO, version='11.04') |
2385 | 911 | lucid = self.factory.make_distroseries(code_name='lucid', | 915 | lucid = self.factory.make_distroseries( |
2386 | 912 | version='10.04') | 916 | code_name='lucid', version='10.04') |
2387 | 913 | maverick = self.factory.make_distroseries(code_name='maverick', | 917 | maverick = self.factory.make_distroseries( |
2388 | 914 | version='10.10') | 918 | code_name='maverick', version='10.10') |
2389 | 915 | 919 | ||
2395 | 916 | response = self.client.get(reverse('wc-department', | 920 | url = reverse('wc-department', |
2396 | 917 | kwargs={ | 921 | kwargs={'distro': settings.DEFAULT_DISTRO, |
2397 | 918 | 'distro': settings.DEFAULT_DISTRO, | 922 | 'dept_slug_or_id': dept.id}) |
2398 | 919 | 'dept_slug_or_id': dept.id | 923 | response = self.client.get(url) |
2394 | 920 | })) | ||
2399 | 921 | 924 | ||
2400 | 922 | for ds in ['lucid', 'maverick']: | 925 | for ds in ['lucid', 'maverick']: |
2401 | 923 | url = reverse('wc-department', | 926 | url = reverse('wc-department', |
2403 | 924 | kwargs={'distro': ds, 'dept_slug_or_id': dept.slug}) | 927 | kwargs={'distro': ds, 'dept_slug_or_id': dept.slug}) |
2404 | 925 | self.assertContains(response, '<a href="{0}">Ubuntu'.format(url)) | 928 | self.assertContains(response, '<a href="{0}">Ubuntu'.format(url)) |
2405 | 926 | 929 | ||
2406 | 927 | def test_department_includes_rating_summary(self): | 930 | def test_department_includes_rating_summary(self): |
2407 | 928 | dept = self.factory.make_department('bar') | 931 | dept = self.factory.make_department('bar') |
2408 | 929 | lucid = self.factory.make_distroseries(code_name='lucid') | 932 | lucid = self.factory.make_distroseries(code_name='lucid') |
2411 | 930 | app = self.factory.make_application(distroseries=lucid, | 933 | app = self.factory.make_application( |
2412 | 931 | ratings_average=Decimal('3.5'), ratings_total=23) | 934 | distroseries=lucid, ratings_average=Decimal('3.5'), |
2413 | 935 | ratings_total=23) | ||
2414 | 932 | app.departments.add(dept) | 936 | app.departments.add(dept) |
2415 | 933 | 937 | ||
2416 | 934 | url = reverse('wc-department', | 938 | url = reverse('wc-department', |
2418 | 935 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.id}) | 939 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.id}) |
2419 | 936 | response = self.client.get(url) | 940 | response = self.client.get(url) |
2420 | 937 | 941 | ||
2421 | 938 | self.assertContains(response, 'images/star-small-1.png', 3) | 942 | self.assertContains(response, 'images/star-small-1.png', 3) |
2422 | @@ -941,8 +945,10 @@ | |||
2423 | 941 | def test_invalid_distroseries_returns_404(self): | 945 | def test_invalid_distroseries_returns_404(self): |
2424 | 942 | dept = self.factory.make_department('bar') | 946 | dept = self.factory.make_department('bar') |
2425 | 943 | 947 | ||
2428 | 944 | response = self.client.get(reverse('wc-department', | 948 | url = reverse('wc-department', |
2429 | 945 | kwargs={'distro': 'amnesiac', 'dept_slug_or_id': dept.id})) | 949 | kwargs={'distro': 'amnesiac', |
2430 | 950 | 'dept_slug_or_id': dept.id}) | ||
2431 | 951 | response = self.client.get(url) | ||
2432 | 946 | 952 | ||
2433 | 947 | self.assertEqual(404, response.status_code) | 953 | self.assertEqual(404, response.status_code) |
2434 | 948 | 954 | ||
2435 | @@ -951,21 +957,21 @@ | |||
2436 | 951 | default = self.factory.make_distroseries( | 957 | default = self.factory.make_distroseries( |
2437 | 952 | code_name=settings.DEFAULT_DISTRO, version='11.04') | 958 | code_name=settings.DEFAULT_DISTRO, version='11.04') |
2438 | 953 | lucid = self.factory.make_distroseries(code_name='lucid', | 959 | lucid = self.factory.make_distroseries(code_name='lucid', |
2440 | 954 | version='10.04') | 960 | version='10.04') |
2441 | 955 | maverick = self.factory.make_distroseries(code_name='maverick', | 961 | maverick = self.factory.make_distroseries(code_name='maverick', |
2452 | 956 | version='10.10') | 962 | version='10.10') |
2453 | 957 | 963 | ||
2454 | 958 | response = self.client.get(reverse('wc-department', | 964 | url = reverse('wc-department', |
2455 | 959 | kwargs={ | 965 | kwargs={'distro': settings.DEFAULT_DISTRO, |
2456 | 960 | 'distro': settings.DEFAULT_DISTRO, | 966 | 'dept_slug_or_id': dept.id}) |
2457 | 961 | 'dept_slug_or_id': dept.id | 967 | response = self.client.get(url) |
2458 | 962 | })) | 968 | |
2459 | 963 | 969 | url = reverse('wc-department', | |
2460 | 964 | url = reverse('wc-department', | 970 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.slug}) |
2451 | 965 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.slug}) | ||
2461 | 966 | lucid_pos = response.content.find('<a href="{0}">Ubuntu'.format(url)) | 971 | lucid_pos = response.content.find('<a href="{0}">Ubuntu'.format(url)) |
2462 | 967 | url = reverse('wc-department', | 972 | url = reverse('wc-department', |
2464 | 968 | kwargs={'distro': 'maverick', 'dept_slug_or_id': dept.slug}) | 973 | kwargs={'distro': 'maverick', |
2465 | 974 | 'dept_slug_or_id': dept.slug}) | ||
2466 | 969 | maver_pos = response.content.find('<a href="{0}">Ubuntu'.format(url)) | 975 | maver_pos = response.content.find('<a href="{0}">Ubuntu'.format(url)) |
2467 | 970 | self.assertTrue(lucid_pos > maver_pos) | 976 | self.assertTrue(lucid_pos > maver_pos) |
2468 | 971 | 977 | ||
2469 | @@ -973,16 +979,17 @@ | |||
2470 | 973 | dept = self.factory.make_department('bar') | 979 | dept = self.factory.make_department('bar') |
2471 | 974 | self.factory.make_distroseries(code_name='lucid') | 980 | self.factory.make_distroseries(code_name='lucid') |
2472 | 975 | 981 | ||
2475 | 976 | response = self.client.get(reverse('wc-department', kwargs={ | 982 | url = reverse('wc-department', |
2476 | 977 | 'distro': 'lucid', 'dept_slug_or_id': dept.slug})) | 983 | kwargs={'distro': 'lucid', 'dept_slug_or_id': dept.slug}) |
2477 | 984 | response = self.client.get(url) | ||
2478 | 978 | 985 | ||
2479 | 979 | self.assertEqual(200, response.status_code) | 986 | self.assertEqual(200, response.status_code) |
2480 | 980 | 987 | ||
2481 | 981 | def test_no_distroseries_does_not_redirect(self): | 988 | def test_no_distroseries_does_not_redirect(self): |
2482 | 982 | dept = self.factory.make_department('bar') | 989 | dept = self.factory.make_department('bar') |
2483 | 983 | 990 | ||
2486 | 984 | response = self.client.get(reverse('wc-department', | 991 | url = reverse('wc-department', kwargs={'dept_slug_or_id': dept.slug}) |
2487 | 985 | kwargs={'dept_slug_or_id': dept.slug})) | 992 | response = self.client.get(url) |
2488 | 986 | 993 | ||
2489 | 987 | self.assertEqual(200, response.status_code) | 994 | self.assertEqual(200, response.status_code) |
2490 | 988 | 995 | ||
2491 | @@ -1006,29 +1013,31 @@ | |||
2492 | 1006 | 1013 | ||
2493 | 1007 | def test_only_valid_apps(self): | 1014 | def test_only_valid_apps(self): |
2494 | 1008 | response = self.client.get(reverse('wc-package-reviews', | 1015 | response = self.client.get(reverse('wc-package-reviews', |
2496 | 1009 | args=['jaunty', 'doesntexist'])) | 1016 | args=['jaunty', 'doesntexist'])) |
2497 | 1010 | 1017 | ||
2498 | 1011 | self.assertEqual(404, response.status_code) | 1018 | self.assertEqual(404, response.status_code) |
2499 | 1012 | 1019 | ||
2500 | 1013 | def test_uncached_calls_to_rnr_api(self): | 1020 | def test_uncached_calls_to_rnr_api(self): |
2501 | 1014 | app = self.factory.make_application() | 1021 | app = self.factory.make_application() |
2502 | 1015 | 1022 | ||
2505 | 1016 | response = self.client.get(reverse('wc-package-reviews', | 1023 | url = reverse('wc-package-reviews', |
2506 | 1017 | args=[app.distroseries.code_name, app.package_name])) | 1024 | args=[app.distroseries.code_name, app.package_name]) |
2507 | 1025 | response = self.client.get(url) | ||
2508 | 1018 | 1026 | ||
2509 | 1019 | self.assertEqual(1, self.mock_get_reviews.call_count) | 1027 | self.assertEqual(1, self.mock_get_reviews.call_count) |
2510 | 1020 | 1028 | ||
2511 | 1021 | def test_second_call_cached(self): | 1029 | def test_second_call_cached(self): |
2512 | 1022 | app = self.factory.make_application() | 1030 | app = self.factory.make_application() |
2513 | 1023 | 1031 | ||
2514 | 1032 | url = reverse('wc-package-reviews', | ||
2515 | 1033 | args=[app.distroseries.code_name, app.package_name]) | ||
2516 | 1024 | for count in range(2): | 1034 | for count in range(2): |
2519 | 1025 | response = self.client.get(reverse('wc-package-reviews', | 1035 | response = self.client.get(url) |
2518 | 1026 | args=[app.distroseries.code_name, app.package_name])) | ||
2520 | 1027 | 1036 | ||
2521 | 1028 | self.assertEqual(1, self.mock_get_reviews.call_count) | 1037 | self.assertEqual(1, self.mock_get_reviews.call_count) |
2522 | 1029 | 1038 | ||
2523 | 1030 | def make_review_details(self, package_name=None, summary=None, | 1039 | def make_review_details(self, package_name=None, summary=None, |
2525 | 1031 | rating='3.5'): | 1040 | rating='3.5'): |
2526 | 1032 | if package_name is None: | 1041 | if package_name is None: |
2527 | 1033 | package_name = self.factory.get_unique_string(prefix='pkg-') | 1042 | package_name = self.factory.get_unique_string(prefix='pkg-') |
2528 | 1034 | if summary is None: | 1043 | if summary is None: |
2529 | @@ -1042,10 +1051,11 @@ | |||
2530 | 1042 | self.mock_get_reviews.return_value = [ | 1051 | self.mock_get_reviews.return_value = [ |
2531 | 1043 | self.make_review_details(summary='review_summary1'), | 1052 | self.make_review_details(summary='review_summary1'), |
2532 | 1044 | self.make_review_details(summary='review_summary2'), | 1053 | self.make_review_details(summary='review_summary2'), |
2534 | 1045 | ] | 1054 | ] |
2535 | 1046 | 1055 | ||
2538 | 1047 | response = self.client.get(reverse('wc-package-reviews', | 1056 | url = reverse('wc-package-reviews', |
2539 | 1048 | args=[app.distroseries.code_name, app.package_name])) | 1057 | args=[app.distroseries.code_name, app.package_name]) |
2540 | 1058 | response = self.client.get(url) | ||
2541 | 1049 | 1059 | ||
2542 | 1050 | self.assertTemplateUsed( | 1060 | self.assertTemplateUsed( |
2543 | 1051 | response, 'webcatalog/application_review_list.html') | 1061 | response, 'webcatalog/application_review_list.html') |
2544 | @@ -1059,10 +1069,11 @@ | |||
2545 | 1059 | self.mock_get_reviews.return_value = [ | 1069 | self.mock_get_reviews.return_value = [ |
2546 | 1060 | self.make_review_details(summary='review_summary1'), | 1070 | self.make_review_details(summary='review_summary1'), |
2547 | 1061 | self.make_review_details(summary='review_summary2'), | 1071 | self.make_review_details(summary='review_summary2'), |
2549 | 1062 | ] | 1072 | ] |
2550 | 1063 | 1073 | ||
2553 | 1064 | response = self.client.get(reverse('wc-package-reviews-ajax', | 1074 | url = reverse('wc-package-reviews-ajax', |
2554 | 1065 | args=[app.distroseries.code_name, app.package_name])) | 1075 | args=[app.distroseries.code_name, app.package_name]) |
2555 | 1076 | response = self.client.get(url) | ||
2556 | 1066 | 1077 | ||
2557 | 1067 | self.assertTemplateNotUsed( | 1078 | self.assertTemplateNotUsed( |
2558 | 1068 | response, 'webcatalog/application_review_list.html') | 1079 | response, 'webcatalog/application_review_list.html') |
2559 | @@ -1076,8 +1087,9 @@ | |||
2560 | 1076 | del self.get_reviews_patcher | 1087 | del self.get_reviews_patcher |
2561 | 1077 | app = self.factory.make_application(package_name='invalid:name') | 1088 | app = self.factory.make_application(package_name='invalid:name') |
2562 | 1078 | 1089 | ||
2565 | 1079 | response = self.client.get(reverse('wc-package-reviews', | 1090 | url = reverse('wc-package-reviews', |
2566 | 1080 | args=[app.distroseries.code_name, app.package_name])) | 1091 | args=[app.distroseries.code_name, app.package_name]) |
2567 | 1092 | response = self.client.get(url) | ||
2568 | 1081 | 1093 | ||
2569 | 1082 | self.assertEqual(200, response.status_code) | 1094 | self.assertEqual(200, response.status_code) |
2570 | 1083 | 1095 | ||
2571 | @@ -1087,7 +1099,7 @@ | |||
2572 | 1087 | self.factory.make_application(package_name='skype', distroseries=ds) | 1099 | self.factory.make_application(package_name='skype', distroseries=ds) |
2573 | 1088 | 1100 | ||
2574 | 1089 | response = self.client.get(reverse('wc-package-reviews', | 1101 | response = self.client.get(reverse('wc-package-reviews', |
2576 | 1090 | args=[ds.code_name, 'skype'])) | 1102 | args=[ds.code_name, 'skype'])) |
2577 | 1091 | 1103 | ||
2578 | 1092 | self.assertEqual(200, response.status_code) | 1104 | self.assertEqual(200, response.status_code) |
2579 | 1093 | 1105 | ||
2580 | @@ -1095,8 +1107,9 @@ | |||
2581 | 1095 | app = self.factory.make_application() | 1107 | app = self.factory.make_application() |
2582 | 1096 | self.mock_get_reviews.side_effect = APIError('500', 'error') | 1108 | self.mock_get_reviews.side_effect = APIError('500', 'error') |
2583 | 1097 | 1109 | ||
2586 | 1098 | response = self.client.get(reverse('wc-package-reviews', | 1110 | url = reverse('wc-package-reviews', |
2587 | 1099 | args=[app.distroseries.code_name, app.package_name])) | 1111 | args=[app.distroseries.code_name, app.package_name]) |
2588 | 1112 | response = self.client.get(url) | ||
2589 | 1100 | 1113 | ||
2590 | 1101 | self.assertEqual(200, response.status_code) | 1114 | self.assertEqual(200, response.status_code) |
2591 | 1102 | 1115 | ||
2592 | @@ -1109,14 +1122,14 @@ | |||
2593 | 1109 | 1122 | ||
2594 | 1110 | def test_only_valid_apps(self): | 1123 | def test_only_valid_apps(self): |
2595 | 1111 | response = self.client.get(reverse('wc-package-screenshots', | 1124 | response = self.client.get(reverse('wc-package-screenshots', |
2597 | 1112 | args=['doesntexist'])) | 1125 | args=['doesntexist'])) |
2598 | 1113 | 1126 | ||
2599 | 1114 | self.assertEqual(404, response.status_code) | 1127 | self.assertEqual(404, response.status_code) |
2600 | 1115 | 1128 | ||
2601 | 1116 | @patch('webcatalog.utilities.urllib.urlopen') | 1129 | @patch('webcatalog.utilities.urllib.urlopen') |
2602 | 1117 | def test_uncached_calls_to_rnr_api(self, mock_urlopen): | 1130 | def test_uncached_calls_to_rnr_api(self, mock_urlopen): |
2603 | 1118 | self.client.get(reverse('wc-package-screenshots', | 1131 | self.client.get(reverse('wc-package-screenshots', |
2605 | 1119 | args=[self.app.package_name])) | 1132 | args=[self.app.package_name])) |
2606 | 1120 | 1133 | ||
2607 | 1121 | self.assertEqual(1, mock_urlopen.call_count) | 1134 | self.assertEqual(1, mock_urlopen.call_count) |
2608 | 1122 | 1135 | ||
2609 | @@ -1124,7 +1137,7 @@ | |||
2610 | 1124 | def test_second_call_cached(self, mock_urlopen): | 1137 | def test_second_call_cached(self, mock_urlopen): |
2611 | 1125 | for count in range(2): | 1138 | for count in range(2): |
2612 | 1126 | self.client.get(reverse('wc-package-screenshots', | 1139 | self.client.get(reverse('wc-package-screenshots', |
2614 | 1127 | args=[self.app.package_name])) | 1140 | args=[self.app.package_name])) |
2615 | 1128 | 1141 | ||
2616 | 1129 | self.assertEqual(1, mock_urlopen.call_count) | 1142 | self.assertEqual(1, mock_urlopen.call_count) |
2617 | 1130 | 1143 | ||
2618 | @@ -1133,7 +1146,7 @@ | |||
2619 | 1133 | mock_get_screenshots.return_value = self.expected | 1146 | mock_get_screenshots.return_value = self.expected |
2620 | 1134 | 1147 | ||
2621 | 1135 | response = self.client.get(reverse('wc-package-screenshots', | 1148 | response = self.client.get(reverse('wc-package-screenshots', |
2623 | 1136 | args=[self.app.package_name])) | 1149 | args=[self.app.package_name])) |
2624 | 1137 | 1150 | ||
2625 | 1138 | self.assertTemplateNotUsed( | 1151 | self.assertTemplateNotUsed( |
2626 | 1139 | response, 'webcatalog/application_review_list.html') | 1152 | response, 'webcatalog/application_review_list.html') |
2627 | @@ -1145,9 +1158,10 @@ | |||
2628 | 1145 | mock_get_screenshots.return_value = self.expected | 1158 | mock_get_screenshots.return_value = self.expected |
2629 | 1146 | 1159 | ||
2630 | 1147 | with patch_settings(CACHE_MIDDLEWARE_SECONDS=600): | 1160 | with patch_settings(CACHE_MIDDLEWARE_SECONDS=600): |
2634 | 1148 | response = self.client.get(reverse('wc-package-screenshots', | 1161 | url = reverse('wc-package-screenshots', |
2635 | 1149 | args=[self.app.package_name]), | 1162 | args=[self.app.package_name]) |
2636 | 1150 | HTTP_X_REQUESTED_WITH='XMLHttpRequest') | 1163 | response = self.client.get(url, |
2637 | 1164 | HTTP_X_REQUESTED_WITH='XMLHttpRequest') | ||
2638 | 1151 | 1165 | ||
2639 | 1152 | self.assertEqual('max-age=600', response['cache-control']) | 1166 | self.assertEqual('max-age=600', response['cache-control']) |
2640 | 1153 | 1167 | ||
2641 | @@ -1156,7 +1170,7 @@ | |||
2642 | 1156 | self.factory.make_application(package_name=self.app.package_name) | 1170 | self.factory.make_application(package_name=self.app.package_name) |
2643 | 1157 | 1171 | ||
2644 | 1158 | response = self.client.get(reverse('wc-package-screenshots', | 1172 | response = self.client.get(reverse('wc-package-screenshots', |
2646 | 1159 | args=[self.app.package_name])) | 1173 | args=[self.app.package_name])) |
2647 | 1160 | 1174 | ||
2648 | 1161 | self.assertEqual(200, response.status_code) | 1175 | self.assertEqual(200, response.status_code) |
2649 | 1162 | 1176 | ||
2650 | @@ -1164,13 +1178,13 @@ | |||
2651 | 1164 | def test_not_dependent_on_is_latest(self, mock_urlopen): | 1178 | def test_not_dependent_on_is_latest(self, mock_urlopen): |
2652 | 1165 | lucid = self.factory.make_distroseries(code_name='lucid') | 1179 | lucid = self.factory.make_distroseries(code_name='lucid') |
2653 | 1166 | maverick = self.factory.make_distroseries(code_name='maverick') | 1180 | maverick = self.factory.make_distroseries(code_name='maverick') |
2658 | 1167 | self.factory.make_application(package_name='foo', distroseries=lucid, | 1181 | self.factory.make_application( |
2659 | 1168 | is_latest=False) | 1182 | package_name='foo', distroseries=lucid, is_latest=False) |
2660 | 1169 | self.factory.make_application(package_name='foo', | 1183 | self.factory.make_application( |
2661 | 1170 | distroseries=maverick, is_latest=False) | 1184 | package_name='foo', distroseries=maverick, is_latest=False) |
2662 | 1171 | 1185 | ||
2663 | 1172 | response = self.client.get(reverse('wc-package-screenshots', | 1186 | response = self.client.get(reverse('wc-package-screenshots', |
2665 | 1173 | args=['foo'])) | 1187 | args=['foo'])) |
2666 | 1174 | 1188 | ||
2667 | 1175 | self.assertEqual(200, response.status_code) | 1189 | self.assertEqual(200, response.status_code) |
2668 | 1176 | 1190 | ||
2669 | @@ -1191,16 +1205,16 @@ | |||
2670 | 1191 | {u'rating': 4.0, u'package_name': u'tribaltrouble2'}, | 1205 | {u'rating': 4.0, u'package_name': u'tribaltrouble2'}, |
2671 | 1192 | {u'rating': 4.0, u'package_name': u'acm'}, | 1206 | {u'rating': 4.0, u'package_name': u'acm'}, |
2672 | 1193 | {u'rating': 4.0, u'package_name': u'zgv'}, | 1207 | {u'rating': 4.0, u'package_name': u'zgv'}, |
2675 | 1194 | {u'rating': 3.0, u'package_name': u'nautilus-wallpaper'} | 1208 | {u'rating': 3.0, u'package_name': u'nautilus-wallpaper'}, |
2676 | 1195 | ], | 1209 | ], |
2677 | 1196 | u'app': u'firefox', | 1210 | u'app': u'firefox', |
2679 | 1197 | } | 1211 | } |
2680 | 1198 | self.mock_get_recommends.return_value = self.eg_recommends | 1212 | self.mock_get_recommends.return_value = self.eg_recommends |
2681 | 1199 | cache.clear() | 1213 | cache.clear() |
2682 | 1200 | 1214 | ||
2683 | 1201 | def test_only_valid_apps(self): | 1215 | def test_only_valid_apps(self): |
2684 | 1202 | response = self.client.get(reverse('wc-package-recommends', | 1216 | response = self.client.get(reverse('wc-package-recommends', |
2686 | 1203 | args=['doesntexist'])) | 1217 | args=['doesntexist'])) |
2687 | 1204 | 1218 | ||
2688 | 1205 | self.assertEqual(404, response.status_code) | 1219 | self.assertEqual(404, response.status_code) |
2689 | 1206 | 1220 | ||
2690 | 1207 | 1221 | ||
2691 | === modified file 'src/webcatalog/views.py' | |||
2692 | --- src/webcatalog/views.py 2012-06-06 18:03:19 +0000 | |||
2693 | +++ src/webcatalog/views.py 2012-06-06 18:03:20 +0000 | |||
2694 | @@ -159,7 +159,7 @@ | |||
2695 | 159 | paginator = Paginator(apps, settings.PAGE_BATCH_SIZE) | 159 | paginator = Paginator(apps, settings.PAGE_BATCH_SIZE) |
2696 | 160 | page_num = _get_page_num_from_request(request, paginator) | 160 | page_num = _get_page_num_from_request(request, paginator) |
2697 | 161 | 161 | ||
2699 | 162 | context = { | 162 | cntxt = { |
2700 | 163 | 'dept': dept, | 163 | 'dept': dept, |
2701 | 164 | 'subdepts': subdepts, | 164 | 'subdepts': subdepts, |
2702 | 165 | 'page': paginator.page(page_num), | 165 | 'page': paginator.page(page_num), |
2703 | @@ -168,7 +168,7 @@ | |||
2704 | 168 | 'distroseries': distro, | 168 | 'distroseries': distro, |
2705 | 169 | } | 169 | } |
2706 | 170 | return render_to_response('webcatalog/department_overview.html', | 170 | return render_to_response('webcatalog/department_overview.html', |
2708 | 171 | context_instance=RequestContext(request, context)) | 171 | context_instance=RequestContext(request, cntxt)) |
2709 | 172 | 172 | ||
2710 | 173 | 173 | ||
2711 | 174 | def application_list(request): | 174 | def application_list(request): |
woo!