Merge lp:~michael.nelson/ubuntu-webcatalog/1002262-dont-insert-errors-via-ajax into lp:ubuntu-webcatalog

Proposed by Michael Nelson
Status: Merged
Approved by: Łukasz Czyżykowski
Approved revision: 130
Merged at revision: 124
Proposed branch: lp:~michael.nelson/ubuntu-webcatalog/1002262-dont-insert-errors-via-ajax
Merge into: lp:ubuntu-webcatalog
Diff against target: 128 lines (+42/-10)
5 files modified
src/webcatalog/forms.py (+1/-1)
src/webcatalog/templates/webcatalog/application_detail.html (+11/-7)
src/webcatalog/tests/test_views.py (+20/-0)
src/webcatalog/utilities.py (+1/-1)
src/webcatalog/views.py (+9/-1)
To merge this branch: bzr merge lp:~michael.nelson/ubuntu-webcatalog/1002262-dont-insert-errors-via-ajax
Reviewer Review Type Date Requested Status
Łukasz Czyżykowski (community) Approve
Review via email: mp+107341@code.launchpad.net

Commit message

Handle multiple apps per packagename/distroseries and other potential view and api errors when requesting reviews.

Description of the change

Overview
========

Contrary to the branch name, the issue was not related to any API call or ajax response. See bug 1002262 for the details, but in summary, we've now got multiple applications with the same packagename and distroseries in the DB (skype, unity-lens-utilities) - perhaps as a result of importing from both extras and myapps [1].

`fab test`

[1] Note: due to another bug, even if we've since removed the app from the published apps on myapps, the corresponding record won't have been removed in uwc - we only import new ones - bug 985446.

To post a comment you must log in.
Revision history for this message
Łukasz Czyżykowski (lukasz-czyzykowski) wrote :

LGTM

review: Approve
Revision history for this message
Michael Nelson (michael.nelson) wrote :

I've just pushed up some further changes that:

1) Ensures that if in the future, the reviews view 500's for some other reason, we won't display the result, and
2) Ensures that if in the future, the rnr api does return an error, we catch it rather than also erroring.

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/webcatalog/forms.py'
--- src/webcatalog/forms.py 2012-05-03 13:06:53 +0000
+++ src/webcatalog/forms.py 2012-05-25 08:57:18 +0000
@@ -141,7 +141,7 @@
141 tagline, _, description = app_data['description'].partition('\n')141 tagline, _, description = app_data['description'].partition('\n')
142 app_data['comment'] = tagline142 app_data['comment'] = tagline
143 app_data['description'] = description143 app_data['description'] = description
144 if 'debtags' in app_data and app_data['debtags']:144 if 'debtags' in app_data and app_data['debtags']:
145 app_data['debtags'] = json.dumps([get_hw_short_description(x)145 app_data['debtags'] = json.dumps([get_hw_short_description(x)
146 for x in app_data['debtags']])146 for x in app_data['debtags']])
147 app_data['application_id'] = app_data.get('id')147 app_data['application_id'] = app_data.get('id')
148148
=== modified file 'src/webcatalog/templates/webcatalog/application_detail.html'
--- src/webcatalog/templates/webcatalog/application_detail.html 2012-05-08 17:03:43 +0000
+++ src/webcatalog/templates/webcatalog/application_detail.html 2012-05-25 08:57:18 +0000
@@ -14,10 +14,12 @@
14 var reviews_uri = "{% url wc-package-reviews-ajax application.distroseries.code_name application.package_name %}";14 var reviews_uri = "{% url wc-package-reviews-ajax application.distroseries.code_name application.package_name %}";
15 Y.io(reviews_uri, {15 Y.io(reviews_uri, {
16 on: {16 on: {
17 complete: function(id, obj){17 complete: function(id, response){
18 var reviews_html = obj.responseText;18 if (response.status == 200) {
19 var reviews_div = Y.one('#reviews_placeholder');19 var reviews_html = response.responseText;
20 reviews_div.set("innerHTML", reviews_html);20 var reviews_div = Y.one('#reviews_placeholder');
21 reviews_div.set("innerHTML", reviews_html);
22 }
21 }23 }
22 }24 }
23 });25 });
@@ -26,9 +28,11 @@
26 var recommendations_uri = "{% url wc-package-recommends application.package_name %}";28 var recommendations_uri = "{% url wc-package-recommends application.package_name %}";
27 Y.io(recommendations_uri, {29 Y.io(recommendations_uri, {
28 on: {30 on: {
29 complete: function(id, obj){31 complete: function(id, response){
30 var recommends_html = obj.responseText;32 if (response.status == 200) {
31 recommends_div.set("innerHTML", recommends_html);33 var recommends_html = response.responseText;
34 recommends_div.set("innerHTML", recommends_html);
35 }
32 }36 }
33 }37 }
34 });38 });
3539
=== modified file 'src/webcatalog/tests/test_views.py'
--- src/webcatalog/tests/test_views.py 2012-05-23 23:11:26 +0000
+++ src/webcatalog/tests/test_views.py 2012-05-25 08:57:18 +0000
@@ -34,6 +34,7 @@
34from django.test import TestCase34from django.test import TestCase
3535
36from mock import patch36from mock import patch
37from piston_mini_client.failhandlers import APIError
37from rnrclient import ReviewDetails38from rnrclient import ReviewDetails
3839
39from webcatalog.models import (40from webcatalog.models import (
@@ -1043,6 +1044,25 @@
10431044
1044 self.assertEqual(200, response.status_code)1045 self.assertEqual(200, response.status_code)
10451046
1047 def test_handles_multiple_apps_for_same_distroseries(self):
1048 ds = self.factory.make_distroseries()
1049 self.factory.make_application(package_name='skype', distroseries=ds)
1050 self.factory.make_application(package_name='skype', distroseries=ds)
1051
1052 response = self.client.get(reverse('wc-package-reviews',
1053 args=[ds.code_name, 'skype']))
1054
1055 self.assertEqual(200, response.status_code)
1056
1057 def test_handles_api_error(self):
1058 app = self.factory.make_application()
1059 self.mock_get_reviews.side_effect = APIError('500', 'error')
1060
1061 response = self.client.get(reverse('wc-package-reviews',
1062 args=[app.distroseries.code_name, app.package_name]))
1063
1064 self.assertEqual(200, response.status_code)
1065
10461066
1047class ApplicationScreenshotsTestCase(TestCaseWithFactory):1067class ApplicationScreenshotsTestCase(TestCaseWithFactory):
1048 def setUp(self):1068 def setUp(self):
10491069
=== modified file 'src/webcatalog/utilities.py'
--- src/webcatalog/utilities.py 2012-04-20 19:15:00 +0000
+++ src/webcatalog/utilities.py 2012-05-25 08:57:18 +0000
@@ -79,7 +79,7 @@
79 try:79 try:
80 fresh_reviews = self.rnr_api.get_reviews(packagename=package_name,80 fresh_reviews = self.rnr_api.get_reviews(packagename=package_name,
81 distroseries=distroseries, page=page)81 distroseries=distroseries, page=page)
82 except ValidationException:82 except (ValidationException, APIError):
83 fresh_reviews = []83 fresh_reviews = []
84 cache.set(key, fresh_reviews, settings.REVIEWS_CACHE_TIMEOUT)84 cache.set(key, fresh_reviews, settings.REVIEWS_CACHE_TIMEOUT)
85 return fresh_reviews85 return fresh_reviews
8686
=== modified file 'src/webcatalog/views.py'
--- src/webcatalog/views.py 2012-05-23 22:28:39 +0000
+++ src/webcatalog/views.py 2012-05-25 08:57:18 +0000
@@ -37,6 +37,7 @@
37 HttpResponse,37 HttpResponse,
38 )38 )
39from django.shortcuts import (39from django.shortcuts import (
40 get_list_or_404,
40 get_object_or_404,41 get_object_or_404,
41 render_to_response,42 render_to_response,
42 )43 )
@@ -224,8 +225,15 @@
224225
225226
226def application_reviews(request, package_name, distro, ajax=False, page=1):227def application_reviews(request, package_name, distro, ajax=False, page=1):
227 app = get_object_or_404(Application, package_name=package_name,228 # XXX 2012-05-25 bug=1002262 michaeln Multiple apps for distroseries.
229 # It seems that we have a few applications which are present in
230 # multiple archives for the same distroseries (skype,
231 # unity-lens-utilities, probably via a myapps PPA as well as extras?).
232 # Don't break when this happens.
233 apps = get_list_or_404(Application, package_name=package_name,
228 distroseries__code_name=distro)234 distroseries__code_name=distro)
235 app = apps[0]
236
229 # XXX michaeln 2011-09-15 bug=851662 Better review language options.237 # XXX michaeln 2011-09-15 bug=851662 Better review language options.
230 reviews = WebServices().get_reviews_for_package(package_name,238 reviews = WebServices().get_reviews_for_package(package_name,
231 distroseries=distro, page=page)239 distroseries=distro, page=page)

Subscribers

People subscribed via source and target branches