Merge lp:~mandel/ubuntu-sso-client/fix-broken-tests into lp:ubuntu-sso-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 952
Merged at revision: 945
Proposed branch: lp:~mandel/ubuntu-sso-client/fix-broken-tests
Merge into: lp:ubuntu-sso-client
Diff against target: 426 lines (+212/-36)
9 files modified
ubuntu_sso/main/__init__.py (+1/-0)
ubuntu_sso/main/linux.py (+4/-0)
ubuntu_sso/main/tests/__init__.py (+4/-4)
ubuntu_sso/main/tests/linux.py (+37/-0)
ubuntu_sso/main/tests/test_clients.py (+16/-21)
ubuntu_sso/main/tests/windows.py (+56/-0)
ubuntu_sso/tests/linux.py (+46/-0)
ubuntu_sso/utils/tests/test_ipc.py (+32/-6)
ubuntu_sso/utils/webclient/txweb.py (+16/-5)
To merge this branch: bzr merge lp:~mandel/ubuntu-sso-client/fix-broken-tests
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Abstain
Natalia Bidart (community) Approve
Brian Curtin (community) Approve
Review via email: mp+99770@code.launchpad.net

Commit message

- Fixed all those broken tests on windows related to the dirty reactor left by twisted.pb (LP: #960436).

Description of the change

- Fixed all those broken tests on windows related to the dirty reactor left by twisted.pb (LP: #960436).

This branch depends on lp:~mandel/ubuntuone-dev-tools/tcp-testcases so please ensure that either it has been merged in the ubuntuone-deb-tools trunk or that it is present in your path.

To post a comment you must log in.
Revision history for this message
Brian Curtin (brian.curtin) wrote :

+1
Works IRL on Windows and seems like a reasonable approach.

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Branch looks good.

Could you please apply the following before approving:

* in ubuntu_sso/utils/tests/test_ipc.py you added a global pylint disable when is not needed globally, but only for setUp. So please remove the global disable/enable and just add on *inside* setUp.

* can you please revert the (I think unneeded) changes in these 3 diff lines:

424 + self.context_factory)
427 +
435 +

(that would be removing the added empty lines and restoring the original spacing for self.context_factory indentation).

review: Approve
Revision history for this message
Manuel de la Peña (mandel) :
review: Abstain
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/main/__init__.py'
2--- ubuntu_sso/main/__init__.py 2012-04-09 17:38:24 +0000
3+++ ubuntu_sso/main/__init__.py 2012-04-18 14:38:20 +0000
4@@ -67,6 +67,7 @@
5 from ubuntu_sso.main import linux
6 source = linux
7
8+UbuntuSSOClient = source.UbuntuSSOClient
9 UbuntuSSOProxy = source.UbuntuSSOProxy
10 get_sso_client = source.get_sso_client
11
12
13=== modified file 'ubuntu_sso/main/linux.py'
14--- ubuntu_sso/main/linux.py 2012-04-09 17:38:24 +0000
15+++ ubuntu_sso/main/linux.py 2012-04-18 14:38:20 +0000
16@@ -440,6 +440,10 @@
17 self.sso_login = SSOLoginClient().dbus_iface
18 self.cred_manager = CredentialsManagementClient().dbus_iface
19
20+ def connect(self):
21+ """No need to connect DBus proxy objects."""
22+ return defer.succeed(None)
23+
24 def disconnect(self):
25 """No need to disconnect DBus proxy objects."""
26 return defer.succeed(None)
27
28=== modified file 'ubuntu_sso/main/tests/__init__.py'
29--- ubuntu_sso/main/tests/__init__.py 2012-04-09 17:38:24 +0000
30+++ ubuntu_sso/main/tests/__init__.py 2012-04-18 14:38:20 +0000
31@@ -39,11 +39,11 @@
32 # pylint: disable=C0103
33
34 if sys.platform == 'win32':
35- from ubuntu_sso.utils.tests.test_ipc import BaseIPCTestCase
36- BaseTestCase = BaseIPCTestCase
37+ from ubuntu_sso.main.tests import windows
38+ BaseTestCase = windows.BaseTestCase
39 else:
40- from ubuntuone.devtools.testcases.dbus import DBusTestCase
41- BaseTestCase = DBusTestCase
42+ from ubuntu_sso.main.tests import linux
43+ BaseTestCase = linux.BaseTestCase
44
45 # pylint: enable=C0103
46
47
48=== added file 'ubuntu_sso/main/tests/linux.py'
49--- ubuntu_sso/main/tests/linux.py 1970-01-01 00:00:00 +0000
50+++ ubuntu_sso/main/tests/linux.py 2012-04-18 14:38:20 +0000
51@@ -0,0 +1,37 @@
52+# -*- coding: utf-8 -*-
53+#
54+# Copyright 2012 Canonical Ltd.
55+#
56+# This program is free software: you can redistribute it and/or modify it
57+# under the terms of the GNU General Public License version 3, as published
58+# by the Free Software Foundation.
59+#
60+# This program is distributed in the hope that it will be useful, but
61+# WITHOUT ANY WARRANTY; without even the implied warranties of
62+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
63+# PURPOSE. See the GNU General Public License for more details.
64+#
65+# You should have received a copy of the GNU General Public License along
66+# with this program. If not, see <http://www.gnu.org/licenses/>.
67+
68+"""Utility classes used for testing main on linux."""
69+
70+from twisted.internet import defer
71+
72+from ubuntu_sso import main
73+from ubuntuone.devtools.testcases.dbus import DBusTestCase
74+
75+
76+class BaseTestCase(DBusTestCase):
77+ """The base test case with platform specific support."""
78+
79+ @defer.inlineCallbacks
80+ def setUp(self):
81+ yield super(BaseTestCase, self).setUp()
82+
83+ self.sso_service = main.UbuntuSSOService()
84+ yield self.sso_service.start()
85+ self.addCleanup(self.sso_service.shutdown)
86+
87+ self.sso_client = yield main.get_sso_client()
88+ self.addCleanup(self.sso_client.disconnect)
89
90=== modified file 'ubuntu_sso/main/tests/test_clients.py'
91--- ubuntu_sso/main/tests/test_clients.py 2012-04-09 17:38:24 +0000
92+++ ubuntu_sso/main/tests/test_clients.py 2012-04-18 14:38:20 +0000
93@@ -81,22 +81,17 @@
94
95 @defer.inlineCallbacks
96 def setUp(self):
97+ # avoid putting stuff in the mainloops this MUST be done
98+ # before the parent setUp is called because it will register
99+ # the callbacks
100+ self.patch(main.source, 'timeout_func', lambda *a: None)
101+ self.patch(main.source, 'shutdown_func', lambda *a: None)
102+
103 yield super(AbstractTestCase, self).setUp()
104 self.keyring = FakedKeyring()
105 self.patch(main, 'Keyring', lambda: self.keyring)
106
107- # avoid putting stuff in the mainloops
108- self.patch(main.source, 'timeout_func', lambda *a: None)
109- self.patch(main.source, 'shutdown_func', lambda *a: None)
110-
111- self.sso_service = main.UbuntuSSOService()
112- yield self.sso_service.start()
113- self.addCleanup(self.sso_service.shutdown)
114-
115- self.sso_client = yield main.get_sso_client()
116- self.addCleanup(self.sso_client.disconnect)
117-
118- self.client = self.patchable_backend = None
119+ self.test_client = self.patchable_backend = None
120
121 if self.backend_method is None:
122 self.backend_method = self.method
123@@ -127,19 +122,19 @@
124 d = defer.Deferred()
125
126 cb = lambda *a: d.callback(a)
127- match = self.client.connect_to_signal(success_signal, cb)
128- self.addCleanup(self.client.disconnect_from_signal,
129+ match = self.test_client.connect_to_signal(success_signal, cb)
130+ self.addCleanup(self.test_client.disconnect_from_signal,
131 success_signal, match)
132
133 eb = lambda *a: d.errback(AssertionError(a))
134- match = self.client.connect_to_signal(error_signal, eb)
135- self.addCleanup(self.client.disconnect_from_signal,
136+ match = self.test_client.connect_to_signal(error_signal, eb)
137+ self.addCleanup(self.test_client.disconnect_from_signal,
138 error_signal, match)
139
140 self.patch(self.patchable_backend, self.backend_method,
141 patched_backend_method)
142
143- yield self.client.call_method(self.method, *self.params)
144+ yield self.test_client.call_method(self.method, *self.params)
145
146 result = yield d
147 self.assertEqual(expected_result, result)
148@@ -171,7 +166,7 @@
149 @defer.inlineCallbacks
150 def setUp(self):
151 yield super(SSOLoginProxyTestCase, self).setUp()
152- self.client = self.sso_client.sso_login
153+ self.test_client = self.sso_client.sso_login
154 self.patchable_backend = self.sso_service.sso_login.processor
155
156
157@@ -285,7 +280,7 @@
158 self.credentials = FakedCredentials()
159 self.patch(main, 'Credentials', lambda *a, **kw: self.credentials)
160
161- self.client = self.sso_client.cred_manager
162+ self.test_client = self.sso_client.cred_manager
163 self.patchable_backend = self.credentials
164
165 def _backend_succeed(self, *args, **kwargs):
166@@ -309,7 +304,7 @@
167 """The credentials are asked and returned in a sync call."""
168 d = defer.Deferred()
169
170- self.client.call_method('find_credentials_sync',
171+ self.test_client.call_method('find_credentials_sync',
172 APP_NAME, self.args,
173 reply_handler=d.callback,
174 error_handler=d.errback)
175@@ -324,7 +319,7 @@
176 self.patch(self.credentials, 'find_credentials', self._backend_fail)
177 d = defer.Deferred()
178
179- self.client.call_method('find_credentials_sync',
180+ self.test_client.call_method('find_credentials_sync',
181 APP_NAME, self.args,
182 reply_handler=d.errback,
183 error_handler=d.callback)
184
185=== added file 'ubuntu_sso/main/tests/windows.py'
186--- ubuntu_sso/main/tests/windows.py 1970-01-01 00:00:00 +0000
187+++ ubuntu_sso/main/tests/windows.py 2012-04-18 14:38:20 +0000
188@@ -0,0 +1,56 @@
189+# -*- coding: utf-8 -*-
190+#
191+# Copyright 2012 Canonical Ltd.
192+#
193+# This program is free software: you can redistribute it and/or modify it
194+# under the terms of the GNU General Public License version 3, as published
195+# by the Free Software Foundation.
196+#
197+# This program is distributed in the hope that it will be useful, but
198+# WITHOUT ANY WARRANTY; without even the implied warranties of
199+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
200+# PURPOSE. See the GNU General Public License for more details.
201+#
202+# You should have received a copy of the GNU General Public License along
203+# with this program. If not, see <http://www.gnu.org/licenses/>.
204+
205+"""Utility classes for testing main on windows."""
206+
207+from twisted.internet import defer
208+
209+from ubuntu_sso import main
210+from ubuntu_sso.utils.tests.test_ipc import BaseIPCTestCase
211+
212+
213+class BaseTestCase(BaseIPCTestCase):
214+ """The base test case with platform specific support."""
215+
216+ client_class = main.UbuntuSSOClient
217+ service_class = lambda *a: main.UbuntuSSOProxy(None)
218+
219+ @defer.inlineCallbacks
220+ def setUp(self):
221+
222+ self.sso_service = None
223+
224+ def service_factory(*args):
225+ """Returns the service class."""
226+ self.sso_service = main.UbuntuSSOService()
227+ return main.UbuntuSSOProxy(self.sso_service)
228+
229+ self.service_class = service_factory
230+
231+ yield super(BaseTestCase, self).setUp()
232+
233+ # set the proxy to be the service started by the parent test class
234+ self.sso_service.proxy = self.service
235+
236+ # patch the start of the proxy since the parent setup started it
237+ self.patch(self.sso_service.proxy, 'start',
238+ lambda: defer.succeed(None))
239+
240+ # start the service which will perform all the required operations
241+ # except the proxy start
242+ yield self.sso_service.start()
243+
244+ self.sso_client = self.client
245
246=== added file 'ubuntu_sso/tests/linux.py'
247--- ubuntu_sso/tests/linux.py 1970-01-01 00:00:00 +0000
248+++ ubuntu_sso/tests/linux.py 2012-04-18 14:38:20 +0000
249@@ -0,0 +1,46 @@
250+# -*- coding: utf-8 -*-
251+#
252+# Copyright 2011 Canonical Ltd.
253+#
254+# This program is free software: you can redistribute it and/or modify it
255+# under the terms of the GNU General Public License version 3, as published
256+# by the Free Software Foundation.
257+#
258+# This program is distributed in the hope that it will be useful, but
259+# WITHOUT ANY WARRANTY; without even the implied warranties of
260+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
261+# PURPOSE. See the GNU General Public License for more details.
262+#
263+# You should have received a copy of the GNU General Public License along
264+# with this program. If not, see <http://www.gnu.org/licenses/>.
265+
266+"""Helpful code for testing on linux."""
267+
268+from twisted.internet import defer
269+
270+from ubuntuone.devtools.testcases.dbus import DBusTestCase
271+
272+# pylint complains about callables
273+# pylint: disable=E1102
274+
275+
276+class BaseServiceTestCase(DBusTestCase):
277+ """Set the ipc to a random port for this instance."""
278+
279+ client_class = None # the BaseClient instance
280+ service_class = None # the BaseService instance
281+
282+ @defer.inlineCallbacks
283+ def setUp(self):
284+ yield super(BaseServiceTestCase, self).setUp()
285+ self.service = None
286+ self.client = None
287+ if self.service_class is not None:
288+ self.service = self.service_class()
289+ self.client = self.client_class()
290+
291+ # pylint: disable=E1102
292+ yield self.service.start()
293+ self.addCleanup(self.service.shutdown)
294+ yield self.client.connect()
295+ self.addCleanup(self.client.disconnect)
296
297=== modified file 'ubuntu_sso/utils/tests/test_ipc.py'
298--- ubuntu_sso/utils/tests/test_ipc.py 2012-04-09 17:38:24 +0000
299+++ ubuntu_sso/utils/tests/test_ipc.py 2012-04-18 14:38:20 +0000
300@@ -38,6 +38,7 @@
301 NoSuchMethod,
302 )
303 from ubuntuone.devtools.handlers import MementoHandler
304+from ubuntuone.devtools.testcases.txtcpserver import PbServerTestCase
305
306 from ubuntu_sso.tests import TestCase
307 from ubuntu_sso.utils import ipc
308@@ -185,7 +186,7 @@
309 service_cmdline = DummyService.cmdline
310
311
312-class BaseIPCTestCase(TestCase):
313+class BaseIPCTestCase(PbServerTestCase, TestCase):
314 """Set the ipc to a random port for this instance."""
315
316 timeout = 5
317@@ -201,20 +202,44 @@
318
319 @defer.inlineCallbacks
320 def setUp(self):
321+ # pylint complains about callables
322+ # pylint: disable=E1102
323 yield super(BaseIPCTestCase, self).setUp()
324
325 self.service = None
326 self.client = None
327
328 if self.service_class is not None:
329+
330+ self.service = self.service_class()
331+ self.client = self.client_class()
332+
333+ # patch server connection and client connection to ensure that
334+ # we have clean connections
335+
336+ def server_listen(server_factory, service_name, activation_cmd,
337+ port, reactor=None):
338+ """Connect to the local running service."""
339+ self.listen_server(self.service)
340+ return defer.succeed(self.listener)
341+
342+ self.patch(ipc, 'server_listen', server_listen)
343+
344+ def client_connect(client_factory, service_name,
345+ activation_cmdline, port, reactor=None):
346+ """Connect the local running client."""
347+ self.connect_client()
348+ self.client.factory = self.client_factory
349+ return defer.succeed(self.connector)
350+
351+ self.patch(ipc, 'client_connect', client_connect)
352+
353 # pylint: disable=E1102
354- self.service = self.service_class()
355 yield self.service.start()
356- self.addCleanup(self.service.shutdown)
357-
358- self.client = self.client_class()
359 yield self.client.connect()
360- self.addCleanup(self.client.disconnect)
361+
362+ yield self.client_connected
363+ # pylint: enable=E1102
364
365 @property
366 def remote_service(self):
367@@ -293,6 +318,7 @@
368 """
369 for signal_name, args, kwargs in self.signal_mapping:
370 self.assert_remote_signal(signal_name, *args, **kwargs)
371+# pylint: enable=E1102
372
373
374 class ListenConnectTestCase(BaseIPCTestCase):
375
376=== modified file 'ubuntu_sso/utils/webclient/txweb.py'
377--- ubuntu_sso/utils/webclient/txweb.py 2012-04-12 12:07:46 +0000
378+++ ubuntu_sso/utils/webclient/txweb.py 2012-04-18 14:38:20 +0000
379@@ -56,8 +56,13 @@
380 class WebClient(BaseWebClient):
381 """A simple web client that does not support proxies, yet."""
382
383+ client_factory = None
384+
385 def __init__(self, connector=None, context_factory=None, **kwargs):
386 """Initialize this webclient."""
387+ # delay import, otherwise a default reactor gets installed
388+ from twisted.web import client
389+
390 super(WebClient, self).__init__(**kwargs)
391
392 if connector is None:
393@@ -72,11 +77,17 @@
394 else:
395 self.context_factory = context_factory
396
397+ # decide which client factory to use
398+ if WebClient.client_factory is None:
399+ self.client_factory = client.HTTPClientFactory
400+ else:
401+ self.client_factory = WebClient.client_factory
402+
403 @defer.inlineCallbacks
404 def raw_request(self, method, uri, headers, postdata):
405 """Make a raw http request."""
406 # delay import, otherwise a default reactor gets installed
407- from twisted.web import client, error
408+ from twisted.web import error
409
410 parsed_url = urlparse.urlparse(uri)
411
412@@ -89,10 +100,10 @@
413 else:
414 port = parsed_url.port
415
416- factory = client.HTTPClientFactory(uri, method=method,
417- postdata=postdata,
418- headers=headers,
419- followRedirect=False)
420+ factory = self.client_factory(uri, method=method,
421+ postdata=postdata,
422+ headers=headers,
423+ followRedirect=False)
424 # pylint: disable=E1103
425 if https:
426 self.connector.connectSSL(host, port, factory,

Subscribers

People subscribed via source and target branches