Merge lp:~salgado/lazr.restful/bug-507447 into lp:lazr.restful

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: not available
Proposed branch: lp:~salgado/lazr.restful/bug-507447
Merge into: lp:lazr.restful
Diff against target: 71 lines (+32/-2)
4 files modified
HACKING.txt (+1/-1)
src/lazr/restful/tests/test_utils.py (+29/-0)
src/lazr/restful/tests/test_webservice.py (+0/-1)
src/lazr/restful/utils.py (+2/-0)
To merge this branch: bzr merge lp:~salgado/lazr.restful/bug-507447
Reviewer Review Type Date Requested Status
Henning Eggers (community) code Approve
Review via email: mp+17395@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote :

Fix get_current_browser_request to not raise an AttributeError when
there's no interaction setup

Revision history for this message
Henning Eggers (henninge) wrote :

Thank you for this fix. Only suggestion I'd have is to split up the test into two methods.

test_get_current_browser_request_no_interaction
test_get_current_browser_request

Cheers,
Henning

review: Approve (code)
Revision history for this message
Guilherme Salgado (salgado) wrote :

On Fri, 2010-01-15 at 11:12 +0000, Henning Eggers wrote:
> Review: Approve code
> Thank you for this fix. Only suggestion I'd have is to split up the test into two methods.
>
> test_get_current_browser_request_no_interaction
> test_get_current_browser_request
>

Yeah, that'd be a nice and trivial change, so, done.

Thanks!

lp:~salgado/lazr.restful/bug-507447 updated
98. By Guilherme Salgado

Split the new test into two

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HACKING.txt'
2--- HACKING.txt 2009-03-25 17:56:54 +0000
3+++ HACKING.txt 2010-01-15 14:15:22 +0000
4@@ -22,7 +22,7 @@
5 These are guidelines for hacking on the lazr.restful project. But first,
6 please see the common hacking guidelines at:
7
8- http://dev.launchpad.net/Hacking
9+ https://dev.launchpad.net/HackingLazrLibraries
10
11
12 Getting help
13
14=== added file 'src/lazr/restful/tests/test_utils.py'
15--- src/lazr/restful/tests/test_utils.py 1970-01-01 00:00:00 +0000
16+++ src/lazr/restful/tests/test_utils.py 2010-01-15 14:15:22 +0000
17@@ -0,0 +1,29 @@
18+# Copyright 2010 Canonical Ltd. All rights reserved.
19+
20+"""Test for lazr.restful.utils."""
21+
22+__metaclass__ = type
23+
24+import unittest
25+
26+from zope.publisher.browser import TestRequest
27+from zope.security.management import (
28+ endInteraction, newInteraction, queryInteraction)
29+
30+from lazr.restful.utils import get_current_browser_request
31+
32+
33+class TestUtils(unittest.TestCase):
34+
35+ def test_get_current_browser_request_no_interaction(self):
36+ # When there's no interaction setup, get_current_browser_request()
37+ # returns None.
38+ self.assertEquals(None, queryInteraction())
39+ self.assertEquals(None, get_current_browser_request())
40+
41+ def test_get_current_browser_request(self):
42+ # When there is an interaction, it returns the interaction's request.
43+ request = TestRequest()
44+ newInteraction(request)
45+ self.assertEquals(request, get_current_browser_request())
46+ endInteraction()
47
48=== modified file 'src/lazr/restful/tests/test_webservice.py'
49--- src/lazr/restful/tests/test_webservice.py 2010-01-11 18:27:43 +0000
50+++ src/lazr/restful/tests/test_webservice.py 2010-01-15 14:15:22 +0000
51@@ -28,7 +28,6 @@
52 from lazr.restful.testing.webservice import (
53 create_web_service_request, WebServiceTestPublication)
54 from lazr.restful.testing.tales import test_tales
55-from lazr.restful.utils import get_current_browser_request
56
57
58 def get_resource_factory(model_interface, resource_interface):
59
60=== modified file 'src/lazr/restful/utils.py'
61--- src/lazr/restful/utils.py 2010-01-14 10:00:38 +0000
62+++ src/lazr/restful/utils.py 2010-01-15 14:15:22 +0000
63@@ -223,6 +223,8 @@
64 from zope.security.management import queryInteraction
65 from zope.publisher.interfaces.http import IHTTPApplicationRequest
66 interaction = queryInteraction()
67+ if interaction is None:
68+ return None
69 requests = [
70 participation
71 for participation in interaction.participations

Subscribers

People subscribed via source and target branches