Merge lp:~benji/launchpad/bug-621090 into lp:launchpad

Proposed by Benji York on 2010-11-09
Status: Merged
Approved by: Māris Fogels on 2010-11-09
Approved revision: no longer in the source branch.
Merged at revision: 11896
Proposed branch: lp:~benji/launchpad/bug-621090
Merge into: lp:launchpad
Diff against target: 83 lines (+36/-2)
4 files modified
lib/lp/bugs/browser/bugsubscription.py (+1/-0)
lib/lp/bugs/browser/tests/test_bugsubscription_views.py (+24/-2)
lib/lp/code/browser/branch.py (+1/-0)
lib/lp/code/browser/tests/test_branch.py (+10/-0)
To merge this branch: bzr merge lp:~benji/launchpad/bug-621090
Reviewer Review Type Date Requested Status
Māris Fogels (community) 2010-11-09 Approve on 2010-11-09
Review via email: mp+40474@code.launchpad.net

Commit Message

[r=mars][ui=none][bug=621090] fix content type on two JSON views

Description of the Change

There are some views that generate JSON but don't explicitly set the
content type which forces the publisher to guess, and being
plain-text-esque, it guesses text/plain (bug 621090).

Besides offending the sensibilities of the more genteel among us, this
causes the site search to index the JSON documents instead of ignoring
them (e.g., the more than half a million search results for
https://launchpad.net/+search?field.text=%2Bbug-portlet-subscribers-ids).

This branch fixes the content type for the view given in bug 621090 as
well as another instance of this class of bugs. I tried to find -- by
various means -- other instances but to no avail.

The following lint was fixed as well:

./lib/lp/bugs/browser/tests/test_bugsubscription_views.py
     170: E501 line too long (82 characters)
     170: Line exceeds 78 characters.

To post a comment you must log in.
Māris Fogels (mars) wrote :

Hi Benji,

This looks good. It looks like you spelled the header as 'content-type' in one place, and 'Content-Type' in the other. With that fix, r=mars.

review: Approve
Benji York (benji) wrote :

On Tue, Nov 9, 2010 at 2:39 PM, Māris Fogels <email address hidden> wrote:
> This looks good.  It looks like you spelled the header as
> 'content-type' in one place, and 'Content-Type' in the other.  With
> that fix, r=mars.

Indeed. Fixed. Thanks.
--
Benji York

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/browser/bugsubscription.py'
2--- lib/lp/bugs/browser/bugsubscription.py 2010-11-05 16:39:57 +0000
3+++ lib/lp/bugs/browser/bugsubscription.py 2010-11-09 19:44:48 +0000
4@@ -500,6 +500,7 @@
5
6 def render(self):
7 """Override the default render() to return only JSON."""
8+ self.request.response.setHeader('content-type', 'application/json')
9 return self.subscriber_ids_js
10
11
12
13=== modified file 'lib/lp/bugs/browser/tests/test_bugsubscription_views.py'
14--- lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2010-11-03 13:56:02 +0000
15+++ lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2010-11-09 19:44:48 +0000
16@@ -8,7 +8,10 @@
17 from canonical.launchpad.ftests import LaunchpadFormHarness
18 from canonical.testing.layers import LaunchpadFunctionalLayer
19
20-from lp.bugs.browser.bugsubscription import BugSubscriptionSubscribeSelfView
21+from lp.bugs.browser.bugsubscription import (
22+ BugPortletSubcribersIds,
23+ BugSubscriptionSubscribeSelfView,
24+ )
25 from lp.registry.enum import BugNotificationLevel
26 from lp.testing import (
27 feature_flags,
28@@ -164,4 +167,23 @@
29 BugNotificationLevel.METADATA,
30 default_notification_level_value,
31 "Default value for bug_notification_level should be "
32- "METADATA, is actually %s" % default_notification_level_value)
33+ "METADATA, is actually %s"
34+ % default_notification_level_value)
35+
36+
37+class BugPortletSubcribersIdsTests(TestCaseWithFactory):
38+
39+ layer = LaunchpadFunctionalLayer
40+
41+ def test_content_type(self):
42+ bug = self.factory.makeBug()
43+
44+ person = self.factory.makePerson()
45+ with person_logged_in(person):
46+ harness = LaunchpadFormHarness(
47+ bug.default_bugtask, BugPortletSubcribersIds)
48+ harness.view.render()
49+
50+ self.assertEqual(
51+ harness.request.response.getHeader('content-type'),
52+ 'application/json')
53
54=== modified file 'lib/lp/code/browser/branch.py'
55--- lib/lp/code/browser/branch.py 2010-11-04 06:36:29 +0000
56+++ lib/lp/code/browser/branch.py 2010-11-09 19:44:48 +0000
57@@ -1500,4 +1500,5 @@
58 values['last_commit'] = adapter.approximatedate()
59 values.update(self._commitCounts())
60
61+ self.request.response.setHeader('content-type', 'application/json')
62 return simplejson.dumps(values)
63
64=== modified file 'lib/lp/code/browser/tests/test_branch.py'
65--- lib/lp/code/browser/tests/test_branch.py 2010-10-26 15:47:24 +0000
66+++ lib/lp/code/browser/tests/test_branch.py 2010-11-09 19:44:48 +0000
67@@ -449,6 +449,16 @@
68 self.assertEqual(0, json['count'])
69 self.assertEqual('empty branch', json['last_commit'])
70
71+ def test_content_type(self):
72+ # The response has the correct (JSON) content type...
73+ branch = self.factory.makeAnyBranch()
74+ request = LaunchpadTestRequest()
75+ view = BranchSparkView(branch, request)
76+ view.render()
77+ self.assertEqual(
78+ request.response.getHeader('content-type'),
79+ 'application/json')
80+
81 def test_old_commits(self):
82 # A branch with a commit older than the COMMIT_DAYS will create a list
83 # of commits that all say zero.