launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #01889
[Merge] lp:~benji/launchpad/bug-621090 into lp:launchpad/devel
Benji York has proposed merging lp:~benji/launchpad/bug-621090 into lp:launchpad/devel.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
#621090 JSON objects are served as text/plain
https://bugs.launchpad.net/bugs/621090
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.
--
https://code.launchpad.net/~benji/launchpad/bug-621090/+merge/40474
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~benji/launchpad/bug-621090 into lp:launchpad/devel.
=== modified file 'lib/lp/bugs/browser/bugsubscription.py'
--- lib/lp/bugs/browser/bugsubscription.py 2010-11-05 16:39:57 +0000
+++ lib/lp/bugs/browser/bugsubscription.py 2010-11-09 19:16:09 +0000
@@ -500,6 +500,7 @@
def render(self):
"""Override the default render() to return only JSON."""
+ self.request.response.setHeader('Content-type', 'application/json')
return self.subscriber_ids_js
=== modified file 'lib/lp/bugs/browser/tests/test_bugsubscription_views.py'
--- lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2010-11-03 13:56:02 +0000
+++ lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2010-11-09 19:16:09 +0000
@@ -8,7 +8,10 @@
from canonical.launchpad.ftests import LaunchpadFormHarness
from canonical.testing.layers import LaunchpadFunctionalLayer
-from lp.bugs.browser.bugsubscription import BugSubscriptionSubscribeSelfView
+from lp.bugs.browser.bugsubscription import (
+ BugPortletSubcribersIds,
+ BugSubscriptionSubscribeSelfView,
+ )
from lp.registry.enum import BugNotificationLevel
from lp.testing import (
feature_flags,
@@ -165,3 +168,21 @@
default_notification_level_value,
"Default value for bug_notification_level should be "
"METADATA, is actually %s" % default_notification_level_value)
+
+
+class BugPortletSubcribersIdsTests(TestCaseWithFactory):
+
+ layer = LaunchpadFunctionalLayer
+
+ def test_content_type(self):
+ bug = self.factory.makeBug()
+
+ person = self.factory.makePerson()
+ with person_logged_in(person):
+ harness = LaunchpadFormHarness(
+ bug.default_bugtask, BugPortletSubcribersIds)
+ harness.view.render()
+
+ self.assertEqual(
+ harness.request.response.getHeader('content-type'),
+ 'application/json')
=== modified file 'lib/lp/code/browser/branch.py'
--- lib/lp/code/browser/branch.py 2010-11-04 06:36:29 +0000
+++ lib/lp/code/browser/branch.py 2010-11-09 19:16:09 +0000
@@ -1500,4 +1500,5 @@
values['last_commit'] = adapter.approximatedate()
values.update(self._commitCounts())
+ self.request.response.setHeader('content-type', 'application/json')
return simplejson.dumps(values)
=== modified file 'lib/lp/code/browser/tests/test_branch.py'
--- lib/lp/code/browser/tests/test_branch.py 2010-10-26 15:47:24 +0000
+++ lib/lp/code/browser/tests/test_branch.py 2010-11-09 19:16:09 +0000
@@ -449,6 +449,16 @@
self.assertEqual(0, json['count'])
self.assertEqual('empty branch', json['last_commit'])
+ def test_content_type(self):
+ # The response has the correct (JSON) content type...
+ branch = self.factory.makeAnyBranch()
+ request = LaunchpadTestRequest()
+ view = BranchSparkView(branch, request)
+ view.render()
+ self.assertEqual(
+ request.response.getHeader('content-type'),
+ 'application/json')
+
def test_old_commits(self):
# A branch with a commit older than the COMMIT_DAYS will create a list
# of commits that all say zero.