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
1=== modified file 'src/lazr/restful/declarations.py'
2--- src/lazr/restful/declarations.py 2010-08-06 15:28:40 +0000
3+++ src/lazr/restful/declarations.py 2010-08-10 18:41:18 +0000
4@@ -966,6 +966,10 @@
5 # dictionary to adapters_by_version. This dictionary will
6 # be turned into an adapter class for this version.
7 adapter_dict = adapters_by_version.setdefault(tags_version, {})
8+
9+ # Set '_orig_interfaces' as early as possible as we want that
10+ # attribute (even if empty) on all adapters.
11+ orig_interfaces = adapter_dict.setdefault('_orig_interfaces', {})
12
13 # Figure out the mutator for this version and add it to
14 # this version's adapter class dictionary.
15@@ -1000,7 +1004,6 @@
16
17 # A dict mapping field names to the interfaces where they came
18 # from.
19- orig_interfaces = adapter_dict.setdefault('_orig_interfaces', {})
20 orig_interfaces[name] = orig_iface
21
22 adapters = []
23@@ -1009,6 +1012,12 @@
24 raise TypeError('webservice_interface is not an interface.')
25 class_dict = adapters_by_version.get(version, {})
26
27+ # If this interface doesn't export a single field/operation,
28+ # class_dict will be empty, and so we'll add '_orig_interfaces'
29+ # manually as it should be always available, even if empty.
30+ if class_dict == {}:
31+ class_dict['_orig_interfaces'] = {}
32+
33 class_dict['schema'] = webservice_interface
34 class_dict['__doc__'] = webservice_interface.__doc__
35 # The webservice interface class name already includes the version
36
37=== modified file 'src/lazr/restful/tests/test_declarations.py'
38--- src/lazr/restful/tests/test_declarations.py 2010-08-04 19:38:18 +0000
39+++ src/lazr/restful/tests/test_declarations.py 2010-08-10 18:41:18 +0000
40@@ -130,6 +130,18 @@
41 self.assertEqual(adapter.bug_count, 10)
42 self.assertEqual(adapter.development_branch, self.product._dev_branch)
43
44+ def test_redacted_fields_for_empty_entry(self):
45+ # An entry which doesn't export any fields/operations will have no
46+ # redacted fields.
47+ class IEmpty(Interface):
48+ export_as_webservice_entry()
49+ class Empty:
50+ implements(IEmpty)
51+ register_test_module('testmod', IEmpty)
52+ entry_resource = EntryResource(Empty(), self.beta_request)
53+ self.assertEquals({}, entry_resource.entry._orig_interfaces)
54+ self.assertEquals([], entry_resource.redacted_fields)
55+
56 def test_redacted_fields_with_no_permission_checker(self):
57 # When looking up an entry's redacted_fields, we take into account the
58 # interface where the field is defined and adapt the context to that
59
60=== modified file 'src/lazr/restful/tests/test_webservice.py'
61--- src/lazr/restful/tests/test_webservice.py 2010-08-09 19:33:20 +0000
62+++ src/lazr/restful/tests/test_webservice.py 2010-08-10 18:41:18 +0000
63@@ -9,25 +9,23 @@
64 import unittest
65
66 from zope.component import getGlobalSiteManager, getUtility
67-from zope.interface import implements, Interface, directlyProvides
68+from zope.interface import implements, Interface
69 from zope.publisher.browser import TestRequest
70 from zope.schema import Date, Datetime, TextLine
71-from zope.security.management import (
72- endInteraction, newInteraction, queryInteraction)
73+from zope.security.management import newInteraction, queryInteraction
74 from zope.traversing.browser.interfaces import IAbsoluteURL
75
76 from lazr.restful import ResourceOperation
77 from lazr.restful.fields import Reference
78 from lazr.restful.interfaces import (
79- ICollection, IEntry, IEntryResource, IResourceGETOperation,
80- IServiceRootResource, IWebServiceConfiguration,
81- IWebServiceClientRequest, IWebServiceVersion)
82+ ICollection, IEntry, IResourceGETOperation, IServiceRootResource,
83+ IWebServiceConfiguration, IWebServiceClientRequest, IWebServiceVersion)
84 from lazr.restful import EntryResource, ResourceGETOperation
85-from lazr.restful.declarations import (exported, export_as_webservice_entry,
86- LAZR_WEBSERVICE_NAME)
87+from lazr.restful.declarations import (
88+ exported, export_as_webservice_entry, LAZR_WEBSERVICE_NAME)
89 from lazr.restful.testing.webservice import (
90 create_web_service_request, IGenericCollection, IGenericEntry,
91- WebServiceTestCase, WebServiceTestPublication)
92+ WebServiceTestCase)
93 from lazr.restful.testing.tales import test_tales
94 from lazr.restful.utils import (
95 get_current_browser_request, get_current_web_service_request,
96
97=== modified file 'versions.cfg'
98--- versions.cfg 2010-08-06 15:28:40 +0000
99+++ versions.cfg 2010-08-10 18:41:18 +0000
100@@ -6,6 +6,7 @@
101 [versions]
102 # Alphabetical, case-SENSITIVE, blank line after this comment
103
104+distribute = 0.6.14
105 Jinja2 = 2.5
106 Pygments = 1.3.1
107 RestrictedPython = 3.5.1

Subscribers

People subscribed via source and target branches