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
=== modified file 'run-tests.bat'
--- run-tests.bat 2011-04-14 11:32:42 +0000
+++ run-tests.bat 2011-06-22 15:39:50 +0000
@@ -52,7 +52,7 @@
52ECHO Python found, executing the tests...52ECHO Python found, executing the tests...
53COPY windows\clientdefs.py ubuntuone\clientdefs.py53COPY windows\clientdefs.py ubuntuone\clientdefs.py
54:: execute the tests with a number of ignored linux only modules54:: execute the tests with a number of ignored linux only modules
55"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1trial" -c tests -p tests\platform\linux55"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1trial" --reactor=txnp -c tests -p tests\platform\linux %1
56"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1lint"56"%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1lint"
57:: test for style if we can, if pep8 is not present, move to the end57:: test for style if we can, if pep8 is not present, move to the end
58IF EXIST "%PYTHONPATH%Scripts\pep8.exe"58IF EXIST "%PYTHONPATH%Scripts\pep8.exe"
@@ -62,4 +62,4 @@
62:: Delete the temp folders62:: Delete the temp folders
63RMDIR /s /q _trial_temp63RMDIR /s /q _trial_temp
64RMDIR /s /q .coverage64RMDIR /s /q .coverage
65:END
66\ No newline at end of file65\ No newline at end of file
66:END
6767
=== modified file 'tests/platform/windows/test_ipc.py'
--- tests/platform/windows/test_ipc.py 2011-06-15 15:40:17 +0000
+++ tests/platform/windows/test_ipc.py 2011-06-22 15:39:50 +0000
@@ -1,6 +1,7 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2#2#
3# Author: Manuel de la Pena<manuel@canonical.com>3# Authors: Manuel de la Pena <manuel@canonical.com>
4# Alejandro J. Cura <alecu@canonical.com>
4#5#
5# Copyright 2011 Canonical Ltd.6# Copyright 2011 Canonical Ltd.
6#7#
@@ -27,12 +28,14 @@
27 Root,28 Root,
28 RemoteReference)29 RemoteReference)
2930
31from ubuntuone.platform.windows import ipc
30from ubuntuone.platform.windows.ipc import (32from ubuntuone.platform.windows.ipc import (
31 AllEventsSender,33 AllEventsSender,
32 Config,34 Config,
33 Events,35 Events,
34 Folders,36 Folders,
35 FileSystem,37 FileSystem,
38 IPCInterface,
36 IPCRoot,39 IPCRoot,
37 PublicFiles,40 PublicFiles,
38 Shares,41 Shares,
@@ -3172,3 +3175,122 @@
3172 d.addCallback(test_execution)3175 d.addCallback(test_execution)
3173 # pylint: enable=E11013176 # pylint: enable=E1101
3174 return d3177 return d
3178
3179
3180class FakeIPCRoot(object, ipc.Root):
3181 """A Fake IPC Root."""
3182
3183 def __init__(self, *args, **kwargs):
3184 """Initialize this fake instance."""
3185 # This empty method is needed to override the default constructor
3186
3187
3188class RandomException(Exception):
3189 """A random exception."""
3190
3191
3192class FakeCredentialsManagementTool(object):
3193 """A Fake CredentialsManagementTool."""
3194
3195 fake_credentials = {
3196 "consumer_key": "sample consumer key",
3197 "consumer_secret": "sample consumer secret",
3198 "token": "sample token",
3199 "token_secret": "sample token secret",
3200 }
3201 should_fail = False
3202
3203 def find_credentials(self):
3204 """Find the credentials."""
3205 if self.should_fail:
3206 return defer.fail(RandomException())
3207 return defer.succeed(self.fake_credentials)
3208
3209 def register(self, *args):
3210 """Register a new user."""
3211 if self.should_fail:
3212 return defer.fail(RandomException())
3213 return defer.succeed(self.fake_credentials)
3214
3215
3216class FakeCredentialsManagementToolFails(FakeCredentialsManagementTool):
3217 """A Fake CredentialsManagementTool that consistently fails."""
3218
3219 should_fail = True
3220
3221
3222class FakeEventQueue(object):
3223 """A fake event queue."""
3224
3225 def __init__(self):
3226 """Initialize this fake instance."""
3227 self.pushed_events = []
3228
3229 def push(self, event_name, **kwargs):
3230 """Store the pushed event."""
3231 event = (event_name, kwargs)
3232 self.pushed_events.append(event)
3233
3234
3235class FakeMain(object):
3236 """A fake main."""
3237
3238 def __init__(self):
3239 """Initialize this fake instance."""
3240 self.event_q = FakeEventQueue()
3241
3242
3243class IPCInterfaceTestCaseBase(TestCase):
3244 """Base tests for IPCInterface."""
3245
3246 cmt_class = None
3247
3248 def setUp(self):
3249 """Initialize this test instance."""
3250 if self.cmt_class is None: return
3251 self.patch(ipc, "CredentialsManagementTool", self.cmt_class)
3252 self.patch(ipc, "GetUserNameEx", lambda x: "sample_username")
3253 self.patch(ipc, "IPCRoot", FakeIPCRoot)
3254 no_op = lambda *args: None
3255 self.patch(ipc.reactor, "listenPipe", no_op)
3256 self.patch(IPCInterface, "network_connected", no_op)
3257 self.ipc = IPCInterface(FakeMain())
3258
3259
3260class IPCInterfaceTestCase(IPCInterfaceTestCaseBase):
3261 """Tests for the IPCInterface when everything goes dandy."""
3262
3263 cmt_class = FakeCredentialsManagementTool
3264
3265 @defer.inlineCallbacks
3266 def test_connect(self):
3267 """Test the connect method."""
3268 expected_token = FakeCredentialsManagementTool.fake_credentials
3269 yield self.ipc.connect()
3270 token = self.ipc.main.event_q.pushed_events[0][1]["access_token"]
3271 self.assertEqual(token, expected_token)
3272
3273 @defer.inlineCallbacks
3274 def test_connect_autoconnecting(self):
3275 """Test the connect method when autoconnecting."""
3276 expected_token = FakeCredentialsManagementTool.fake_credentials
3277 yield self.ipc.connect(autoconnecting=True)
3278 token = self.ipc.main.event_q.pushed_events[0][1]["access_token"]
3279 self.assertEqual(token, expected_token)
3280
3281
3282class IPCInterfaceFailingTestCase(IPCInterfaceTestCaseBase):
3283 """Tests for the IPCInterface on a rainy day."""
3284
3285 cmt_class = FakeCredentialsManagementToolFails
3286
3287 @defer.inlineCallbacks
3288 def test_connect(self):
3289 """Test the connect method fails."""
3290 yield self.assertFailure(self.ipc.connect(), ipc.NoAccessToken)
3291
3292 @defer.inlineCallbacks
3293 def test_connect_autoconnecting(self):
3294 """Test the connect method when autoconnecting fails."""
3295 d = self.ipc.connect(autoconnecting=True)
3296 yield self.assertFailure(d, ipc.NoAccessToken)
31753297
=== modified file 'ubuntuone/platform/windows/ipc.py'
--- ubuntuone/platform/windows/ipc.py 2011-06-21 09:57:17 +0000
+++ ubuntuone/platform/windows/ipc.py 2011-06-22 15:39:50 +0000
@@ -1,6 +1,7 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2#2#
3# Author: Manuel de la Pena<manuel@canonical.com>3# Authors: Manuel de la Pena <manuel@canonical.com>
4# Alejandro J. Cura <alecu@canonical.com>
4#5#
5# Copyright 2011 Canonical Ltd.6# Copyright 2011 Canonical Ltd.
6#7#
@@ -25,7 +26,6 @@
2526
26from twisted.internet import defer, reactor27from twisted.internet import defer, reactor
27from twisted.spread.pb import Referenceable, Root, PBServerFactory28from twisted.spread.pb import Referenceable, Root, PBServerFactory
28from twisted.python.failure import Failure
29from ubuntuone.syncdaemon.interfaces import IMarker29from ubuntuone.syncdaemon.interfaces import IMarker
30from ubuntuone.platform.windows import CredentialsManagementTool30from ubuntuone.platform.windows import CredentialsManagementTool
31from ubuntuone.platform.windows.network_manager import NetworkManager31from ubuntuone.platform.windows.network_manager import NetworkManager
@@ -1057,56 +1057,28 @@
1057 return1057 return
1058 token = {'consumer_key': ckey, 'consumer_secret': csecret,1058 token = {'consumer_key': ckey, 'consumer_secret': csecret,
1059 'token': key, 'token_secret': secret}1059 'token': key, 'token_secret': secret}
1060 self.main.event_q.push('SYS_USER_CONNECT', access_token=token)
1061 else:1060 else:
1062 token = yield self._request_token(autoconnecting=autoconnecting)1061 try:
10631062 token = yield self._request_token(
1064 def on_credentials_found_cb(self, app_name, creds, *args, **kwargs):1063 autoconnecting=autoconnecting)
1065 """Provide the creds."""1064 except Exception, e:
1066 print 'Creds are %s' % creds1065 raise NoAccessToken(e)
1067 logger.info('connect: credential request was successful, '1066
1068 'pushing SYS_USER_CONNECT.')1067 self.main.event_q.push('SYS_USER_CONNECT', access_token=token)
1069 self.main.event_q.push('SYS_USER_CONNECT', access_token=creds)
1070
1071 def on_credentials_error_cb(self, app_name, *args, **kwargs):
1072 """Deal with the error."""
1073 d = self._deferred
1074 d.errback(Failure(NoAccessToken()))
1075
1076 @defer.inlineCallbacks
1077 def _register_to_signals(self):
1078 """Register to the creds signals."""
1079 management_tool = CredentialsManagementTool()
1080 self.creds = yield management_tool.get_creds_proxy()
1081 self.creds.register_to_credentials_found(self.on_credentials_found_cb)
1082 self.creds.register_to_credentials_not_found(
1083 self.on_credentials_error_cb)
1084 self.creds.register_to_authorization_denied(
1085 self.on_credentials_error_cb)
1086 self.creds.register_to_credentials_error(self.on_credentials_error_cb)
10871068
1088 def _request_token(self, autoconnecting):1069 def _request_token(self, autoconnecting):
1089 """Request to SSO auth service to fetch the token."""1070 """Request to SSO auth service to fetch the token."""
1090 self._deferred = defer.Deferred()
1091
1092 def error_handler(error):
1093 """Default error handler."""
1094 logger.error('Handling error from sso %s.', error)
1095
1096 # call ubuntu sso1071 # call ubuntu sso
1097 try:1072 try:
1098 management = CredentialsManagementTool()1073 management = CredentialsManagementTool()
1099 # add the diff callbacks to be executed1074 # return the deferred, since we are no longer using signals
1100 self._register_to_signals()
1101 # ignore the reply, we get the result via signals
1102 if autoconnecting:1075 if autoconnecting:
1103 return management.find_credentials()1076 return management.find_credentials()
1104 else:1077 else:
1105 return management.register({'window_id': '0'}) # no window ID1078 return management.register({'window_id': '0'}) # no window ID
1106 except:1079 except:
1107 logger.exception('connect failed while getting the token')1080 logger.exception('failure while getting the token')
1108 raise1081 raise
1109 return self._deferred
11101082
1111 def disconnect(self):1083 def disconnect(self):
1112 """ Push the SYS_USER_DISCONNECT event. """1084 """ Push the SYS_USER_DISCONNECT event. """

Subscribers

People subscribed via source and target branches