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
diff --git a/lib/lp/services/webapp/doc/webapp-publication.txt b/lib/lp/services/webapp/doc/webapp-publication.txt
index 046ae2f..ffe6a69 100644
--- a/lib/lp/services/webapp/doc/webapp-publication.txt
+++ b/lib/lp/services/webapp/doc/webapp-publication.txt
@@ -595,8 +595,9 @@ Originally, this variable isn't set.
595595
596 >>> 'launchpad.pageid' in request._orig_env596 >>> 'launchpad.pageid' in request._orig_env
597 False597 False
598 >>> logout()
598599
599It is set during the callObject() hook. The pageid is made of the600It is set during the afterTraversal() hook. The pageid is made of the
600name of the context class and the view class name.601name of the context class and the view class name.
601602
602 >>> class TestView(object):603 >>> class TestView(object):
@@ -613,10 +614,13 @@ name of the context class and the view class name.
613 ... """Test context object."""614 ... """Test context object."""
614615
615 >>> view = TestView(TestContext(), request)616 >>> view = TestView(TestContext(), request)
616 >>> publication.callObject(request, view)617 >>> publication.beforeTraversal(request)
617 u'Result'618 >>> publication.afterTraversal(request, view)
618 >>> print request._orig_env['launchpad.pageid']619 >>> print request._orig_env['launchpad.pageid']
619 TestContext:TestView620 TestContext:TestView
621 >>> from lp.services.webapp.adapter import (
622 ... clear_request_started, set_request_started)
623 >>> clear_request_started()
620624
621625
622Durations626Durations
@@ -682,8 +686,6 @@ some calls to prepare that code to what handleException expects.)
682If the exception is raised before we even start the traversal, then686If the exception is raised before we even start the traversal, then
683there's nothing to store.687there's nothing to store.
684688
685 >>> from lp.services.webapp.adapter import (
686 ... clear_request_started, set_request_started)
687 >>> logger.setLevel(logging.CRITICAL)689 >>> logger.setLevel(logging.CRITICAL)
688 >>> request, publication = get_request_and_publication()690 >>> request, publication = get_request_and_publication()
689 >>> request.setPrincipal(auth_utility.unauthenticatedPrincipal())691 >>> request.setPrincipal(auth_utility.unauthenticatedPrincipal())
diff --git a/lib/lp/services/webapp/publication.py b/lib/lp/services/webapp/publication.py
index b76eec7..5c3e473 100644
--- a/lib/lp/services/webapp/publication.py
+++ b/lib/lp/services/webapp/publication.py
@@ -427,8 +427,12 @@ class LaunchpadBrowserPublication(
427 request.setInWSGIEnvironment(427 request.setInWSGIEnvironment(
428 'launchpad.userid', request.principal.id)428 'launchpad.userid', request.principal.id)
429429
430 # pageid is calculated at `afterTraversal`430 # pageid is calculated at `afterTraversal`, but can be missing
431 pageid = request._orig_env['launchpad.pageid']431 # if callObject is used directly, so either use the one we've got
432 # or work it out.
433 pageid = request._orig_env.get(
434 'launchpad.pageid',
435 self._setPageIDInEnvironment(request, ob))
432 # And spit the pageid out to our tracelog.436 # And spit the pageid out to our tracelog.
433 tracelog(request, 'p', pageid)437 tracelog(request, 'p', pageid)
434438
@@ -552,6 +556,16 @@ class LaunchpadBrowserPublication(
552 request.traversed_objects.append(ob)556 request.traversed_objects.append(ob)
553 notify(BeforeTraverseEvent(ob, request))557 notify(BeforeTraverseEvent(ob, request))
554558
559 def _setPageIDInEnvironment(self, request, view):
560 # The view may be security proxied
561 view = removeSecurityProxy(view)
562 # It's possible that the view is a bound method.
563 view = getattr(view, '__self__', view)
564 context = removeSecurityProxy(getattr(view, 'context', None))
565 pageid = self.constructPageID(view, context)
566 request.setInWSGIEnvironment('launchpad.pageid', pageid)
567 return pageid
568
555 def afterTraversal(self, request, ob):569 def afterTraversal(self, request, ob):
556 """See zope.publisher.interfaces.IPublication.570 """See zope.publisher.interfaces.IPublication.
557571
@@ -562,13 +576,7 @@ class LaunchpadBrowserPublication(
562 # Log the URL including vhost information to the ZServer tracelog.576 # Log the URL including vhost information to the ZServer tracelog.
563 tracelog(request, 'u', request.getURL())577 tracelog(request, 'u', request.getURL())
564578
565 # The view may be security proxied579 pageid = self._setPageIDInEnvironment(request, ob)
566 view = removeSecurityProxy(ob)
567 # It's possible that the view is a bound method.
568 view = getattr(view, '__self__', view)
569 context = removeSecurityProxy(getattr(view, 'context', None))
570 pageid = self.constructPageID(view, context)
571 request.setInWSGIEnvironment('launchpad.pageid', pageid)
572580
573 assert hasattr(request, '_traversal_start'), (581 assert hasattr(request, '_traversal_start'), (
574 'request._traversal_start, which should have been set by '582 'request._traversal_start, which should have been set by '

Subscribers

People subscribed via source and target branches

to status/vote changes: