Merge lp:~elachuni/ubuntu-webcatalog/pep8-test into lp:ubuntu-webcatalog
- pep8-test
- Merge into trunk
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Approved by: | Danny Tamez |
Approved revision: | 61 |
Merged at revision: | 60 |
Proposed branch: | lp:~elachuni/ubuntu-webcatalog/pep8-test |
Merge into: | lp:ubuntu-webcatalog |
Diff against target: |
618 lines (+144/-38) 25 files modified
setup.py (+1/-0) src/webcatalog/admin.py (+1/-0) src/webcatalog/api/forms.py (+2/-0) src/webcatalog/api/handlers.py (+8/-4) src/webcatalog/api/urls.py (+7/-3) src/webcatalog/auth.py (+12/-7) src/webcatalog/context_processors.py (+1/-0) src/webcatalog/department_filters.py (+2/-0) src/webcatalog/forms.py (+3/-2) src/webcatalog/management/commands/import_app_install_data.py (+2/-1) src/webcatalog/management/commands/import_for_purchase_apps.py (+3/-1) src/webcatalog/models/applications.py (+3/-1) src/webcatalog/models/oauthtoken.py (+1/-1) src/webcatalog/schema.py (+1/-1) src/webcatalog/templatetags/webcatalog.py (+1/-0) src/webcatalog/tests/__init__.py (+1/-0) src/webcatalog/tests/test_api.py (+3/-0) src/webcatalog/tests/test_commands.py (+4/-5) src/webcatalog/tests/test_models.py (+1/-1) src/webcatalog/tests/test_pep8.py (+72/-0) src/webcatalog/tests/test_templatetags.py (+7/-5) src/webcatalog/tests/test_utilities.py (+4/-3) src/webcatalog/utilities.py (+1/-1) src/webcatalog/views.py (+1/-1) src/webcatalog/wsgi.py (+2/-1) |
To merge this branch: | bzr merge lp:~elachuni/ubuntu-webcatalog/pep8-test |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danny Tamez (community) | Approve | ||
Review via email: mp+87792@code.launchpad.net |
Commit message
Added a test that checks code against PEP 8, and made it pass.
Description of the change
Overview
========
This branch adds a test that checks our code against PEP8, and makes it pass.
Details
=======
The test itself is copied over from sca/devportal.
To post a comment you must log in.
- 61. By Anthony Lenton
-
small doc fix.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'setup.py' | |||
2 | --- setup.py 2011-11-17 16:02:20 +0000 | |||
3 | +++ setup.py 2012-01-06 18:17:37 +0000 | |||
4 | @@ -47,6 +47,7 @@ | |||
5 | 47 | 'httplib2', | 47 | 'httplib2', |
6 | 48 | 'django-pgtools==0.1', | 48 | 'django-pgtools==0.1', |
7 | 49 | 'rnrclient==1.0', | 49 | 'rnrclient==1.0', |
8 | 50 | 'pep8', | ||
9 | 50 | 'PIL', | 51 | 'PIL', |
10 | 51 | 'lazr.restfulclient', | 52 | 'lazr.restfulclient', |
11 | 52 | ], | 53 | ], |
12 | 53 | 54 | ||
13 | === modified file 'src/webcatalog/admin.py' | |||
14 | --- src/webcatalog/admin.py 2011-09-12 13:37:24 +0000 | |||
15 | +++ src/webcatalog/admin.py 2012-01-06 18:17:37 +0000 | |||
16 | @@ -42,6 +42,7 @@ | |||
17 | 42 | list_filter = ('distroseries', 'departments') | 42 | list_filter = ('distroseries', 'departments') |
18 | 43 | exclude = ('for_purchase', 'archive_id') | 43 | exclude = ('for_purchase', 'archive_id') |
19 | 44 | 44 | ||
20 | 45 | |||
21 | 45 | class MachineAdmin(admin.ModelAdmin): | 46 | class MachineAdmin(admin.ModelAdmin): |
22 | 46 | search_fields = ('owner__username', 'hostname', 'uuid') | 47 | search_fields = ('owner__username', 'hostname', 'uuid') |
23 | 47 | list_display = ('hostname', 'uuid', 'owner') | 48 | list_display = ('hostname', 'uuid', 'owner') |
24 | 48 | 49 | ||
25 | === modified file 'src/webcatalog/api/forms.py' | |||
26 | --- src/webcatalog/api/forms.py 2011-09-12 13:37:24 +0000 | |||
27 | +++ src/webcatalog/api/forms.py 2012-01-06 18:17:37 +0000 | |||
28 | @@ -29,6 +29,7 @@ | |||
29 | 29 | 29 | ||
30 | 30 | from webcatalog.models import Machine | 30 | from webcatalog.models import Machine |
31 | 31 | 31 | ||
32 | 32 | |||
33 | 32 | class MachineCreateUpdateForm(forms.ModelForm): | 33 | class MachineCreateUpdateForm(forms.ModelForm): |
34 | 33 | class Meta: | 34 | class Meta: |
35 | 34 | model = Machine | 35 | model = Machine |
36 | @@ -37,6 +38,7 @@ | |||
37 | 37 | 'logo_checksum', | 38 | 'logo_checksum', |
38 | 38 | ) | 39 | ) |
39 | 39 | 40 | ||
40 | 41 | |||
41 | 40 | class MachineUpdatePackagesForm(forms.ModelForm): | 42 | class MachineUpdatePackagesForm(forms.ModelForm): |
42 | 41 | class Meta: | 43 | class Meta: |
43 | 42 | model = Machine | 44 | model = Machine |
44 | 43 | 45 | ||
45 | === modified file 'src/webcatalog/api/handlers.py' | |||
46 | --- src/webcatalog/api/handlers.py 2011-09-12 13:37:24 +0000 | |||
47 | +++ src/webcatalog/api/handlers.py 2012-01-06 18:17:37 +0000 | |||
48 | @@ -37,12 +37,14 @@ | |||
49 | 37 | from webcatalog.models import Machine | 37 | from webcatalog.models import Machine |
50 | 38 | from .forms import MachineCreateUpdateForm, MachineUpdatePackagesForm | 38 | from .forms import MachineCreateUpdateForm, MachineUpdatePackagesForm |
51 | 39 | 39 | ||
52 | 40 | |||
53 | 40 | class ServerStatusHandler(BaseHandler): | 41 | class ServerStatusHandler(BaseHandler): |
54 | 41 | allowed_methods = ('GET',) | 42 | allowed_methods = ('GET',) |
55 | 42 | 43 | ||
56 | 43 | def read(self, request): | 44 | def read(self, request): |
57 | 44 | return "ok" | 45 | return "ok" |
58 | 45 | 46 | ||
59 | 47 | |||
60 | 46 | class ListMachinesHandler(BaseHandler): | 48 | class ListMachinesHandler(BaseHandler): |
61 | 47 | allowed_methods = ('GET',) | 49 | allowed_methods = ('GET',) |
62 | 48 | model = Machine | 50 | model = Machine |
63 | @@ -52,6 +54,7 @@ | |||
64 | 52 | result = Machine.objects.filter(owner=request.user) | 54 | result = Machine.objects.filter(owner=request.user) |
65 | 53 | return result.defer('package_list') | 55 | return result.defer('package_list') |
66 | 54 | 56 | ||
67 | 57 | |||
68 | 55 | class MachineHandler(BaseHandler): | 58 | class MachineHandler(BaseHandler): |
69 | 56 | allowed_methods = ('GET', 'POST', 'DELETE') | 59 | allowed_methods = ('GET', 'POST', 'DELETE') |
70 | 57 | model = Machine | 60 | model = Machine |
71 | @@ -78,7 +81,7 @@ | |||
72 | 78 | for (k, v) in form.errors.items()) | 81 | for (k, v) in form.errors.items()) |
73 | 79 | result = {'status': 'error', 'errors': errors} | 82 | result = {'status': 'error', 'errors': errors} |
74 | 80 | return result | 83 | return result |
76 | 81 | 84 | ||
77 | 82 | def delete(self, request, uuid): | 85 | def delete(self, request, uuid): |
78 | 83 | instances = Machine.objects.filter(owner=request.user, uuid=uuid) | 86 | instances = Machine.objects.filter(owner=request.user, uuid=uuid) |
79 | 84 | if instances.count() > 0: | 87 | if instances.count() > 0: |
80 | @@ -86,17 +89,18 @@ | |||
81 | 86 | return HttpResponse(status=204) | 89 | return HttpResponse(status=204) |
82 | 87 | else: | 90 | else: |
83 | 88 | return HttpResponseNotFound('Invalid machine UUID') | 91 | return HttpResponseNotFound('Invalid machine UUID') |
85 | 89 | 92 | ||
86 | 90 | 93 | ||
87 | 91 | class PackagesHandler(BaseHandler): | 94 | class PackagesHandler(BaseHandler): |
89 | 92 | allowed_methods = ('GET', 'POST',) | 95 | allowed_methods = ('GET', 'POST',) |
90 | 96 | |||
91 | 93 | def read(self, request, uuid): | 97 | def read(self, request, uuid): |
92 | 94 | try: | 98 | try: |
93 | 95 | instance = Machine.objects.get(owner=request.user, uuid=uuid) | 99 | instance = Machine.objects.get(owner=request.user, uuid=uuid) |
94 | 96 | return instance.package_list | 100 | return instance.package_list |
95 | 97 | except Machine.DoesNotExist: | 101 | except Machine.DoesNotExist: |
96 | 98 | return HttpResponseNotFound('Invalid machine UUID') | 102 | return HttpResponseNotFound('Invalid machine UUID') |
98 | 99 | 103 | ||
99 | 100 | def create(self, request, uuid): | 104 | def create(self, request, uuid): |
100 | 101 | try: | 105 | try: |
101 | 102 | instance = Machine.objects.get(owner=request.user, uuid=uuid) | 106 | instance = Machine.objects.get(owner=request.user, uuid=uuid) |
102 | 103 | 107 | ||
103 | === modified file 'src/webcatalog/api/urls.py' | |||
104 | --- src/webcatalog/api/urls.py 2011-09-19 19:54:15 +0000 | |||
105 | +++ src/webcatalog/api/urls.py 2012-01-06 18:17:37 +0000 | |||
106 | @@ -27,6 +27,7 @@ | |||
107 | 27 | 27 | ||
108 | 28 | auth = SSOOAuthAuthentication(realm="Ubuntu Software Center") | 28 | auth = SSOOAuthAuthentication(realm="Ubuntu Software Center") |
109 | 29 | 29 | ||
110 | 30 | |||
111 | 30 | class CSRFExemptResource(Resource): | 31 | class CSRFExemptResource(Resource): |
112 | 31 | """A Custom Resource that is csrf exempt""" | 32 | """A Custom Resource that is csrf exempt""" |
113 | 32 | def __init__(self, handler, authentication=None): | 33 | def __init__(self, handler, authentication=None): |
114 | @@ -34,9 +35,12 @@ | |||
115 | 34 | self.csrf_exempt = True | 35 | self.csrf_exempt = True |
116 | 35 | 36 | ||
117 | 36 | server_status_resource = Resource(handler=ServerStatusHandler) | 37 | server_status_resource = Resource(handler=ServerStatusHandler) |
121 | 37 | list_machines_resource = Resource(handler=ListMachinesHandler, authentication=auth) | 38 | list_machines_resource = Resource(handler=ListMachinesHandler, |
122 | 38 | machine_resource = CSRFExemptResource(handler=MachineHandler, authentication=auth) | 39 | authentication=auth) |
123 | 39 | packages_resource = CSRFExemptResource(handler=PackagesHandler, authentication=auth) | 40 | machine_resource = CSRFExemptResource(handler=MachineHandler, |
124 | 41 | authentication=auth) | ||
125 | 42 | packages_resource = CSRFExemptResource(handler=PackagesHandler, | ||
126 | 43 | authentication=auth) | ||
127 | 40 | 44 | ||
128 | 41 | urlpatterns = patterns('', | 45 | urlpatterns = patterns('', |
129 | 42 | # get status of the service (usually just "ok", might be "read-only") | 46 | # get status of the service (usually just "ok", might be "read-only") |
130 | 43 | 47 | ||
131 | === modified file 'src/webcatalog/auth.py' | |||
132 | --- src/webcatalog/auth.py 2011-09-19 20:01:32 +0000 | |||
133 | +++ src/webcatalog/auth.py 2012-01-06 18:17:37 +0000 | |||
134 | @@ -39,8 +39,9 @@ | |||
135 | 39 | full_claimed_id, | 39 | full_claimed_id, |
136 | 40 | ) | 40 | ) |
137 | 41 | 41 | ||
140 | 42 | TOKEN_CACHE_EXPIRY = timedelta(hours= | 42 | TOKEN_CACHE_EXPIRY = timedelta(hours=getattr(settings, |
141 | 43 | getattr(settings, 'TOKEN_CACHE_EXPIRY_HOURS', 4)) | 43 | 'TOKEN_CACHE_EXPIRY_HOURS', 4)) |
142 | 44 | |||
143 | 44 | 45 | ||
144 | 45 | class SSOOAuthAuthentication(OAuthAuthentication): | 46 | class SSOOAuthAuthentication(OAuthAuthentication): |
145 | 46 | """ This class is a Piston Authentication class. | 47 | """ This class is a Piston Authentication class. |
146 | @@ -65,7 +66,7 @@ | |||
147 | 65 | before the oauth mechanism asks us for them | 66 | before the oauth mechanism asks us for them |
148 | 66 | """ | 67 | """ |
149 | 67 | http_auth = request.META.get('HTTP_AUTHORIZATION', '') | 68 | http_auth = request.META.get('HTTP_AUTHORIZATION', '') |
151 | 68 | headers = {'Authorization' : http_auth} | 69 | headers = {'Authorization': http_auth} |
152 | 69 | orequest = oauth.OAuthRequest.from_request( | 70 | orequest = oauth.OAuthRequest.from_request( |
153 | 70 | request.method, request.build_absolute_uri(), headers=headers, | 71 | request.method, request.build_absolute_uri(), headers=headers, |
154 | 71 | query_string=request.META['QUERY_STRING']) | 72 | query_string=request.META['QUERY_STRING']) |
155 | @@ -98,7 +99,8 @@ | |||
156 | 98 | if len(tokens) == 0 or (tokens[0].updated_at < | 99 | if len(tokens) == 0 or (tokens[0].updated_at < |
157 | 99 | datetime.now() - TOKEN_CACHE_EXPIRY): | 100 | datetime.now() - TOKEN_CACHE_EXPIRY): |
158 | 100 | pieces = web_services.get_data_for_account(token=oauthtoken, | 101 | pieces = web_services.get_data_for_account(token=oauthtoken, |
160 | 101 | openid_identifier=consumer_key, signature=request.get_parameter('oauth_signature')) | 102 | openid_identifier=consumer_key, |
161 | 103 | signature=request.get_parameter('oauth_signature')) | ||
162 | 102 | if not pieces: | 104 | if not pieces: |
163 | 103 | return | 105 | return |
164 | 104 | Consumer.objects.filter(key=consumer_key).exclude( | 106 | Consumer.objects.filter(key=consumer_key).exclude( |
165 | @@ -137,12 +139,13 @@ | |||
166 | 137 | raise OAuthError('initialize_server_request returned None') | 139 | raise OAuthError('initialize_server_request returned None') |
167 | 138 | return oauth_server.verify_request(oauth_request) | 140 | return oauth_server.verify_request(oauth_request) |
168 | 139 | 141 | ||
169 | 142 | |||
170 | 140 | def initialize_server_request(request): | 143 | def initialize_server_request(request): |
171 | 141 | """ | 144 | """ |
172 | 142 | Shortcut for initialization. | 145 | Shortcut for initialization. |
173 | 143 | """ | 146 | """ |
174 | 144 | headers = { | 147 | headers = { |
176 | 145 | 'Authorization' : request.META.get('HTTP_AUTHORIZATION', '') | 148 | 'Authorization': request.META.get('HTTP_AUTHORIZATION', '') |
177 | 146 | } | 149 | } |
178 | 147 | oauth_request = oauth.OAuthRequest.from_request( | 150 | oauth_request = oauth.OAuthRequest.from_request( |
179 | 148 | request.method, request.build_absolute_uri(), headers=headers, | 151 | request.method, request.build_absolute_uri(), headers=headers, |
180 | @@ -150,8 +153,10 @@ | |||
181 | 150 | 153 | ||
182 | 151 | if oauth_request: | 154 | if oauth_request: |
183 | 152 | oauth_server = oauth.OAuthServer(oauth_datastore(oauth_request)) | 155 | oauth_server = oauth.OAuthServer(oauth_datastore(oauth_request)) |
186 | 153 | oauth_server.add_signature_method(oauth.OAuthSignatureMethod_PLAINTEXT()) | 156 | oauth_server.add_signature_method( |
187 | 154 | oauth_server.add_signature_method(oauth.OAuthSignatureMethod_HMAC_SHA1()) | 157 | oauth.OAuthSignatureMethod_PLAINTEXT()) |
188 | 158 | oauth_server.add_signature_method( | ||
189 | 159 | oauth.OAuthSignatureMethod_HMAC_SHA1()) | ||
190 | 155 | else: | 160 | else: |
191 | 156 | oauth_server = None | 161 | oauth_server = None |
192 | 157 | 162 | ||
193 | 158 | 163 | ||
194 | === modified file 'src/webcatalog/context_processors.py' | |||
195 | --- src/webcatalog/context_processors.py 2012-01-06 14:24:49 +0000 | |||
196 | +++ src/webcatalog/context_processors.py 2012-01-06 18:17:37 +0000 | |||
197 | @@ -19,6 +19,7 @@ | |||
198 | 19 | 19 | ||
199 | 20 | from django.conf import settings | 20 | from django.conf import settings |
200 | 21 | 21 | ||
201 | 22 | |||
202 | 22 | def google_analytics_id(request): | 23 | def google_analytics_id(request): |
203 | 23 | """Adds the google analytics id to the context if it's present.""" | 24 | """Adds the google analytics id to the context if it's present.""" |
204 | 24 | return { | 25 | return { |
205 | 25 | 26 | ||
206 | === modified file 'src/webcatalog/department_filters.py' | |||
207 | --- src/webcatalog/department_filters.py 2011-09-12 13:37:24 +0000 | |||
208 | +++ src/webcatalog/department_filters.py 2012-01-06 18:17:37 +0000 | |||
209 | @@ -38,12 +38,14 @@ | |||
210 | 38 | return bool(app.categories_set.intersection(categories_set)) | 38 | return bool(app.categories_set.intersection(categories_set)) |
211 | 39 | return filter_func | 39 | return filter_func |
212 | 40 | 40 | ||
213 | 41 | |||
214 | 41 | def package_name_filter(name_regex): | 42 | def package_name_filter(name_regex): |
215 | 42 | """Returns a filter func that checks if an app's name matches a regex""" | 43 | """Returns a filter func that checks if an app's name matches a regex""" |
216 | 43 | def filter_func(app): | 44 | def filter_func(app): |
217 | 44 | return re.match(name_regex, app.package_name) is not None | 45 | return re.match(name_regex, app.package_name) is not None |
218 | 45 | return filter_func | 46 | return filter_func |
219 | 46 | 47 | ||
220 | 48 | |||
221 | 47 | def section_filter(sections): | 49 | def section_filter(sections): |
222 | 48 | """Returns a filter that checks if an app is in certain sections.""" | 50 | """Returns a filter that checks if an app is in certain sections.""" |
223 | 49 | def filter_func(app): | 51 | def filter_func(app): |
224 | 50 | 52 | ||
225 | === modified file 'src/webcatalog/forms.py' | |||
226 | --- src/webcatalog/forms.py 2011-09-12 13:37:24 +0000 | |||
227 | +++ src/webcatalog/forms.py 2012-01-06 18:17:37 +0000 | |||
228 | @@ -53,7 +53,7 @@ | |||
229 | 53 | 53 | ||
230 | 54 | class Meta: | 54 | class Meta: |
231 | 55 | model = Application | 55 | model = Application |
233 | 56 | exclude = ('distroseries','for_purchase', 'archive_id', 'price') | 56 | exclude = ('distroseries', 'for_purchase', 'archive_id', 'price') |
234 | 57 | 57 | ||
235 | 58 | @classmethod | 58 | @classmethod |
236 | 59 | def get_form_from_desktop_data(cls, str_data, distroseries): | 59 | def get_form_from_desktop_data(cls, str_data, distroseries): |
237 | @@ -61,7 +61,7 @@ | |||
238 | 61 | parser.readfp(StringIO(str_data)) | 61 | parser.readfp(StringIO(str_data)) |
239 | 62 | data = dict(parser.items('Desktop Entry')) | 62 | data = dict(parser.items('Desktop Entry')) |
240 | 63 | for desktop_key, app_key in desktop_field_mappings.items(): | 63 | for desktop_key, app_key in desktop_field_mappings.items(): |
242 | 64 | if data.has_key(desktop_key): | 64 | if desktop_key in data: |
243 | 65 | data[app_key] = data[desktop_key] | 65 | data[app_key] = data[desktop_key] |
244 | 66 | del(data[desktop_key]) | 66 | del(data[desktop_key]) |
245 | 67 | 67 | ||
246 | @@ -86,6 +86,7 @@ | |||
247 | 86 | 86 | ||
248 | 87 | return cleaned_data | 87 | return cleaned_data |
249 | 88 | 88 | ||
250 | 89 | |||
251 | 89 | class ForPurchaseApplicationForm(forms.ModelForm): | 90 | class ForPurchaseApplicationForm(forms.ModelForm): |
252 | 90 | class Meta: | 91 | class Meta: |
253 | 91 | model = Application | 92 | model = Application |
254 | 92 | 93 | ||
255 | === modified file 'src/webcatalog/management/commands/import_app_install_data.py' | |||
256 | --- src/webcatalog/management/commands/import_app_install_data.py 2011-09-12 13:37:24 +0000 | |||
257 | +++ src/webcatalog/management/commands/import_app_install_data.py 2012-01-06 18:17:37 +0000 | |||
258 | @@ -135,7 +135,8 @@ | |||
259 | 135 | 135 | ||
260 | 136 | # Extract and parse the deb archive. | 136 | # Extract and parse the deb archive. |
261 | 137 | deb_file = DebFile(deb_location) | 137 | deb_file = DebFile(deb_location) |
263 | 138 | self.output("Processing application data to update database...\n", 1) | 138 | self.output("Processing application data to update database...\n", |
264 | 139 | 1) | ||
265 | 139 | deb_file.data.extractall(data_dir) | 140 | deb_file.data.extractall(data_dir) |
266 | 140 | matcher = data_dir + '/usr/share/app-install/desktop/*.desktop' | 141 | matcher = data_dir + '/usr/share/app-install/desktop/*.desktop' |
267 | 141 | icon_dir = data_dir + '/usr/share/app-install/icons/' | 142 | icon_dir = data_dir + '/usr/share/app-install/icons/' |
268 | 142 | 143 | ||
269 | === modified file 'src/webcatalog/management/commands/import_for_purchase_apps.py' | |||
270 | --- src/webcatalog/management/commands/import_for_purchase_apps.py 2011-09-15 08:58:19 +0000 | |||
271 | +++ src/webcatalog/management/commands/import_for_purchase_apps.py 2012-01-06 18:17:37 +0000 | |||
272 | @@ -15,7 +15,9 @@ | |||
273 | 15 | # You should have received a copy of the GNU Affero General Public License | 15 | # You should have received a copy of the GNU Affero General Public License |
274 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
275 | 17 | 17 | ||
277 | 18 | """Management command to import for purchase applications from Software Center.""" | 18 | """Management command to import for purchase applications from Software |
278 | 19 | Center. | ||
279 | 20 | """ | ||
280 | 19 | 21 | ||
281 | 20 | from __future__ import ( | 22 | from __future__ import ( |
282 | 21 | absolute_import, | 23 | absolute_import, |
283 | 22 | 24 | ||
284 | === modified file 'src/webcatalog/models/applications.py' | |||
285 | --- src/webcatalog/models/applications.py 2011-09-12 13:37:24 +0000 | |||
286 | +++ src/webcatalog/models/applications.py 2012-01-06 18:17:37 +0000 | |||
287 | @@ -175,7 +175,7 @@ | |||
288 | 175 | if distro is not None: | 175 | if distro is not None: |
289 | 176 | args = [distro] | 176 | args = [distro] |
290 | 177 | args.append(self.id) | 177 | args.append(self.id) |
292 | 178 | url =reverse('wc-department', args=args) | 178 | url = reverse('wc-department', args=args) |
293 | 179 | crumbs.append({'name': self.name, 'url': url}) | 179 | crumbs.append({'name': self.name, 'url': url}) |
294 | 180 | return crumbs | 180 | return crumbs |
295 | 181 | 181 | ||
296 | @@ -186,6 +186,7 @@ | |||
297 | 186 | class ReviewStatsImport(models.Model): | 186 | class ReviewStatsImport(models.Model): |
298 | 187 | distroseries = models.ForeignKey(DistroSeries, unique=True) | 187 | distroseries = models.ForeignKey(DistroSeries, unique=True) |
299 | 188 | last_import = models.DateTimeField(default=datetime.utcnow) | 188 | last_import = models.DateTimeField(default=datetime.utcnow) |
300 | 189 | |||
301 | 189 | class Meta: | 190 | class Meta: |
302 | 190 | app_label = 'webcatalog' | 191 | app_label = 'webcatalog' |
303 | 191 | 192 | ||
304 | @@ -197,6 +198,7 @@ | |||
305 | 197 | packages_checksum = models.CharField(max_length=56) | 198 | packages_checksum = models.CharField(max_length=56) |
306 | 198 | package_list = models.TextField() | 199 | package_list = models.TextField() |
307 | 199 | logo_checksum = models.CharField(max_length=56, blank=True) | 200 | logo_checksum = models.CharField(max_length=56, blank=True) |
308 | 201 | |||
309 | 200 | class Meta: | 202 | class Meta: |
310 | 201 | app_label = 'webcatalog' | 203 | app_label = 'webcatalog' |
311 | 202 | unique_together = ('owner', 'uuid') | 204 | unique_together = ('owner', 'uuid') |
312 | 203 | 205 | ||
313 | === modified file 'src/webcatalog/models/oauthtoken.py' | |||
314 | --- src/webcatalog/models/oauthtoken.py 2011-09-12 13:37:24 +0000 | |||
315 | +++ src/webcatalog/models/oauthtoken.py 2012-01-06 18:17:37 +0000 | |||
316 | @@ -151,6 +151,7 @@ | |||
317 | 151 | class Meta: | 151 | class Meta: |
318 | 152 | app_label = 'webcatalog' | 152 | app_label = 'webcatalog' |
319 | 153 | 153 | ||
320 | 154 | |||
321 | 154 | class DataStore(OAuthDataStore): | 155 | class DataStore(OAuthDataStore): |
322 | 155 | 156 | ||
323 | 156 | def lookup_token(self, token_type, token_field): | 157 | def lookup_token(self, token_type, token_field): |
324 | @@ -186,7 +187,6 @@ | |||
325 | 186 | if consumer is not None: | 187 | if consumer is not None: |
326 | 187 | return consumer.oauth_consumer() | 188 | return consumer.oauth_consumer() |
327 | 188 | 189 | ||
328 | 189 | |||
329 | 190 | def lookup_nonce(self, consumer, token, nonce): | 190 | def lookup_nonce(self, consumer, token, nonce): |
330 | 191 | """ | 191 | """ |
331 | 192 | :param consumer: OAuthConsumer object | 192 | :param consumer: OAuthConsumer object |
332 | 193 | 193 | ||
333 | === modified file 'src/webcatalog/schema.py' | |||
334 | --- src/webcatalog/schema.py 2012-01-06 14:24:49 +0000 | |||
335 | +++ src/webcatalog/schema.py 2012-01-06 18:17:37 +0000 | |||
336 | @@ -76,7 +76,7 @@ | |||
337 | 76 | rnr = ConfigSection() | 76 | rnr = ConfigSection() |
338 | 77 | rnr.rnr_service_root = StringConfigOption( | 77 | rnr.rnr_service_root = StringConfigOption( |
339 | 78 | default="http://reviews.ubuntu.com/reviews/api/1.0") | 78 | default="http://reviews.ubuntu.com/reviews/api/1.0") |
341 | 79 | rnr.reviews_cache_timeout = IntConfigOption(default=60*15) | 79 | rnr.reviews_cache_timeout = IntConfigOption(default=60 * 15) |
342 | 80 | 80 | ||
343 | 81 | sso_api = ConfigSection() | 81 | sso_api = ConfigSection() |
344 | 82 | sso_api.sso_api_service_root = StringConfigOption() | 82 | sso_api.sso_api_service_root = StringConfigOption() |
345 | 83 | 83 | ||
346 | === modified file 'src/webcatalog/templatetags/webcatalog.py' | |||
347 | --- src/webcatalog/templatetags/webcatalog.py 2011-09-15 10:53:40 +0000 | |||
348 | +++ src/webcatalog/templatetags/webcatalog.py 2012-01-06 18:17:37 +0000 | |||
349 | @@ -155,6 +155,7 @@ | |||
350 | 155 | old_indent_level = indent_level | 155 | old_indent_level = indent_level |
351 | 156 | return norm_description.strip() | 156 | return norm_description.strip() |
352 | 157 | 157 | ||
353 | 158 | |||
354 | 158 | @register.filter | 159 | @register.filter |
355 | 159 | def htmlize_package_description(desc): | 160 | def htmlize_package_description(desc): |
356 | 160 | html = "" | 161 | html = "" |
357 | 161 | 162 | ||
358 | === modified file 'src/webcatalog/tests/__init__.py' | |||
359 | --- src/webcatalog/tests/__init__.py 2012-01-06 14:24:49 +0000 | |||
360 | +++ src/webcatalog/tests/__init__.py 2012-01-06 18:17:37 +0000 | |||
361 | @@ -23,6 +23,7 @@ | |||
362 | 23 | from .test_forms import * | 23 | from .test_forms import * |
363 | 24 | from .test_handlers import * | 24 | from .test_handlers import * |
364 | 25 | from .test_models import * | 25 | from .test_models import * |
365 | 26 | from .test_pep8 import * | ||
366 | 26 | from .test_templatetags import * | 27 | from .test_templatetags import * |
367 | 27 | from .test_utilities import * | 28 | from .test_utilities import * |
368 | 28 | from .test_views import * | 29 | from .test_views import * |
369 | 29 | 30 | ||
370 | === modified file 'src/webcatalog/tests/test_api.py' | |||
371 | --- src/webcatalog/tests/test_api.py 2011-09-12 13:37:24 +0000 | |||
372 | +++ src/webcatalog/tests/test_api.py 2012-01-06 18:17:37 +0000 | |||
373 | @@ -43,11 +43,13 @@ | |||
374 | 43 | from .factory import TestCaseWithFactory | 43 | from .factory import TestCaseWithFactory |
375 | 44 | from webcatalog.models import Machine | 44 | from webcatalog.models import Machine |
376 | 45 | 45 | ||
377 | 46 | |||
378 | 46 | class ServerStatusTestCase(TestCase): | 47 | class ServerStatusTestCase(TestCase): |
379 | 47 | def test_server_status(self): | 48 | def test_server_status(self): |
380 | 48 | response = self.client.get('/cat/api/1.0/server-status/') | 49 | response = self.client.get('/cat/api/1.0/server-status/') |
381 | 49 | self.assertEqual(response.content, '"ok"') | 50 | self.assertEqual(response.content, '"ok"') |
382 | 50 | 51 | ||
383 | 52 | |||
384 | 51 | class AuthenticatedAPITestCase(TestCaseWithFactory): | 53 | class AuthenticatedAPITestCase(TestCaseWithFactory): |
385 | 52 | def auth_header_for_user(self, url, user=None, realm='OAuth'): | 54 | def auth_header_for_user(self, url, user=None, realm='OAuth'): |
386 | 53 | token, consumer = self.factory.make_oauth_token_and_consumer(user=user) | 55 | token, consumer = self.factory.make_oauth_token_and_consumer(user=user) |
387 | @@ -63,6 +65,7 @@ | |||
388 | 63 | 65 | ||
389 | 64 | class ListMachinesTestCase(AuthenticatedAPITestCase): | 66 | class ListMachinesTestCase(AuthenticatedAPITestCase): |
390 | 65 | url = '/cat/api/1.0/list-machines/' | 67 | url = '/cat/api/1.0/list-machines/' |
391 | 68 | |||
392 | 66 | def test_no_auth_returns_401(self): | 69 | def test_no_auth_returns_401(self): |
393 | 67 | response = self.client.get(self.url) | 70 | response = self.client.get(self.url) |
394 | 68 | self.assertEqual(401, response.status_code) | 71 | self.assertEqual(401, response.status_code) |
395 | 69 | 72 | ||
396 | === modified file 'src/webcatalog/tests/test_commands.py' | |||
397 | --- src/webcatalog/tests/test_commands.py 2011-09-15 10:53:40 +0000 | |||
398 | +++ src/webcatalog/tests/test_commands.py 2012-01-06 18:17:37 +0000 | |||
399 | @@ -89,9 +89,9 @@ | |||
400 | 89 | mock_cache = MagicMock() | 89 | mock_cache = MagicMock() |
401 | 90 | mock_apt_firefox = self.make_mock_apt_package('firefox', | 90 | mock_apt_firefox = self.make_mock_apt_package('firefox', |
402 | 91 | description="Firefox description") | 91 | description="Firefox description") |
404 | 92 | mock_apt_scribus=self.make_mock_apt_package('scribus', | 92 | mock_apt_scribus = self.make_mock_apt_package('scribus', |
405 | 93 | description="Scribus description") | 93 | description="Scribus description") |
407 | 94 | mock_other_app=self.make_mock_apt_package('otherapp', | 94 | mock_other_app = self.make_mock_apt_package('otherapp', |
408 | 95 | description="Otherapp description", | 95 | description="Otherapp description", |
409 | 96 | summary="Otherapp the Internet\nA tagline for Otherapp") | 96 | summary="Otherapp the Internet\nA tagline for Otherapp") |
410 | 97 | mock_app_install_data = self.make_mock_apt_package('app-install-data', | 97 | mock_app_install_data = self.make_mock_apt_package('app-install-data', |
411 | @@ -169,7 +169,8 @@ | |||
412 | 169 | with patch(get_uri_fn) as mock_get_uri: | 169 | with patch(get_uri_fn) as mock_get_uri: |
413 | 170 | mock_get_uri.return_value = 'http://example.com/my.deb' | 170 | mock_get_uri.return_value = 'http://example.com/my.deb' |
414 | 171 | with patch('urllib.urlretrieve') as mock_urlretrieve: | 171 | with patch('urllib.urlretrieve') as mock_urlretrieve: |
416 | 172 | ImportAppInstallCommand().get_latest_app_data_for_series('natty', tmp_dir) | 172 | ImportAppInstallCommand().get_latest_app_data_for_series( |
417 | 173 | 'natty', tmp_dir) | ||
418 | 173 | shutil.rmtree(tmp_dir) | 174 | shutil.rmtree(tmp_dir) |
419 | 174 | 175 | ||
420 | 175 | mock_urlretrieve.assert_called_with( | 176 | mock_urlretrieve.assert_called_with( |
421 | @@ -540,5 +541,3 @@ | |||
422 | 540 | 541 | ||
423 | 541 | # update_apps_with_stats returns None on success: | 542 | # update_apps_with_stats returns None on success: |
424 | 542 | self.assertIsNone(command.update_apps_with_stats(natty, stats)) | 543 | self.assertIsNone(command.update_apps_with_stats(natty, stats)) |
425 | 543 | |||
426 | 544 | |||
427 | 545 | 544 | ||
428 | === modified file 'src/webcatalog/tests/test_models.py' | |||
429 | --- src/webcatalog/tests/test_models.py 2011-09-12 13:37:24 +0000 | |||
430 | +++ src/webcatalog/tests/test_models.py 2012-01-06 18:17:37 +0000 | |||
431 | @@ -102,7 +102,7 @@ | |||
432 | 102 | def test_normalized_name(self): | 102 | def test_normalized_name(self): |
433 | 103 | cases = { | 103 | cases = { |
434 | 104 | 'Foo': 'Foo', | 104 | 'Foo': 'Foo', |
436 | 105 | 'Foo & Bar': 'FooBar', | 105 | 'Foo & Bar': 'FooBar', |
437 | 106 | ' Foo, Bar ': 'FooBar', | 106 | ' Foo, Bar ': 'FooBar', |
438 | 107 | ' && , ': '', | 107 | ' && , ': '', |
439 | 108 | '': '' | 108 | '': '' |
440 | 109 | 109 | ||
441 | === added file 'src/webcatalog/tests/test_pep8.py' | |||
442 | --- src/webcatalog/tests/test_pep8.py 1970-01-01 00:00:00 +0000 | |||
443 | +++ src/webcatalog/tests/test_pep8.py 2012-01-06 18:17:37 +0000 | |||
444 | @@ -0,0 +1,72 @@ | |||
445 | 1 | # -*- coding: utf-8 -*- | ||
446 | 2 | # This file is part of the Apps Directory | ||
447 | 3 | # Copyright (C) 2011 Canonical Ltd. | ||
448 | 4 | # | ||
449 | 5 | # This program is free software: you can redistribute it and/or modify | ||
450 | 6 | # it under the terms of the GNU Affero General Public License as | ||
451 | 7 | # published by the Free Software Foundation, either version 3 of the | ||
452 | 8 | # License, or (at your option) any later version. | ||
453 | 9 | # | ||
454 | 10 | # This program is distributed in the hope that it will be useful, | ||
455 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
456 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
457 | 13 | # GNU Affero General Public License for more details. | ||
458 | 14 | # | ||
459 | 15 | # You should have received a copy of the GNU Affero General Public License | ||
460 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
461 | 17 | |||
462 | 18 | """Apps Directory pep-8 compliance tests.""" | ||
463 | 19 | |||
464 | 20 | from __future__ import absolute_import | ||
465 | 21 | |||
466 | 22 | __metaclass__ = type | ||
467 | 23 | __all__ = [ | ||
468 | 24 | 'WebCatalogPep8TestCase', | ||
469 | 25 | ] | ||
470 | 26 | |||
471 | 27 | import os | ||
472 | 28 | import pep8 | ||
473 | 29 | from collections import defaultdict | ||
474 | 30 | from unittest import TestCase | ||
475 | 31 | |||
476 | 32 | import webcatalog | ||
477 | 33 | |||
478 | 34 | |||
479 | 35 | class PackagePep8TestCase(TestCase): | ||
480 | 36 | maxDiff = None | ||
481 | 37 | packages = [] | ||
482 | 38 | exclude = ['migrations'] | ||
483 | 39 | |||
484 | 40 | def message(self, text): | ||
485 | 41 | self.errors.append(text) | ||
486 | 42 | |||
487 | 43 | def setUp(self): | ||
488 | 44 | self.errors = [] | ||
489 | 45 | |||
490 | 46 | class Options(object): | ||
491 | 47 | exclude = self.exclude | ||
492 | 48 | filename = ['*.py'] | ||
493 | 49 | testsuite = '' | ||
494 | 50 | doctest = '' | ||
495 | 51 | counters = defaultdict(int) | ||
496 | 52 | messages = {} | ||
497 | 53 | verbose = 0 | ||
498 | 54 | quiet = 0 | ||
499 | 55 | repeat = True | ||
500 | 56 | show_source = False | ||
501 | 57 | show_pep8 = False | ||
502 | 58 | select = [] | ||
503 | 59 | ignore = [] | ||
504 | 60 | pep8.options = Options() | ||
505 | 61 | pep8.message = self.message | ||
506 | 62 | Options.physical_checks = pep8.find_checks('physical_line') | ||
507 | 63 | Options.logical_checks = pep8.find_checks('logical_line') | ||
508 | 64 | |||
509 | 65 | def test_all_code(self): | ||
510 | 66 | for package in self.packages: | ||
511 | 67 | pep8.input_dir(os.path.dirname(package.__file__)) | ||
512 | 68 | self.assertEqual([], self.errors) | ||
513 | 69 | |||
514 | 70 | |||
515 | 71 | class WebCatalogPep8TestCase(PackagePep8TestCase): | ||
516 | 72 | packages = [webcatalog] | ||
517 | 0 | 73 | ||
518 | === modified file 'src/webcatalog/tests/test_templatetags.py' | |||
519 | --- src/webcatalog/tests/test_templatetags.py 2011-09-15 10:53:40 +0000 | |||
520 | +++ src/webcatalog/tests/test_templatetags.py 2012-01-06 18:17:37 +0000 | |||
521 | @@ -182,7 +182,8 @@ | |||
522 | 182 | * Lha archives (.lzh) | 182 | * Lha archives (.lzh) |
523 | 183 | * Single files compressed with gzip (.gz), bzip (.bz), bzip2 (.bz2), | 183 | * Single files compressed with gzip (.gz), bzip (.bz), bzip2 (.bz2), |
524 | 184 | compress (.Z), lzip (.lz), lzop (.lzo), lzma (.lzma) and xz (.xz) | 184 | compress (.Z), lzip (.lz), lzop (.lzo), lzma (.lzma) and xz (.xz) |
526 | 185 | File-roller doesn't perform archive operations by itself, but relies on standard tools for this. | 185 | File-roller doesn't perform archive operations by itself, but relies on \ |
527 | 186 | standard tools for this. | ||
528 | 186 | """ | 187 | """ |
529 | 187 | 188 | ||
530 | 188 | #drgeo | 189 | #drgeo |
531 | @@ -240,6 +241,7 @@ | |||
532 | 240 | * Extensible with plugins | 241 | * Extensible with plugins |
533 | 241 | """ | 242 | """ |
534 | 242 | 243 | ||
535 | 244 | |||
536 | 243 | class HtmlizePackageDescriptionTestCase(unittest.TestCase): | 245 | class HtmlizePackageDescriptionTestCase(unittest.TestCase): |
537 | 244 | def test_htmlize(self): | 246 | def test_htmlize(self): |
538 | 245 | for descr in [d1, d2, d3]: | 247 | for descr in [d1, d2, d3]: |
539 | @@ -275,13 +277,13 @@ | |||
540 | 275 | class VisiblePageRangeTestCase(unittest.TestCase): | 277 | class VisiblePageRangeTestCase(unittest.TestCase): |
541 | 276 | def test_visible_page_range(self): | 278 | def test_visible_page_range(self): |
542 | 277 | cases = [ | 279 | cases = [ |
544 | 278 | ( 2, 1, [1, 2]), | 280 | (2, 1, [1, 2]), |
545 | 279 | (20, 1, range(1, 11)), | 281 | (20, 1, range(1, 11)), |
547 | 280 | ( 3, 2, [1, 2, 3]), | 282 | (3, 2, [1, 2, 3]), |
548 | 281 | (20, 2, range(1, 11)), | 283 | (20, 2, range(1, 11)), |
550 | 282 | ( 4, 4, [1, 2, 3, 4]), | 284 | (4, 4, [1, 2, 3, 4]), |
551 | 283 | (20, 8, range(3, 13)), | 285 | (20, 8, range(3, 13)), |
553 | 284 | ( 8, 8, range(3, 9)), | 286 | (8, 8, range(3, 9)), |
554 | 285 | (20, 18, range(13, 21)), | 287 | (20, 18, range(13, 21)), |
555 | 286 | (400, 400, range(395, 401)), | 288 | (400, 400, range(395, 401)), |
556 | 287 | ] | 289 | ] |
557 | 288 | 290 | ||
558 | === modified file 'src/webcatalog/tests/test_utilities.py' | |||
559 | --- src/webcatalog/tests/test_utilities.py 2011-09-12 13:37:24 +0000 | |||
560 | +++ src/webcatalog/tests/test_utilities.py 2012-01-06 18:17:37 +0000 | |||
561 | @@ -22,12 +22,13 @@ | |||
562 | 22 | from webcatalog.tests.factory import TestCaseWithFactory | 22 | from webcatalog.tests.factory import TestCaseWithFactory |
563 | 23 | from webcatalog.utilities import create_png_from_file | 23 | from webcatalog.utilities import create_png_from_file |
564 | 24 | 24 | ||
565 | 25 | |||
566 | 25 | class CreatePNGFromFileTestCase(TestCaseWithFactory): | 26 | class CreatePNGFromFileTestCase(TestCaseWithFactory): |
567 | 26 | def test_file_conversion(self): | 27 | def test_file_conversion(self): |
568 | 27 | filenames = [ | 28 | filenames = [ |
572 | 28 | self.factory.get_test_path('firefox.xpm'), # Regular xpm | 29 | self.factory.get_test_path('firefox.xpm'), # Regular xpm |
573 | 29 | self.factory.get_test_path('mini-gsmc.xpm'), # named colors | 30 | self.factory.get_test_path('mini-gsmc.xpm'), # named colors |
574 | 30 | self.factory.get_test_path('access.svg'), # SVG file | 31 | self.factory.get_test_path('access.svg'), # SVG file |
575 | 31 | ] | 32 | ] |
576 | 32 | pngpath = 'test_file_DELETEME.png' | 33 | pngpath = 'test_file_DELETEME.png' |
577 | 33 | for f in filenames: | 34 | for f in filenames: |
578 | 34 | 35 | ||
579 | === modified file 'src/webcatalog/utilities.py' | |||
580 | --- src/webcatalog/utilities.py 2011-09-15 13:40:53 +0000 | |||
581 | +++ src/webcatalog/utilities.py 2012-01-06 18:17:37 +0000 | |||
582 | @@ -102,7 +102,7 @@ | |||
583 | 102 | if cached_reviews is not None: | 102 | if cached_reviews is not None: |
584 | 103 | return cached_reviews | 103 | return cached_reviews |
585 | 104 | 104 | ||
587 | 105 | fresh_reviews = self.rnr_api.get_reviews(packagename=package_name, | 105 | fresh_reviews = self.rnr_api.get_reviews(packagename=package_name, |
588 | 106 | distroseries=distroseries, page=page) | 106 | distroseries=distroseries, page=page) |
589 | 107 | cache.set(key, fresh_reviews, settings.REVIEWS_CACHE_TIMEOUT) | 107 | cache.set(key, fresh_reviews, settings.REVIEWS_CACHE_TIMEOUT) |
590 | 108 | return fresh_reviews | 108 | return fresh_reviews |
591 | 109 | 109 | ||
592 | === modified file 'src/webcatalog/views.py' | |||
593 | --- src/webcatalog/views.py 2011-09-16 09:43:11 +0000 | |||
594 | +++ src/webcatalog/views.py 2012-01-06 18:17:37 +0000 | |||
595 | @@ -182,7 +182,7 @@ | |||
596 | 182 | app = get_object_or_404(Application, package_name=package_name, | 182 | app = get_object_or_404(Application, package_name=package_name, |
597 | 183 | distroseries__code_name=distro) | 183 | distroseries__code_name=distro) |
598 | 184 | # XXX michaeln 2011-09-15 bug=851662 Better review language options. | 184 | # XXX michaeln 2011-09-15 bug=851662 Better review language options. |
600 | 185 | reviews = WebServices().get_reviews_for_package(package_name, | 185 | reviews = WebServices().get_reviews_for_package(package_name, |
601 | 186 | distroseries=distro, page=page) | 186 | distroseries=distro, page=page) |
602 | 187 | 187 | ||
603 | 188 | context = dict(application=app, reviews=reviews) | 188 | context = dict(application=app, reviews=reviews) |
604 | 189 | 189 | ||
605 | === modified file 'src/webcatalog/wsgi.py' | |||
606 | --- src/webcatalog/wsgi.py 2011-09-12 13:37:24 +0000 | |||
607 | +++ src/webcatalog/wsgi.py 2012-01-06 18:17:37 +0000 | |||
608 | @@ -25,8 +25,9 @@ | |||
609 | 25 | from django.core.handlers.wsgi import WSGIHandler | 25 | from django.core.handlers.wsgi import WSGIHandler |
610 | 26 | from django.conf import settings | 26 | from django.conf import settings |
611 | 27 | 27 | ||
612 | 28 | |||
613 | 28 | def make_app(): | 29 | def make_app(): |
615 | 29 | """Encapsulate our webcatalog handler in an OOPS app for error reporting.""" | 30 | """Encapsulate our webcatalog handler in an OOPS app.""" |
616 | 30 | default_id = ''.join(x for x in platform.node() if x.isalpha()) | 31 | default_id = ''.join(x for x in platform.node() if x.isalpha()) |
617 | 31 | appserver_id = getattr(settings, 'APPSERVER_ID', default_id) | 32 | appserver_id = getattr(settings, 'APPSERVER_ID', default_id) |
618 | 32 | logging.config.fileConfig(settings.WEBAPP_LOGGING_CONFIG) | 33 | logging.config.fileConfig(settings.WEBAPP_LOGGING_CONFIG) |
I always wondered how many PEP8 changes would have to be made when adding this test :)
Looks good