Merge lp:~allenap/storm/adapt-sqlobject-to-storm into lp:storm

Proposed by James Henstridge
Status: Merged
Merged at revision: not available
Proposed branch: lp:~allenap/storm/adapt-sqlobject-to-storm
Merge into: lp:storm
Diff against target: 185 lines
To merge this branch: bzr merge lp:~allenap/storm/adapt-sqlobject-to-storm
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Approve
James Henstridge Approve
Review via email: mp+4197@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Henstridge (jamesh) wrote :

From the associated bug report, Gavin said:

In Launchpad, because we use both the native Storm API and have lots of older code using the SQLObject shim, we sometimes need to get at the underlying Storm ResultSet from an SQLObjectResultSet. That's possible via so_result_set._result_set, but it's not a public interface. It also doesn't play well in our Zope environment where result sets are always wrapped in security proxies.

For a Zope environment, one proposed solution (from Francis Lacoste) is to create a trusted adapter from ISQLObjectResultSet to IResultSet.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

It looks like a nice idea, but needs testing.

review: Needs Fixing
304. By Gavin Panella

Unit test for sqlobject to storm result set adapter.

305. By Gavin Panella

Move definition of the has_* globals into the tests.zope package.

Revision history for this message
Gavin Panella (allenap) wrote :
Download full text (4.5 KiB)

Hi Gustavo, thanks for looking at this, and James too.

I've added a test now, and refactored the definition of has_zope and
its companions into the tests.zope package rather than in
tests.zope.zstorm.

If this isn't really what you're looking for, let's have a chat on IRC
before I head off into the wild again.

Incremental diff:

=== modified file 'test'
--- test 2009-02-05 10:16:40 +0000
+++ test 2009-03-05 21:50:46 +0000
@@ -66,7 +66,7 @@
             elif relpath == os.path.join("tests", "zope", "README.txt"):
                 # Special case the inclusion of the Zope-dependent
                 # ZStorm doctest.
- from tests.zope.zstorm import has_zope
+ from tests.zope import has_zope
                 if has_zope:
                     doctests.append(relpath)
             elif filename.endswith(".txt"):

=== modified file 'tests/zope/__init__.py'
--- tests/zope/__init__.py 2007-08-05 21:59:54 +0000
+++ tests/zope/__init__.py 2009-03-05 21:50:34 +0000
@@ -17,3 +17,25 @@
 # You should have received a copy of the GNU Lesser General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
+
+__all__ = [
+ 'has_transaction',
+ 'has_zope',
+ 'has_zope_component',
+ ]
+
+try:
+ import transaction
+except ImportError:
+ has_transaction = False
+else:
+ has_transaction = True
+
+try:
+ import zope.component
+except ImportError:
+ has_zope_component = False
+else:
+ has_zope_component = True
+
+has_zope = has_transaction and has_zope_component

=== added file 'tests/zope/adapters.py'
--- tests/zope/adapters.py 1970-01-01 00:00:00 +0000
+++ tests/zope/adapters.py 2009-03-05 21:49:47 +0000
@@ -0,0 +1,57 @@
+#
+# Copyright (c) 2006, 2007 Canonical
+#
+# Written by Gustavo Niemeyer <email address hidden>
+#
+# This file is part of Storm Object Relational Mapper.
+#
+# Storm is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# Storm is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+from tests.helper import TestHelper
+from tests.zope import has_zope_component
+
+
+if has_zope_component:
+ from zope.interface import implements
+ from zope.component import getGlobalSiteManager
+
+ from storm.store import EmptyResultSet
+ from storm.zope.adapters import sqlobject_result_set_to_storm_result_set
+ from storm.zope.interfaces import IResultSet, ISQLObjectResultSet
+
+ class TestSQLObjectResultSet(object):
+ implements(ISQLObjectResultSet)
+ _result_set = EmptyResultSet()
+
+
+class AdaptersTest(TestHelper):
+
+ def is_supported(self):
+ return has_zope_component
+
+ def setUp(self):
+ g...

Read more...

Revision history for this message
James Henstridge (jamesh) wrote :

The added tests look good to me.

I suppose we should look at how to test the ZCML bits in future, but it looks like you're successfully testing everything below that level for your change.

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

Thanks James. Is there anything else I need to do at this point to get this merged, or is this now in your (or Storm devs) court? I guess it is pending an Approve from Gustavo in any case.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Looks good! Thank you!

Revision history for this message
Gustavo Niemeyer (niemeyer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'storm/zope/adapters.py'
2--- storm/zope/adapters.py 1970-01-01 00:00:00 +0000
3+++ storm/zope/adapters.py 2009-03-05 22:20:09 +0000
4@@ -0,0 +1,31 @@
5+#
6+# Copyright (c) 2006, 2007 Canonical
7+#
8+# Written by Gustavo Niemeyer <gustavo@niemeyer.net>
9+#
10+# This file is part of Storm Object Relational Mapper.
11+#
12+# Storm is free software; you can redistribute it and/or modify
13+# it under the terms of the GNU Lesser General Public License as
14+# published by the Free Software Foundation; either version 2.1 of
15+# the License, or (at your option) any later version.
16+#
17+# Storm is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Lesser General Public License for more details.
21+#
22+# You should have received a copy of the GNU Lesser General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+
26+from zope.component import adapter
27+from zope.interface import implementer
28+
29+from storm.zope.interfaces import IResultSet, ISQLObjectResultSet
30+
31+
32+@adapter(ISQLObjectResultSet)
33+@implementer(IResultSet)
34+def sqlobject_result_set_to_storm_result_set(so_result_set):
35+ return so_result_set._result_set
36
37=== modified file 'storm/zope/configure.zcml'
38--- storm/zope/configure.zcml 2008-06-09 09:08:19 +0000
39+++ storm/zope/configure.zcml 2009-03-05 22:20:09 +0000
40@@ -32,4 +32,7 @@
41 <require like_class="storm.references.BoundReferenceSet" />
42 </class>
43
44+ <adapter factory=".adapters.sqlobject_result_set_to_storm_result_set"
45+ trusted="yes" />
46+
47 </configure>
48
49=== modified file 'test'
50--- test 2009-02-05 10:16:40 +0000
51+++ test 2009-03-05 22:20:09 +0000
52@@ -66,7 +66,7 @@
53 elif relpath == os.path.join("tests", "zope", "README.txt"):
54 # Special case the inclusion of the Zope-dependent
55 # ZStorm doctest.
56- from tests.zope.zstorm import has_zope
57+ from tests.zope import has_zope
58 if has_zope:
59 doctests.append(relpath)
60 elif filename.endswith(".txt"):
61
62=== modified file 'tests/zope/__init__.py'
63--- tests/zope/__init__.py 2007-08-05 21:59:54 +0000
64+++ tests/zope/__init__.py 2009-03-05 22:20:09 +0000
65@@ -17,3 +17,25 @@
66 # You should have received a copy of the GNU Lesser General Public License
67 # along with this program. If not, see <http://www.gnu.org/licenses/>.
68 #
69+
70+__all__ = [
71+ 'has_transaction',
72+ 'has_zope',
73+ 'has_zope_component',
74+ ]
75+
76+try:
77+ import transaction
78+except ImportError:
79+ has_transaction = False
80+else:
81+ has_transaction = True
82+
83+try:
84+ import zope.component
85+except ImportError:
86+ has_zope_component = False
87+else:
88+ has_zope_component = True
89+
90+has_zope = has_transaction and has_zope_component
91
92=== added file 'tests/zope/adapters.py'
93--- tests/zope/adapters.py 1970-01-01 00:00:00 +0000
94+++ tests/zope/adapters.py 2009-03-05 22:20:09 +0000
95@@ -0,0 +1,57 @@
96+#
97+# Copyright (c) 2006, 2007 Canonical
98+#
99+# Written by Gustavo Niemeyer <gustavo@niemeyer.net>
100+#
101+# This file is part of Storm Object Relational Mapper.
102+#
103+# Storm is free software; you can redistribute it and/or modify
104+# it under the terms of the GNU Lesser General Public License as
105+# published by the Free Software Foundation; either version 2.1 of
106+# the License, or (at your option) any later version.
107+#
108+# Storm is distributed in the hope that it will be useful,
109+# but WITHOUT ANY WARRANTY; without even the implied warranty of
110+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111+# GNU Lesser General Public License for more details.
112+#
113+# You should have received a copy of the GNU Lesser General Public License
114+# along with this program. If not, see <http://www.gnu.org/licenses/>.
115+#
116+from tests.helper import TestHelper
117+from tests.zope import has_zope_component
118+
119+
120+if has_zope_component:
121+ from zope.interface import implements
122+ from zope.component import getGlobalSiteManager
123+
124+ from storm.store import EmptyResultSet
125+ from storm.zope.adapters import sqlobject_result_set_to_storm_result_set
126+ from storm.zope.interfaces import IResultSet, ISQLObjectResultSet
127+
128+ class TestSQLObjectResultSet(object):
129+ implements(ISQLObjectResultSet)
130+ _result_set = EmptyResultSet()
131+
132+
133+class AdaptersTest(TestHelper):
134+
135+ def is_supported(self):
136+ return has_zope_component
137+
138+ def setUp(self):
139+ getGlobalSiteManager().registerAdapter(
140+ sqlobject_result_set_to_storm_result_set)
141+
142+ def tearDown(self):
143+ getGlobalSiteManager().unregisterAdapter(
144+ sqlobject_result_set_to_storm_result_set)
145+
146+ def test_adapt_sqlobject_to_storm(self):
147+ so_result_set = TestSQLObjectResultSet()
148+ self.assertTrue(
149+ ISQLObjectResultSet.providedBy(so_result_set))
150+ result_set = IResultSet(so_result_set)
151+ self.assertTrue(
152+ IResultSet.providedBy(result_set))
153
154=== modified file 'tests/zope/zstorm.py'
155--- tests/zope/zstorm.py 2008-10-21 09:19:47 +0000
156+++ tests/zope/zstorm.py 2009-03-05 22:20:09 +0000
157@@ -21,25 +21,15 @@
158 import thread, weakref, gc
159
160 from tests.helper import TestHelper
161+from tests.zope import has_transaction, has_zope_component
162
163-try:
164+if has_transaction:
165 import transaction
166-except ImportError:
167- has_transaction = False
168-else:
169- has_transaction = True
170 from storm.zope.interfaces import IZStorm, ZStormError
171 from storm.zope.zstorm import ZStorm, StoreDataManager
172
173-try:
174+if has_zope_component:
175 from zope.component import provideUtility, getUtility
176-except ImportError:
177- has_zope_component = False
178-else:
179- has_zope_component = True
180-
181-has_zope = has_transaction and has_zope_component
182-
183
184 from storm.exceptions import OperationalError
185 from storm.locals import Store

Subscribers

People subscribed via source and target branches

to status/vote changes: