Merge lp:~salgado/lazr.restful/fix-exporting-empty-entries into lp:lazr.restful

Proposed by Guilherme Salgado
Status: Merged
Approved by: Leonard Richardson
Approved revision: 138
Merged at revision: 138
Proposed branch: lp:~salgado/lazr.restful/fix-exporting-empty-entries
Merge into: lp:lazr.restful
Diff against target: 107 lines (+30/-10)
4 files modified
src/lazr/restful/declarations.py (+10/-1)
src/lazr/restful/tests/test_declarations.py (+12/-0)
src/lazr/restful/tests/test_webservice.py (+7/-9)
versions.cfg (+1/-0)
To merge this branch: bzr merge lp:~salgado/lazr.restful/fix-exporting-empty-entries
Reviewer Review Type Date Requested Status
Leonard Richardson (community) Approve
Review via email: mp+32239@code.launchpad.net

Description of the change

Fix a bug that Leonard uncovered when running the Launchpad test suite using the latest lazr.restful.

The IEntry adapters generated for interfaces that didn't export any fields/operations didn't include the '_orig_interfaces' attribute, as all adapters should. That was causing EntryResource.redacted_fields to raise an AttributeError for those empty interfaces.

To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/lazr/restful/declarations.py'
--- src/lazr/restful/declarations.py 2010-08-06 15:28:40 +0000
+++ src/lazr/restful/declarations.py 2010-08-10 18:41:18 +0000
@@ -966,6 +966,10 @@
966 # dictionary to adapters_by_version. This dictionary will966 # dictionary to adapters_by_version. This dictionary will
967 # be turned into an adapter class for this version.967 # be turned into an adapter class for this version.
968 adapter_dict = adapters_by_version.setdefault(tags_version, {})968 adapter_dict = adapters_by_version.setdefault(tags_version, {})
969
970 # Set '_orig_interfaces' as early as possible as we want that
971 # attribute (even if empty) on all adapters.
972 orig_interfaces = adapter_dict.setdefault('_orig_interfaces', {})
969973
970 # Figure out the mutator for this version and add it to974 # Figure out the mutator for this version and add it to
971 # this version's adapter class dictionary.975 # this version's adapter class dictionary.
@@ -1000,7 +1004,6 @@
10001004
1001 # A dict mapping field names to the interfaces where they came1005 # A dict mapping field names to the interfaces where they came
1002 # from.1006 # from.
1003 orig_interfaces = adapter_dict.setdefault('_orig_interfaces', {})
1004 orig_interfaces[name] = orig_iface1007 orig_interfaces[name] = orig_iface
10051008
1006 adapters = []1009 adapters = []
@@ -1009,6 +1012,12 @@
1009 raise TypeError('webservice_interface is not an interface.')1012 raise TypeError('webservice_interface is not an interface.')
1010 class_dict = adapters_by_version.get(version, {})1013 class_dict = adapters_by_version.get(version, {})
10111014
1015 # If this interface doesn't export a single field/operation,
1016 # class_dict will be empty, and so we'll add '_orig_interfaces'
1017 # manually as it should be always available, even if empty.
1018 if class_dict == {}:
1019 class_dict['_orig_interfaces'] = {}
1020
1012 class_dict['schema'] = webservice_interface1021 class_dict['schema'] = webservice_interface
1013 class_dict['__doc__'] = webservice_interface.__doc__1022 class_dict['__doc__'] = webservice_interface.__doc__
1014 # The webservice interface class name already includes the version1023 # The webservice interface class name already includes the version
10151024
=== modified file 'src/lazr/restful/tests/test_declarations.py'
--- src/lazr/restful/tests/test_declarations.py 2010-08-04 19:38:18 +0000
+++ src/lazr/restful/tests/test_declarations.py 2010-08-10 18:41:18 +0000
@@ -130,6 +130,18 @@
130 self.assertEqual(adapter.bug_count, 10)130 self.assertEqual(adapter.bug_count, 10)
131 self.assertEqual(adapter.development_branch, self.product._dev_branch)131 self.assertEqual(adapter.development_branch, self.product._dev_branch)
132132
133 def test_redacted_fields_for_empty_entry(self):
134 # An entry which doesn't export any fields/operations will have no
135 # redacted fields.
136 class IEmpty(Interface):
137 export_as_webservice_entry()
138 class Empty:
139 implements(IEmpty)
140 register_test_module('testmod', IEmpty)
141 entry_resource = EntryResource(Empty(), self.beta_request)
142 self.assertEquals({}, entry_resource.entry._orig_interfaces)
143 self.assertEquals([], entry_resource.redacted_fields)
144
133 def test_redacted_fields_with_no_permission_checker(self):145 def test_redacted_fields_with_no_permission_checker(self):
134 # When looking up an entry's redacted_fields, we take into account the146 # When looking up an entry's redacted_fields, we take into account the
135 # interface where the field is defined and adapt the context to that147 # interface where the field is defined and adapt the context to that
136148
=== modified file 'src/lazr/restful/tests/test_webservice.py'
--- src/lazr/restful/tests/test_webservice.py 2010-08-09 19:33:20 +0000
+++ src/lazr/restful/tests/test_webservice.py 2010-08-10 18:41:18 +0000
@@ -9,25 +9,23 @@
9import unittest9import unittest
1010
11from zope.component import getGlobalSiteManager, getUtility11from zope.component import getGlobalSiteManager, getUtility
12from zope.interface import implements, Interface, directlyProvides12from zope.interface import implements, Interface
13from zope.publisher.browser import TestRequest13from zope.publisher.browser import TestRequest
14from zope.schema import Date, Datetime, TextLine14from zope.schema import Date, Datetime, TextLine
15from zope.security.management import (15from zope.security.management import newInteraction, queryInteraction
16 endInteraction, newInteraction, queryInteraction)
17from zope.traversing.browser.interfaces import IAbsoluteURL16from zope.traversing.browser.interfaces import IAbsoluteURL
1817
19from lazr.restful import ResourceOperation18from lazr.restful import ResourceOperation
20from lazr.restful.fields import Reference19from lazr.restful.fields import Reference
21from lazr.restful.interfaces import (20from lazr.restful.interfaces import (
22 ICollection, IEntry, IEntryResource, IResourceGETOperation,21 ICollection, IEntry, IResourceGETOperation, IServiceRootResource,
23 IServiceRootResource, IWebServiceConfiguration,22 IWebServiceConfiguration, IWebServiceClientRequest, IWebServiceVersion)
24 IWebServiceClientRequest, IWebServiceVersion)
25from lazr.restful import EntryResource, ResourceGETOperation23from lazr.restful import EntryResource, ResourceGETOperation
26from lazr.restful.declarations import (exported, export_as_webservice_entry,24from lazr.restful.declarations import (
27 LAZR_WEBSERVICE_NAME)25 exported, export_as_webservice_entry, LAZR_WEBSERVICE_NAME)
28from lazr.restful.testing.webservice import (26from lazr.restful.testing.webservice import (
29 create_web_service_request, IGenericCollection, IGenericEntry,27 create_web_service_request, IGenericCollection, IGenericEntry,
30 WebServiceTestCase, WebServiceTestPublication)28 WebServiceTestCase)
31from lazr.restful.testing.tales import test_tales29from lazr.restful.testing.tales import test_tales
32from lazr.restful.utils import (30from lazr.restful.utils import (
33 get_current_browser_request, get_current_web_service_request,31 get_current_browser_request, get_current_web_service_request,
3432
=== modified file 'versions.cfg'
--- versions.cfg 2010-08-06 15:28:40 +0000
+++ versions.cfg 2010-08-10 18:41:18 +0000
@@ -6,6 +6,7 @@
6[versions]6[versions]
7# Alphabetical, case-SENSITIVE, blank line after this comment7# Alphabetical, case-SENSITIVE, blank line after this comment
88
9distribute = 0.6.14
9Jinja2 = 2.510Jinja2 = 2.5
10Pygments = 1.3.111Pygments = 1.3.1
11RestrictedPython = 3.5.112RestrictedPython = 3.5.1

Subscribers

People subscribed via source and target branches