Merge lp:~alecu/ubuntuone-client/fix-cmt-usage into lp:ubuntuone-client
- fix-cmt-usage
- Merge into trunk
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 | ||||
Related bugs: |
|
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 CredentialsMana
Description of the change
On Windows, use the CredentialsMana
Alejandro J. Cura (alecu) wrote : | # |
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_
def on_credentials_
* The rest looks great!
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_
>
> def on_credentials_
This is now fixed and pushed.
> * The rest looks great!
thanks!
Natalia Bidart (nataliabidart) : | # |
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.
Manuel de la Peña (mandel) : | # |
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
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/
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_
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...
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
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 | 52 | ECHO Python found, executing the tests... | 52 | ECHO Python found, executing the tests... |
6 | 53 | COPY windows\clientdefs.py ubuntuone\clientdefs.py | 53 | COPY windows\clientdefs.py ubuntuone\clientdefs.py |
7 | 54 | :: execute the tests with a number of ignored linux only modules | 54 | :: execute the tests with a number of ignored linux only modules |
9 | 55 | "%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1trial" -c tests -p tests\platform\linux | 55 | "%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1trial" --reactor=txnp -c tests -p tests\platform\linux %1 |
10 | 56 | "%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1lint" | 56 | "%PYTHONPATH%\python.exe" "%PYTHONPATH%\Scripts\u1lint" |
11 | 57 | :: test for style if we can, if pep8 is not present, move to the end | 57 | :: test for style if we can, if pep8 is not present, move to the end |
12 | 58 | IF EXIST "%PYTHONPATH%Scripts\pep8.exe" | 58 | IF EXIST "%PYTHONPATH%Scripts\pep8.exe" |
13 | @@ -62,4 +62,4 @@ | |||
14 | 62 | :: Delete the temp folders | 62 | :: Delete the temp folders |
15 | 63 | RMDIR /s /q _trial_temp | 63 | RMDIR /s /q _trial_temp |
16 | 64 | RMDIR /s /q .coverage | 64 | RMDIR /s /q .coverage |
17 | 65 | :END | ||
18 | 66 | \ No newline at end of file | 65 | \ No newline at end of file |
19 | 66 | :END | ||
20 | 67 | 67 | ||
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 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
26 | 2 | # | 2 | # |
28 | 3 | # Author: Manuel de la Pena<manuel@canonical.com> | 3 | # Authors: Manuel de la Pena <manuel@canonical.com> |
29 | 4 | # Alejandro J. Cura <alecu@canonical.com> | ||
30 | 4 | # | 5 | # |
31 | 5 | # Copyright 2011 Canonical Ltd. | 6 | # Copyright 2011 Canonical Ltd. |
32 | 6 | # | 7 | # |
33 | @@ -27,12 +28,14 @@ | |||
34 | 27 | Root, | 28 | Root, |
35 | 28 | RemoteReference) | 29 | RemoteReference) |
36 | 29 | 30 | ||
37 | 31 | from ubuntuone.platform.windows import ipc | ||
38 | 30 | from ubuntuone.platform.windows.ipc import ( | 32 | from ubuntuone.platform.windows.ipc import ( |
39 | 31 | AllEventsSender, | 33 | AllEventsSender, |
40 | 32 | Config, | 34 | Config, |
41 | 33 | Events, | 35 | Events, |
42 | 34 | Folders, | 36 | Folders, |
43 | 35 | FileSystem, | 37 | FileSystem, |
44 | 38 | IPCInterface, | ||
45 | 36 | IPCRoot, | 39 | IPCRoot, |
46 | 37 | PublicFiles, | 40 | PublicFiles, |
47 | 38 | Shares, | 41 | Shares, |
48 | @@ -3172,3 +3175,122 @@ | |||
49 | 3172 | d.addCallback(test_execution) | 3175 | d.addCallback(test_execution) |
50 | 3173 | # pylint: enable=E1101 | 3176 | # pylint: enable=E1101 |
51 | 3174 | return d | 3177 | return d |
52 | 3178 | |||
53 | 3179 | |||
54 | 3180 | class FakeIPCRoot(object, ipc.Root): | ||
55 | 3181 | """A Fake IPC Root.""" | ||
56 | 3182 | |||
57 | 3183 | def __init__(self, *args, **kwargs): | ||
58 | 3184 | """Initialize this fake instance.""" | ||
59 | 3185 | # This empty method is needed to override the default constructor | ||
60 | 3186 | |||
61 | 3187 | |||
62 | 3188 | class RandomException(Exception): | ||
63 | 3189 | """A random exception.""" | ||
64 | 3190 | |||
65 | 3191 | |||
66 | 3192 | class FakeCredentialsManagementTool(object): | ||
67 | 3193 | """A Fake CredentialsManagementTool.""" | ||
68 | 3194 | |||
69 | 3195 | fake_credentials = { | ||
70 | 3196 | "consumer_key": "sample consumer key", | ||
71 | 3197 | "consumer_secret": "sample consumer secret", | ||
72 | 3198 | "token": "sample token", | ||
73 | 3199 | "token_secret": "sample token secret", | ||
74 | 3200 | } | ||
75 | 3201 | should_fail = False | ||
76 | 3202 | |||
77 | 3203 | def find_credentials(self): | ||
78 | 3204 | """Find the credentials.""" | ||
79 | 3205 | if self.should_fail: | ||
80 | 3206 | return defer.fail(RandomException()) | ||
81 | 3207 | return defer.succeed(self.fake_credentials) | ||
82 | 3208 | |||
83 | 3209 | def register(self, *args): | ||
84 | 3210 | """Register a new user.""" | ||
85 | 3211 | if self.should_fail: | ||
86 | 3212 | return defer.fail(RandomException()) | ||
87 | 3213 | return defer.succeed(self.fake_credentials) | ||
88 | 3214 | |||
89 | 3215 | |||
90 | 3216 | class FakeCredentialsManagementToolFails(FakeCredentialsManagementTool): | ||
91 | 3217 | """A Fake CredentialsManagementTool that consistently fails.""" | ||
92 | 3218 | |||
93 | 3219 | should_fail = True | ||
94 | 3220 | |||
95 | 3221 | |||
96 | 3222 | class FakeEventQueue(object): | ||
97 | 3223 | """A fake event queue.""" | ||
98 | 3224 | |||
99 | 3225 | def __init__(self): | ||
100 | 3226 | """Initialize this fake instance.""" | ||
101 | 3227 | self.pushed_events = [] | ||
102 | 3228 | |||
103 | 3229 | def push(self, event_name, **kwargs): | ||
104 | 3230 | """Store the pushed event.""" | ||
105 | 3231 | event = (event_name, kwargs) | ||
106 | 3232 | self.pushed_events.append(event) | ||
107 | 3233 | |||
108 | 3234 | |||
109 | 3235 | class FakeMain(object): | ||
110 | 3236 | """A fake main.""" | ||
111 | 3237 | |||
112 | 3238 | def __init__(self): | ||
113 | 3239 | """Initialize this fake instance.""" | ||
114 | 3240 | self.event_q = FakeEventQueue() | ||
115 | 3241 | |||
116 | 3242 | |||
117 | 3243 | class IPCInterfaceTestCaseBase(TestCase): | ||
118 | 3244 | """Base tests for IPCInterface.""" | ||
119 | 3245 | |||
120 | 3246 | cmt_class = None | ||
121 | 3247 | |||
122 | 3248 | def setUp(self): | ||
123 | 3249 | """Initialize this test instance.""" | ||
124 | 3250 | if self.cmt_class is None: return | ||
125 | 3251 | self.patch(ipc, "CredentialsManagementTool", self.cmt_class) | ||
126 | 3252 | self.patch(ipc, "GetUserNameEx", lambda x: "sample_username") | ||
127 | 3253 | self.patch(ipc, "IPCRoot", FakeIPCRoot) | ||
128 | 3254 | no_op = lambda *args: None | ||
129 | 3255 | self.patch(ipc.reactor, "listenPipe", no_op) | ||
130 | 3256 | self.patch(IPCInterface, "network_connected", no_op) | ||
131 | 3257 | self.ipc = IPCInterface(FakeMain()) | ||
132 | 3258 | |||
133 | 3259 | |||
134 | 3260 | class IPCInterfaceTestCase(IPCInterfaceTestCaseBase): | ||
135 | 3261 | """Tests for the IPCInterface when everything goes dandy.""" | ||
136 | 3262 | |||
137 | 3263 | cmt_class = FakeCredentialsManagementTool | ||
138 | 3264 | |||
139 | 3265 | @defer.inlineCallbacks | ||
140 | 3266 | def test_connect(self): | ||
141 | 3267 | """Test the connect method.""" | ||
142 | 3268 | expected_token = FakeCredentialsManagementTool.fake_credentials | ||
143 | 3269 | yield self.ipc.connect() | ||
144 | 3270 | token = self.ipc.main.event_q.pushed_events[0][1]["access_token"] | ||
145 | 3271 | self.assertEqual(token, expected_token) | ||
146 | 3272 | |||
147 | 3273 | @defer.inlineCallbacks | ||
148 | 3274 | def test_connect_autoconnecting(self): | ||
149 | 3275 | """Test the connect method when autoconnecting.""" | ||
150 | 3276 | expected_token = FakeCredentialsManagementTool.fake_credentials | ||
151 | 3277 | yield self.ipc.connect(autoconnecting=True) | ||
152 | 3278 | token = self.ipc.main.event_q.pushed_events[0][1]["access_token"] | ||
153 | 3279 | self.assertEqual(token, expected_token) | ||
154 | 3280 | |||
155 | 3281 | |||
156 | 3282 | class IPCInterfaceFailingTestCase(IPCInterfaceTestCaseBase): | ||
157 | 3283 | """Tests for the IPCInterface on a rainy day.""" | ||
158 | 3284 | |||
159 | 3285 | cmt_class = FakeCredentialsManagementToolFails | ||
160 | 3286 | |||
161 | 3287 | @defer.inlineCallbacks | ||
162 | 3288 | def test_connect(self): | ||
163 | 3289 | """Test the connect method fails.""" | ||
164 | 3290 | yield self.assertFailure(self.ipc.connect(), ipc.NoAccessToken) | ||
165 | 3291 | |||
166 | 3292 | @defer.inlineCallbacks | ||
167 | 3293 | def test_connect_autoconnecting(self): | ||
168 | 3294 | """Test the connect method when autoconnecting fails.""" | ||
169 | 3295 | d = self.ipc.connect(autoconnecting=True) | ||
170 | 3296 | yield self.assertFailure(d, ipc.NoAccessToken) | ||
171 | 3175 | 3297 | ||
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 | 1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
177 | 2 | # | 2 | # |
179 | 3 | # Author: Manuel de la Pena<manuel@canonical.com> | 3 | # Authors: Manuel de la Pena <manuel@canonical.com> |
180 | 4 | # Alejandro J. Cura <alecu@canonical.com> | ||
181 | 4 | # | 5 | # |
182 | 5 | # Copyright 2011 Canonical Ltd. | 6 | # Copyright 2011 Canonical Ltd. |
183 | 6 | # | 7 | # |
184 | @@ -25,7 +26,6 @@ | |||
185 | 25 | 26 | ||
186 | 26 | from twisted.internet import defer, reactor | 27 | from twisted.internet import defer, reactor |
187 | 27 | from twisted.spread.pb import Referenceable, Root, PBServerFactory | 28 | from twisted.spread.pb import Referenceable, Root, PBServerFactory |
188 | 28 | from twisted.python.failure import Failure | ||
189 | 29 | from ubuntuone.syncdaemon.interfaces import IMarker | 29 | from ubuntuone.syncdaemon.interfaces import IMarker |
190 | 30 | from ubuntuone.platform.windows import CredentialsManagementTool | 30 | from ubuntuone.platform.windows import CredentialsManagementTool |
191 | 31 | from ubuntuone.platform.windows.network_manager import NetworkManager | 31 | from ubuntuone.platform.windows.network_manager import NetworkManager |
192 | @@ -1057,56 +1057,28 @@ | |||
193 | 1057 | return | 1057 | return |
194 | 1058 | token = {'consumer_key': ckey, 'consumer_secret': csecret, | 1058 | token = {'consumer_key': ckey, 'consumer_secret': csecret, |
195 | 1059 | 'token': key, 'token_secret': secret} | 1059 | 'token': key, 'token_secret': secret} |
196 | 1060 | self.main.event_q.push('SYS_USER_CONNECT', access_token=token) | ||
197 | 1061 | else: | 1060 | else: |
223 | 1062 | token = yield self._request_token(autoconnecting=autoconnecting) | 1061 | try: |
224 | 1063 | 1062 | token = yield self._request_token( | |
225 | 1064 | def on_credentials_found_cb(self, app_name, creds, *args, **kwargs): | 1063 | autoconnecting=autoconnecting) |
226 | 1065 | """Provide the creds.""" | 1064 | except Exception, e: |
227 | 1066 | print 'Creds are %s' % creds | 1065 | raise NoAccessToken(e) |
228 | 1067 | logger.info('connect: credential request was successful, ' | 1066 | |
229 | 1068 | 'pushing SYS_USER_CONNECT.') | 1067 | self.main.event_q.push('SYS_USER_CONNECT', access_token=token) |
205 | 1069 | self.main.event_q.push('SYS_USER_CONNECT', access_token=creds) | ||
206 | 1070 | |||
207 | 1071 | def on_credentials_error_cb(self, app_name, *args, **kwargs): | ||
208 | 1072 | """Deal with the error.""" | ||
209 | 1073 | d = self._deferred | ||
210 | 1074 | d.errback(Failure(NoAccessToken())) | ||
211 | 1075 | |||
212 | 1076 | @defer.inlineCallbacks | ||
213 | 1077 | def _register_to_signals(self): | ||
214 | 1078 | """Register to the creds signals.""" | ||
215 | 1079 | management_tool = CredentialsManagementTool() | ||
216 | 1080 | self.creds = yield management_tool.get_creds_proxy() | ||
217 | 1081 | self.creds.register_to_credentials_found(self.on_credentials_found_cb) | ||
218 | 1082 | self.creds.register_to_credentials_not_found( | ||
219 | 1083 | self.on_credentials_error_cb) | ||
220 | 1084 | self.creds.register_to_authorization_denied( | ||
221 | 1085 | self.on_credentials_error_cb) | ||
222 | 1086 | self.creds.register_to_credentials_error(self.on_credentials_error_cb) | ||
230 | 1087 | 1068 | ||
231 | 1088 | def _request_token(self, autoconnecting): | 1069 | def _request_token(self, autoconnecting): |
232 | 1089 | """Request to SSO auth service to fetch the token.""" | 1070 | """Request to SSO auth service to fetch the token.""" |
233 | 1090 | self._deferred = defer.Deferred() | ||
234 | 1091 | |||
235 | 1092 | def error_handler(error): | ||
236 | 1093 | """Default error handler.""" | ||
237 | 1094 | logger.error('Handling error from sso %s.', error) | ||
238 | 1095 | |||
239 | 1096 | # call ubuntu sso | 1071 | # call ubuntu sso |
240 | 1097 | try: | 1072 | try: |
241 | 1098 | management = CredentialsManagementTool() | 1073 | management = CredentialsManagementTool() |
245 | 1099 | # add the diff callbacks to be executed | 1074 | # return the deferred, since we are no longer using signals |
243 | 1100 | self._register_to_signals() | ||
244 | 1101 | # ignore the reply, we get the result via signals | ||
246 | 1102 | if autoconnecting: | 1075 | if autoconnecting: |
247 | 1103 | return management.find_credentials() | 1076 | return management.find_credentials() |
248 | 1104 | else: | 1077 | else: |
249 | 1105 | return management.register({'window_id': '0'}) # no window ID | 1078 | return management.register({'window_id': '0'}) # no window ID |
250 | 1106 | except: | 1079 | except: |
252 | 1107 | logger.exception('connect failed while getting the token') | 1080 | logger.exception('failure while getting the token') |
253 | 1108 | raise | 1081 | raise |
254 | 1109 | return self._deferred | ||
255 | 1110 | 1082 | ||
256 | 1111 | def disconnect(self): | 1083 | def disconnect(self): |
257 | 1112 | """ Push the SYS_USER_DISCONNECT event. """ | 1084 | """ Push the SYS_USER_DISCONNECT event. """ |
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