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
1=== modified file 'src/webcatalog/forms.py'
2--- src/webcatalog/forms.py 2012-05-03 13:06:53 +0000
3+++ src/webcatalog/forms.py 2012-05-25 08:57:18 +0000
4@@ -141,7 +141,7 @@
5 tagline, _, description = app_data['description'].partition('\n')
6 app_data['comment'] = tagline
7 app_data['description'] = description
8- if 'debtags' in app_data and app_data['debtags']:
9+ if 'debtags' in app_data and app_data['debtags']:
10 app_data['debtags'] = json.dumps([get_hw_short_description(x)
11 for x in app_data['debtags']])
12 app_data['application_id'] = app_data.get('id')
13
14=== modified file 'src/webcatalog/templates/webcatalog/application_detail.html'
15--- src/webcatalog/templates/webcatalog/application_detail.html 2012-05-08 17:03:43 +0000
16+++ src/webcatalog/templates/webcatalog/application_detail.html 2012-05-25 08:57:18 +0000
17@@ -14,10 +14,12 @@
18 var reviews_uri = "{% url wc-package-reviews-ajax application.distroseries.code_name application.package_name %}";
19 Y.io(reviews_uri, {
20 on: {
21- complete: function(id, obj){
22- var reviews_html = obj.responseText;
23- var reviews_div = Y.one('#reviews_placeholder');
24- reviews_div.set("innerHTML", reviews_html);
25+ complete: function(id, response){
26+ if (response.status == 200) {
27+ var reviews_html = response.responseText;
28+ var reviews_div = Y.one('#reviews_placeholder');
29+ reviews_div.set("innerHTML", reviews_html);
30+ }
31 }
32 }
33 });
34@@ -26,9 +28,11 @@
35 var recommendations_uri = "{% url wc-package-recommends application.package_name %}";
36 Y.io(recommendations_uri, {
37 on: {
38- complete: function(id, obj){
39- var recommends_html = obj.responseText;
40- recommends_div.set("innerHTML", recommends_html);
41+ complete: function(id, response){
42+ if (response.status == 200) {
43+ var recommends_html = response.responseText;
44+ recommends_div.set("innerHTML", recommends_html);
45+ }
46 }
47 }
48 });
49
50=== modified file 'src/webcatalog/tests/test_views.py'
51--- src/webcatalog/tests/test_views.py 2012-05-23 23:11:26 +0000
52+++ src/webcatalog/tests/test_views.py 2012-05-25 08:57:18 +0000
53@@ -34,6 +34,7 @@
54 from django.test import TestCase
55
56 from mock import patch
57+from piston_mini_client.failhandlers import APIError
58 from rnrclient import ReviewDetails
59
60 from webcatalog.models import (
61@@ -1043,6 +1044,25 @@
62
63 self.assertEqual(200, response.status_code)
64
65+ def test_handles_multiple_apps_for_same_distroseries(self):
66+ ds = self.factory.make_distroseries()
67+ self.factory.make_application(package_name='skype', distroseries=ds)
68+ self.factory.make_application(package_name='skype', distroseries=ds)
69+
70+ response = self.client.get(reverse('wc-package-reviews',
71+ args=[ds.code_name, 'skype']))
72+
73+ self.assertEqual(200, response.status_code)
74+
75+ def test_handles_api_error(self):
76+ app = self.factory.make_application()
77+ self.mock_get_reviews.side_effect = APIError('500', 'error')
78+
79+ response = self.client.get(reverse('wc-package-reviews',
80+ args=[app.distroseries.code_name, app.package_name]))
81+
82+ self.assertEqual(200, response.status_code)
83+
84
85 class ApplicationScreenshotsTestCase(TestCaseWithFactory):
86 def setUp(self):
87
88=== modified file 'src/webcatalog/utilities.py'
89--- src/webcatalog/utilities.py 2012-04-20 19:15:00 +0000
90+++ src/webcatalog/utilities.py 2012-05-25 08:57:18 +0000
91@@ -79,7 +79,7 @@
92 try:
93 fresh_reviews = self.rnr_api.get_reviews(packagename=package_name,
94 distroseries=distroseries, page=page)
95- except ValidationException:
96+ except (ValidationException, APIError):
97 fresh_reviews = []
98 cache.set(key, fresh_reviews, settings.REVIEWS_CACHE_TIMEOUT)
99 return fresh_reviews
100
101=== modified file 'src/webcatalog/views.py'
102--- src/webcatalog/views.py 2012-05-23 22:28:39 +0000
103+++ src/webcatalog/views.py 2012-05-25 08:57:18 +0000
104@@ -37,6 +37,7 @@
105 HttpResponse,
106 )
107 from django.shortcuts import (
108+ get_list_or_404,
109 get_object_or_404,
110 render_to_response,
111 )
112@@ -224,8 +225,15 @@
113
114
115 def application_reviews(request, package_name, distro, ajax=False, page=1):
116- app = get_object_or_404(Application, package_name=package_name,
117+ # XXX 2012-05-25 bug=1002262 michaeln Multiple apps for distroseries.
118+ # It seems that we have a few applications which are present in
119+ # multiple archives for the same distroseries (skype,
120+ # unity-lens-utilities, probably via a myapps PPA as well as extras?).
121+ # Don't break when this happens.
122+ apps = get_list_or_404(Application, package_name=package_name,
123 distroseries__code_name=distro)
124+ app = apps[0]
125+
126 # XXX michaeln 2011-09-15 bug=851662 Better review language options.
127 reviews = WebServices().get_reviews_for_package(package_name,
128 distroseries=distro, page=page)

Subscribers

People subscribed via source and target branches