Merge lp:~alecu/ubuntuone-client/fix-cmt-usage into lp:ubuntuone-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 1058
Merged at revision: 1013
Proposed branch: lp:~alecu/ubuntuone-client/fix-cmt-usage
Merge into: lp:ubuntuone-client
Diff against target: 257 lines (+136/-42)
3 files modified
run-tests.bat (+2/-2)
tests/platform/windows/test_ipc.py (+123/-1)
ubuntuone/platform/windows/ipc.py (+11/-39)
To merge this branch: bzr merge lp:~alecu/ubuntuone-client/fix-cmt-usage
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+65438@code.launchpad.net

Commit message

On Windows, use the CredentialsManagementTool in the proper way (LP: #799958)

Description of the change

On Windows, use the CredentialsManagementTool in the proper way (LP: #799958)

To post a comment you must log in.
Revision history for this message
Alejandro J. Cura (alecu) wrote :

To run just the tests for this branch, use a command line similar to the following:

E:\ubuntuone-client\fix-cmt-usage>python c:\python27\scripts\u1trial --reactor=txnp tests\platform\windows\test_ipc.py

Revision history for this message
Manuel de la Peña (mandel) wrote :

Grande!

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

* As far as I see, there is no need to have an __init__ method for FakeIPCRoot.

* I think this code needs to be deleted since is not used:

    def on_credentials_found_cb(self, app_name, creds, *args, **kwargs):

    def on_credentials_error_cb(self, app_name, *args, **kwargs):

* The rest looks great!

review: Needs Fixing
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Hi, thanks for the review!

> * As far as I see, there is no need to have an __init__ method for
> FakeIPCRoot.

The empty method on FakeIPCRoot is needed in order to override the default constructor. I've added a comment to clarify this.

> > * I think this code needs to be deleted since is not used:
>
> def on_credentials_found_cb(self, app_name, creds, *args, **kwargs):
>
> def on_credentials_error_cb(self, app_name, *args, **kwargs):

This is now fixed and pushed.

> * The rest looks great!

thanks!

Revision history for this message
Natalia Bidart (nataliabidart) :
review: Approve
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.

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

The attempt to merge lp:~alecu/ubuntuone-client/fix-cmt-usage into lp:ubuntuone-client failed. Below is the output from the failed tests.

/usr/bin/gnome-autogen.sh
checking for autoconf >= 2.53...
  testing autoconf2.50... not found.
  testing autoconf... found 2.67
checking for automake >= 1.10...
  testing automake-1.11... found 1.11.1
checking for libtool >= 1.5...
  testing libtoolize... found 2.2.6b
checking for intltool >= 0.30...
  testing intltoolize... found 0.41.1
checking for pkg-config >= 0.14.0...
  testing pkg-config... found 0.25
checking for gtk-doc >= 1.0...
  testing gtkdocize... found 1.17
Checking for required M4 macros...
Checking for forbidden M4 macros...
Processing ./configure.ac
Running libtoolize...
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
Running intltoolize...
Running gtkdocize...
Running aclocal-1.11...
Running autoconf...
Running autoheader...
Running automake-1.11...
Running ./configure --enable-gtk-doc --enable-debug ...
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for library containing strerror... none required
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking dependency style of gcc... (cached) gcc3
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent librarie...

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 'run-tests.bat'
2--- run-tests.bat 2011-04-14 11:32:42 +0000
3+++ run-tests.bat 2011-06-22 15:39:50 +0000
4@@ -52,7 +52,7 @@
5 ECHO Python found, executing the tests...
6 COPY windows\clientdefs.py ubuntuone\clientdefs.py
7 :: execute the tests with a number of ignored linux only modules
8-"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1trial" -c tests -p tests\platform\linux
9+"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1trial" --reactor=txnp -c tests -p tests\platform\linux %1
10 "%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1lint"
11 :: test for style if we can, if pep8 is not present, move to the end
12 IF EXIST "%PYTHONPATH%Scripts\pep8.exe"
13@@ -62,4 +62,4 @@
14 :: Delete the temp folders
15 RMDIR /s /q _trial_temp
16 RMDIR /s /q .coverage
17-:END
18\ No newline at end of file
19+:END
20
21=== modified file 'tests/platform/windows/test_ipc.py'
22--- tests/platform/windows/test_ipc.py 2011-06-15 15:40:17 +0000
23+++ tests/platform/windows/test_ipc.py 2011-06-22 15:39:50 +0000
24@@ -1,6 +1,7 @@
25 # -*- coding: utf-8 -*-
26 #
27-# Author: Manuel de la Pena<manuel@canonical.com>
28+# Authors: Manuel de la Pena <manuel@canonical.com>
29+# Alejandro J. Cura <alecu@canonical.com>
30 #
31 # Copyright 2011 Canonical Ltd.
32 #
33@@ -27,12 +28,14 @@
34 Root,
35 RemoteReference)
36
37+from ubuntuone.platform.windows import ipc
38 from ubuntuone.platform.windows.ipc import (
39 AllEventsSender,
40 Config,
41 Events,
42 Folders,
43 FileSystem,
44+ IPCInterface,
45 IPCRoot,
46 PublicFiles,
47 Shares,
48@@ -3172,3 +3175,122 @@
49 d.addCallback(test_execution)
50 # pylint: enable=E1101
51 return d
52+
53+
54+class FakeIPCRoot(object, ipc.Root):
55+ """A Fake IPC Root."""
56+
57+ def __init__(self, *args, **kwargs):
58+ """Initialize this fake instance."""
59+ # This empty method is needed to override the default constructor
60+
61+
62+class RandomException(Exception):
63+ """A random exception."""
64+
65+
66+class FakeCredentialsManagementTool(object):
67+ """A Fake CredentialsManagementTool."""
68+
69+ fake_credentials = {
70+ "consumer_key": "sample consumer key",
71+ "consumer_secret": "sample consumer secret",
72+ "token": "sample token",
73+ "token_secret": "sample token secret",
74+ }
75+ should_fail = False
76+
77+ def find_credentials(self):
78+ """Find the credentials."""
79+ if self.should_fail:
80+ return defer.fail(RandomException())
81+ return defer.succeed(self.fake_credentials)
82+
83+ def register(self, *args):
84+ """Register a new user."""
85+ if self.should_fail:
86+ return defer.fail(RandomException())
87+ return defer.succeed(self.fake_credentials)
88+
89+
90+class FakeCredentialsManagementToolFails(FakeCredentialsManagementTool):
91+ """A Fake CredentialsManagementTool that consistently fails."""
92+
93+ should_fail = True
94+
95+
96+class FakeEventQueue(object):
97+ """A fake event queue."""
98+
99+ def __init__(self):
100+ """Initialize this fake instance."""
101+ self.pushed_events = []
102+
103+ def push(self, event_name, **kwargs):
104+ """Store the pushed event."""
105+ event = (event_name, kwargs)
106+ self.pushed_events.append(event)
107+
108+
109+class FakeMain(object):
110+ """A fake main."""
111+
112+ def __init__(self):
113+ """Initialize this fake instance."""
114+ self.event_q = FakeEventQueue()
115+
116+
117+class IPCInterfaceTestCaseBase(TestCase):
118+ """Base tests for IPCInterface."""
119+
120+ cmt_class = None
121+
122+ def setUp(self):
123+ """Initialize this test instance."""
124+ if self.cmt_class is None: return
125+ self.patch(ipc, "CredentialsManagementTool", self.cmt_class)
126+ self.patch(ipc, "GetUserNameEx", lambda x: "sample_username")
127+ self.patch(ipc, "IPCRoot", FakeIPCRoot)
128+ no_op = lambda *args: None
129+ self.patch(ipc.reactor, "listenPipe", no_op)
130+ self.patch(IPCInterface, "network_connected", no_op)
131+ self.ipc = IPCInterface(FakeMain())
132+
133+
134+class IPCInterfaceTestCase(IPCInterfaceTestCaseBase):
135+ """Tests for the IPCInterface when everything goes dandy."""
136+
137+ cmt_class = FakeCredentialsManagementTool
138+
139+ @defer.inlineCallbacks
140+ def test_connect(self):
141+ """Test the connect method."""
142+ expected_token = FakeCredentialsManagementTool.fake_credentials
143+ yield self.ipc.connect()
144+ token = self.ipc.main.event_q.pushed_events[0][1]["access_token"]
145+ self.assertEqual(token, expected_token)
146+
147+ @defer.inlineCallbacks
148+ def test_connect_autoconnecting(self):
149+ """Test the connect method when autoconnecting."""
150+ expected_token = FakeCredentialsManagementTool.fake_credentials
151+ yield self.ipc.connect(autoconnecting=True)
152+ token = self.ipc.main.event_q.pushed_events[0][1]["access_token"]
153+ self.assertEqual(token, expected_token)
154+
155+
156+class IPCInterfaceFailingTestCase(IPCInterfaceTestCaseBase):
157+ """Tests for the IPCInterface on a rainy day."""
158+
159+ cmt_class = FakeCredentialsManagementToolFails
160+
161+ @defer.inlineCallbacks
162+ def test_connect(self):
163+ """Test the connect method fails."""
164+ yield self.assertFailure(self.ipc.connect(), ipc.NoAccessToken)
165+
166+ @defer.inlineCallbacks
167+ def test_connect_autoconnecting(self):
168+ """Test the connect method when autoconnecting fails."""
169+ d = self.ipc.connect(autoconnecting=True)
170+ yield self.assertFailure(d, ipc.NoAccessToken)
171
172=== modified file 'ubuntuone/platform/windows/ipc.py'
173--- ubuntuone/platform/windows/ipc.py 2011-06-21 09:57:17 +0000
174+++ ubuntuone/platform/windows/ipc.py 2011-06-22 15:39:50 +0000
175@@ -1,6 +1,7 @@
176 # -*- coding: utf-8 -*-
177 #
178-# Author: Manuel de la Pena<manuel@canonical.com>
179+# Authors: Manuel de la Pena <manuel@canonical.com>
180+# Alejandro J. Cura <alecu@canonical.com>
181 #
182 # Copyright 2011 Canonical Ltd.
183 #
184@@ -25,7 +26,6 @@
185
186 from twisted.internet import defer, reactor
187 from twisted.spread.pb import Referenceable, Root, PBServerFactory
188-from twisted.python.failure import Failure
189 from ubuntuone.syncdaemon.interfaces import IMarker
190 from ubuntuone.platform.windows import CredentialsManagementTool
191 from ubuntuone.platform.windows.network_manager import NetworkManager
192@@ -1057,56 +1057,28 @@
193 return
194 token = {'consumer_key': ckey, 'consumer_secret': csecret,
195 'token': key, 'token_secret': secret}
196- self.main.event_q.push('SYS_USER_CONNECT', access_token=token)
197 else:
198- token = yield self._request_token(autoconnecting=autoconnecting)
199-
200- def on_credentials_found_cb(self, app_name, creds, *args, **kwargs):
201- """Provide the creds."""
202- print 'Creds are %s' % creds
203- logger.info('connect: credential request was successful, '
204- 'pushing SYS_USER_CONNECT.')
205- self.main.event_q.push('SYS_USER_CONNECT', access_token=creds)
206-
207- def on_credentials_error_cb(self, app_name, *args, **kwargs):
208- """Deal with the error."""
209- d = self._deferred
210- d.errback(Failure(NoAccessToken()))
211-
212- @defer.inlineCallbacks
213- def _register_to_signals(self):
214- """Register to the creds signals."""
215- management_tool = CredentialsManagementTool()
216- self.creds = yield management_tool.get_creds_proxy()
217- self.creds.register_to_credentials_found(self.on_credentials_found_cb)
218- self.creds.register_to_credentials_not_found(
219- self.on_credentials_error_cb)
220- self.creds.register_to_authorization_denied(
221- self.on_credentials_error_cb)
222- self.creds.register_to_credentials_error(self.on_credentials_error_cb)
223+ try:
224+ token = yield self._request_token(
225+ autoconnecting=autoconnecting)
226+ except Exception, e:
227+ raise NoAccessToken(e)
228+
229+ self.main.event_q.push('SYS_USER_CONNECT', access_token=token)
230
231 def _request_token(self, autoconnecting):
232 """Request to SSO auth service to fetch the token."""
233- self._deferred = defer.Deferred()
234-
235- def error_handler(error):
236- """Default error handler."""
237- logger.error('Handling error from sso %s.', error)
238-
239 # call ubuntu sso
240 try:
241 management = CredentialsManagementTool()
242- # add the diff callbacks to be executed
243- self._register_to_signals()
244- # ignore the reply, we get the result via signals
245+ # return the deferred, since we are no longer using signals
246 if autoconnecting:
247 return management.find_credentials()
248 else:
249 return management.register({'window_id': '0'}) # no window ID
250 except:
251- logger.exception('connect failed while getting the token')
252+ logger.exception('failure while getting the token')
253 raise
254- return self._deferred
255
256 def disconnect(self):
257 """ Push the SYS_USER_DISCONNECT event. """

Subscribers

People subscribed via source and target branches