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
=== modified file 'src/lazr/restful/NEWS.txt'
--- src/lazr/restful/NEWS.txt 2011-03-23 16:30:43 +0000
+++ src/lazr/restful/NEWS.txt 2011-03-24 21:21:48 +0000
@@ -2,6 +2,11 @@
2NEWS for lazr.restful2NEWS for lazr.restful
3=====================3=====================
44
50.18.1 (2011-03-24)
6===================
7
8Fixed minor test failures.
9
50.18.0 (2011-03-23)100.18.0 (2011-03-23)
6===================11===================
712
813
=== modified file 'src/lazr/restful/example/base/configure.zcml'
--- src/lazr/restful/example/base/configure.zcml 2011-02-02 14:15:24 +0000
+++ src/lazr/restful/example/base/configure.zcml 2011-03-24 21:21:48 +0000
@@ -6,6 +6,9 @@
6 <webservice:register module="lazr.restful.example.base.interfaces" />6 <webservice:register module="lazr.restful.example.base.interfaces" />
7 <grok:grok package="lazr.restful.example.base" />7 <grok:grok package="lazr.restful.example.base" />
88
9 <subscriber for="zope.processlifetime.IProcessStarting"
10 handler="lazr.restful.metazcml.webservice_sanity_checks" />
11
9 <!--Registering these two adapters will cause web_link to show up in12 <!--Registering these two adapters will cause web_link to show up in
10 representations.-->13 representations.-->
1114
1215
=== modified file 'src/lazr/restful/metazcml.py'
--- src/lazr/restful/metazcml.py 2011-03-23 14:38:04 +0000
+++ src/lazr/restful/metazcml.py 2011-03-24 21:21:48 +0000
@@ -331,6 +331,9 @@
331 it may not be published in the same version in which it's331 it may not be published in the same version in which it's
332 referenced.332 referenced.
333 """333 """
334 global REGISTERED_ENTRIES
335 global REGISTERED_OPERATIONS
336
334 # Create a mapping of marker interfaces to version names.337 # Create a mapping of marker interfaces to version names.
335 versions = getUtility(IWebServiceConfiguration).active_versions338 versions = getUtility(IWebServiceConfiguration).active_versions
336 version_for_marker = { IWebServiceClientRequest: versions[0] }339 version_for_marker = { IWebServiceClientRequest: versions[0] }
@@ -388,6 +391,11 @@
388 _assert_interface_registered_for_version(391 _assert_interface_registered_for_version(
389 version, referenced_interface, available_registrations,392 version, referenced_interface, available_registrations,
390 "named operation %s accepts %s" % (tags['as'], what))393 "named operation %s accepts %s" % (tags['as'], what))
394 while len(REGISTERED_OPERATIONS) > 0:
395 REGISTERED_OPERATIONS.pop()
396 while len(REGISTERED_ENTRIES) > 0:
397 REGISTERED_ENTRIES.pop()
398
391399
392def _extract_reference_type(field):400def _extract_reference_type(field):
393 """Determine what kind of object the given field is a reference to.401 """Determine what kind of object the given field is a reference to.
394402
=== modified file 'src/lazr/restful/testing/helpers.py'
--- src/lazr/restful/testing/helpers.py 2011-03-08 19:59:46 +0000
+++ src/lazr/restful/testing/helpers.py 2011-03-24 21:21:48 +0000
@@ -4,7 +4,9 @@
4from zope.configuration import xmlconfig4from zope.configuration import xmlconfig
5from zope.interface import implements5from zope.interface import implements
66
7from lazr.restful import metazcml
7from lazr.restful.interfaces import IWebServiceConfiguration8from lazr.restful.interfaces import IWebServiceConfiguration
9from lazr.restful.metazcml import webservice_sanity_checks
8from lazr.restful.simple import (10from lazr.restful.simple import (
9 Request,11 Request,
10 RootResource,12 RootResource,
@@ -24,6 +26,11 @@
2426
25def register_test_module(name, *contents):27def register_test_module(name, *contents):
26 new_module = create_test_module(name, *contents)28 new_module = create_test_module(name, *contents)
29 # Clear out any registrations from other imports that weren't
30 # sanity-checked.
31 metazcml.REGISTERED_OPERATIONS = []
32 metazcml.REGISTERED_ENTRIES = []
33
27 try:34 try:
28 xmlconfig.string("""35 xmlconfig.string("""
29 <configure36 <configure
@@ -33,6 +40,7 @@
33 <webservice:register module="lazr.restful.%s" />40 <webservice:register module="lazr.restful.%s" />
34 </configure>41 </configure>
35 """ % name)42 """ % name)
43 webservice_sanity_checks(None)
36 except Exception, e:44 except Exception, e:
37 del sys.modules['lazr.restful.' + name]45 del sys.modules['lazr.restful.' + name]
38 raise e46 raise e
3947
=== modified file 'src/lazr/restful/tests/test_declarations.py'
--- src/lazr/restful/tests/test_declarations.py 2011-03-18 15:31:53 +0000
+++ src/lazr/restful/tests/test_declarations.py 2011-03-24 21:21:48 +0000
@@ -835,8 +835,8 @@
835 this list, so there's no need to specify it again.835 this list, so there's no need to specify it again.
836 """836 """
837 exception = self.assertRaises(837 exception = self.assertRaises(
838 ConfigurationExecutionError, register_test_module, 'testmod',838 ValueError, register_test_module,
839 *(list(classes) + [expect_failure_due_to_interface]))839 'testmod', *(list(classes) + [expect_failure_due_to_interface]))
840 expected_message = (840 expected_message = (
841 "In version %(version)s, %(reason)s, but version %(version)s "841 "In version %(version)s, %(reason)s, but version %(version)s "
842 "of the web service does not publish %(interface)s as an entry. "842 "of the web service does not publish %(interface)s as an entry. "
@@ -844,7 +844,8 @@
844 version=expect_failure_in_version,844 version=expect_failure_in_version,
845 reason=expect_failure_for_reason,845 reason=expect_failure_for_reason,
846 interface=expect_failure_due_to_interface.__name__))846 interface=expect_failure_due_to_interface.__name__))
847 self.assertTrue(expected_message in str(exception))847 self.assertEquals(str(exception), expected_message)
848
848849
849 def test_reference_to_unpublished_object_fails(self):850 def test_reference_to_unpublished_object_fails(self):
850 self._test_fails_sanity_check(851 self._test_fails_sanity_check(
851852
=== modified file 'src/lazr/restful/version.txt'
--- src/lazr/restful/version.txt 2011-03-21 14:00:50 +0000
+++ src/lazr/restful/version.txt 2011-03-24 21:21:48 +0000
@@ -1,1 +1,1 @@
10.18.010.18.1

Subscribers

People subscribed via source and target branches