Merge ~twom/launchpad:stats-fix-pageid-doctests into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: bd21869504b72da2a8ccaa2d98c098043581d3ca
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:stats-fix-pageid-doctests
Merge into: launchpad:master
Diff against target: 91 lines (+24/-14)
2 files modified
lib/lp/services/webapp/doc/webapp-publication.txt (+7/-5)
lib/lp/services/webapp/publication.py (+17/-9)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+391193@code.launchpad.net

Commit message

Fix publication doctests for change in pageid generation

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Tom Wardill (twom) :
0bfb200... by Tom Wardill

Remove duplicate import

Revision history for this message
Colin Watson (cjwatson) :
bd21869... by Tom Wardill

Allow callObject to calculate pageid directly

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/services/webapp/doc/webapp-publication.txt b/lib/lp/services/webapp/doc/webapp-publication.txt
2index 046ae2f..ffe6a69 100644
3--- a/lib/lp/services/webapp/doc/webapp-publication.txt
4+++ b/lib/lp/services/webapp/doc/webapp-publication.txt
5@@ -595,8 +595,9 @@ Originally, this variable isn't set.
6
7 >>> 'launchpad.pageid' in request._orig_env
8 False
9+ >>> logout()
10
11-It is set during the callObject() hook. The pageid is made of the
12+It is set during the afterTraversal() hook. The pageid is made of the
13 name of the context class and the view class name.
14
15 >>> class TestView(object):
16@@ -613,10 +614,13 @@ name of the context class and the view class name.
17 ... """Test context object."""
18
19 >>> view = TestView(TestContext(), request)
20- >>> publication.callObject(request, view)
21- u'Result'
22+ >>> publication.beforeTraversal(request)
23+ >>> publication.afterTraversal(request, view)
24 >>> print request._orig_env['launchpad.pageid']
25 TestContext:TestView
26+ >>> from lp.services.webapp.adapter import (
27+ ... clear_request_started, set_request_started)
28+ >>> clear_request_started()
29
30
31 Durations
32@@ -682,8 +686,6 @@ some calls to prepare that code to what handleException expects.)
33 If the exception is raised before we even start the traversal, then
34 there's nothing to store.
35
36- >>> from lp.services.webapp.adapter import (
37- ... clear_request_started, set_request_started)
38 >>> logger.setLevel(logging.CRITICAL)
39 >>> request, publication = get_request_and_publication()
40 >>> request.setPrincipal(auth_utility.unauthenticatedPrincipal())
41diff --git a/lib/lp/services/webapp/publication.py b/lib/lp/services/webapp/publication.py
42index b76eec7..5c3e473 100644
43--- a/lib/lp/services/webapp/publication.py
44+++ b/lib/lp/services/webapp/publication.py
45@@ -427,8 +427,12 @@ class LaunchpadBrowserPublication(
46 request.setInWSGIEnvironment(
47 'launchpad.userid', request.principal.id)
48
49- # pageid is calculated at `afterTraversal`
50- pageid = request._orig_env['launchpad.pageid']
51+ # pageid is calculated at `afterTraversal`, but can be missing
52+ # if callObject is used directly, so either use the one we've got
53+ # or work it out.
54+ pageid = request._orig_env.get(
55+ 'launchpad.pageid',
56+ self._setPageIDInEnvironment(request, ob))
57 # And spit the pageid out to our tracelog.
58 tracelog(request, 'p', pageid)
59
60@@ -552,6 +556,16 @@ class LaunchpadBrowserPublication(
61 request.traversed_objects.append(ob)
62 notify(BeforeTraverseEvent(ob, request))
63
64+ def _setPageIDInEnvironment(self, request, view):
65+ # The view may be security proxied
66+ view = removeSecurityProxy(view)
67+ # It's possible that the view is a bound method.
68+ view = getattr(view, '__self__', view)
69+ context = removeSecurityProxy(getattr(view, 'context', None))
70+ pageid = self.constructPageID(view, context)
71+ request.setInWSGIEnvironment('launchpad.pageid', pageid)
72+ return pageid
73+
74 def afterTraversal(self, request, ob):
75 """See zope.publisher.interfaces.IPublication.
76
77@@ -562,13 +576,7 @@ class LaunchpadBrowserPublication(
78 # Log the URL including vhost information to the ZServer tracelog.
79 tracelog(request, 'u', request.getURL())
80
81- # The view may be security proxied
82- view = removeSecurityProxy(ob)
83- # It's possible that the view is a bound method.
84- view = getattr(view, '__self__', view)
85- context = removeSecurityProxy(getattr(view, 'context', None))
86- pageid = self.constructPageID(view, context)
87- request.setInWSGIEnvironment('launchpad.pageid', pageid)
88+ pageid = self._setPageIDInEnvironment(request, ob)
89
90 assert hasattr(request, '_traversal_start'), (
91 'request._traversal_start, which should have been set by '

Subscribers

People subscribed via source and target branches

to status/vote changes: