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