Merge lp:~leonardr/lazr.restful/fix-test-failures into lp:lazr.restful

Proposed by Leonard Richardson
Status: Merged
Merged at revision: 186
Proposed branch: lp:~leonardr/lazr.restful/fix-test-failures
Merge into: lp:lazr.restful
Diff against target: 121 lines (+29/-4)
6 files modified
src/lazr/restful/NEWS.txt (+5/-0)
src/lazr/restful/example/base/configure.zcml (+3/-0)
src/lazr/restful/metazcml.py (+8/-0)
src/lazr/restful/testing/helpers.py (+8/-0)
src/lazr/restful/tests/test_declarations.py (+4/-3)
src/lazr/restful/version.txt (+1/-1)
To merge this branch: bzr merge lp:~leonardr/lazr.restful/fix-test-failures
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+54773@code.launchpad.net

Description of the change

This branch fixes some test failures that started happening when I decoupled the webservice sanity checks from the module registration. Earlier, a web service that failed the sanity check would raise an exception during module registration. Now, the module is registered and the sanity check must be run afterwards. But I didn't change my tests to run the sanity check at all, so they just saw the module being registered and said "wait, that shouldn't have worked".

To fix the failures, I explicitly run webservice_sanity_checks and verify that it throws the expected exception. I also created a tearDown method to wipe lazr.restful's record of things that need to be sanity-checked.

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

Looks good.

review: Approve
188. By Leonard Richardson

Run the sanity checks whenever registering a module.

189. By Leonard Richardson

Have the sanity-checking code itself responsible for clearing out the list of registered operations.

190. By Leonard Richardson

Removed unnecessary code.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restful/NEWS.txt'
2--- src/lazr/restful/NEWS.txt 2011-03-23 16:30:43 +0000
3+++ src/lazr/restful/NEWS.txt 2011-03-24 21:21:48 +0000
4@@ -2,6 +2,11 @@
5 NEWS for lazr.restful
6 =====================
7
8+0.18.1 (2011-03-24)
9+===================
10+
11+Fixed minor test failures.
12+
13 0.18.0 (2011-03-23)
14 ===================
15
16
17=== modified file 'src/lazr/restful/example/base/configure.zcml'
18--- src/lazr/restful/example/base/configure.zcml 2011-02-02 14:15:24 +0000
19+++ src/lazr/restful/example/base/configure.zcml 2011-03-24 21:21:48 +0000
20@@ -6,6 +6,9 @@
21 <webservice:register module="lazr.restful.example.base.interfaces" />
22 <grok:grok package="lazr.restful.example.base" />
23
24+ <subscriber for="zope.processlifetime.IProcessStarting"
25+ handler="lazr.restful.metazcml.webservice_sanity_checks" />
26+
27 <!--Registering these two adapters will cause web_link to show up in
28 representations.-->
29
30
31=== modified file 'src/lazr/restful/metazcml.py'
32--- src/lazr/restful/metazcml.py 2011-03-23 14:38:04 +0000
33+++ src/lazr/restful/metazcml.py 2011-03-24 21:21:48 +0000
34@@ -331,6 +331,9 @@
35 it may not be published in the same version in which it's
36 referenced.
37 """
38+ global REGISTERED_ENTRIES
39+ global REGISTERED_OPERATIONS
40+
41 # Create a mapping of marker interfaces to version names.
42 versions = getUtility(IWebServiceConfiguration).active_versions
43 version_for_marker = { IWebServiceClientRequest: versions[0] }
44@@ -388,6 +391,11 @@
45 _assert_interface_registered_for_version(
46 version, referenced_interface, available_registrations,
47 "named operation %s accepts %s" % (tags['as'], what))
48+ while len(REGISTERED_OPERATIONS) > 0:
49+ REGISTERED_OPERATIONS.pop()
50+ while len(REGISTERED_ENTRIES) > 0:
51+ REGISTERED_ENTRIES.pop()
52+
53
54 def _extract_reference_type(field):
55 """Determine what kind of object the given field is a reference to.
56
57=== modified file 'src/lazr/restful/testing/helpers.py'
58--- src/lazr/restful/testing/helpers.py 2011-03-08 19:59:46 +0000
59+++ src/lazr/restful/testing/helpers.py 2011-03-24 21:21:48 +0000
60@@ -4,7 +4,9 @@
61 from zope.configuration import xmlconfig
62 from zope.interface import implements
63
64+from lazr.restful import metazcml
65 from lazr.restful.interfaces import IWebServiceConfiguration
66+from lazr.restful.metazcml import webservice_sanity_checks
67 from lazr.restful.simple import (
68 Request,
69 RootResource,
70@@ -24,6 +26,11 @@
71
72 def register_test_module(name, *contents):
73 new_module = create_test_module(name, *contents)
74+ # Clear out any registrations from other imports that weren't
75+ # sanity-checked.
76+ metazcml.REGISTERED_OPERATIONS = []
77+ metazcml.REGISTERED_ENTRIES = []
78+
79 try:
80 xmlconfig.string("""
81 <configure
82@@ -33,6 +40,7 @@
83 <webservice:register module="lazr.restful.%s" />
84 </configure>
85 """ % name)
86+ webservice_sanity_checks(None)
87 except Exception, e:
88 del sys.modules['lazr.restful.' + name]
89 raise e
90
91=== modified file 'src/lazr/restful/tests/test_declarations.py'
92--- src/lazr/restful/tests/test_declarations.py 2011-03-18 15:31:53 +0000
93+++ src/lazr/restful/tests/test_declarations.py 2011-03-24 21:21:48 +0000
94@@ -835,8 +835,8 @@
95 this list, so there's no need to specify it again.
96 """
97 exception = self.assertRaises(
98- ConfigurationExecutionError, register_test_module, 'testmod',
99- *(list(classes) + [expect_failure_due_to_interface]))
100+ ValueError, register_test_module,
101+ 'testmod', *(list(classes) + [expect_failure_due_to_interface]))
102 expected_message = (
103 "In version %(version)s, %(reason)s, but version %(version)s "
104 "of the web service does not publish %(interface)s as an entry. "
105@@ -844,7 +844,8 @@
106 version=expect_failure_in_version,
107 reason=expect_failure_for_reason,
108 interface=expect_failure_due_to_interface.__name__))
109- self.assertTrue(expected_message in str(exception))
110+ self.assertEquals(str(exception), expected_message)
111+
112
113 def test_reference_to_unpublished_object_fails(self):
114 self._test_fails_sanity_check(
115
116=== modified file 'src/lazr/restful/version.txt'
117--- src/lazr/restful/version.txt 2011-03-21 14:00:50 +0000
118+++ src/lazr/restful/version.txt 2011-03-24 21:21:48 +0000
119@@ -1,1 +1,1 @@
120-0.18.0
121+0.18.1

Subscribers

People subscribed via source and target branches