Merge lp:~nataliabidart/magicicada-server/no-more-storms-1 into lp:magicicada-server
- no-more-storms-1
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Facundo Batista |
Approved revision: | 52 |
Merged at revision: | 51 |
Proposed branch: | lp:~nataliabidart/magicicada-server/no-more-storms-1 |
Merge into: | lp:magicicada-server |
Prerequisite: | lp:~nataliabidart/magicicada-server/no-more-storms-0 |
Diff against target: |
761 lines (+164/-233) 12 files modified
src/server/integtests/test_action_queue.py (+9/-9) src/server/integtests/test_share_sync.py (+2/-1) src/server/server.py (+3/-6) src/server/testing/testcase.py (+8/-6) src/server/tests/test_auth.py (+7/-14) src/server/tests/test_basic.py (+3/-0) src/server/tests/test_content.py (+5/-17) src/server/tests/test_fileops.py (+12/-16) src/server/tests/test_make.py (+14/-18) src/server/tests/test_oops.py (+12/-14) src/server/tests/test_sharing.py (+72/-118) src/server/tests/test_volumes.py (+17/-14) |
To merge this branch: | bzr merge lp:~nataliabidart/magicicada-server/no-more-storms-1 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Facundo Batista | Approve | ||
Review via email: mp+287119@code.launchpad.net |
Commit message
- Transform many server tests that were using the old deferred school into inlineCallbacks tests.
- Fixed some docstrings.
- Ensure src/server/
- Replaced many hard-coded "user id 0" with the actual id of self.usr0, so later when the ID gets generated automatically, tests do not depend on a hard coded value.
Description of the change
- 49. By Natalia Bidart
-
Merged no-more-storms-0 into no-more-storms-1.
- 50. By Natalia Bidart
-
Merged trunk in.
- 51. By Natalia Bidart
-
Merged trunk in.
- 52. By Natalia Bidart
-
Merged trunk into no-more-storms-1.
Facundo Batista (facundo) wrote : | # |
I'm consistently getting this:
$ ./test src/backends/
backends.
StorageUserGa
test_
File "/usr/lib/
testMethod()
File "/home/
set([(d.id, d.vol_type) for d in expected_dirs]))
File "/usr/lib/
assertion_
File "/usr/lib/
self.
File "/usr/lib/
raise self.failureExc
exceptions.
('7c36e5fa-
('bb841d58-
('9ec2e502-
Items in the second set but not the first:
(UUID('
(UUID('
(UUID('
[FAIL]
=======
[FAIL]
Traceback (most recent call last):
File "/usr/lib/
testMethod()
File "/home/
set([(d.id, d.vol_type) for d in expected_dirs]))
File "/usr/lib/
assertion_
File "/usr/lib/
self.
File "/usr/lib/
raise self.failureExc
exceptions.
('7c36e5fa-
('bb841d58-
('9ec2e502-
Items in the second set but not the first:
(UUID('
(UUID('
(UUID('
backends.
Preview Diff
1 | === modified file 'src/server/integtests/test_action_queue.py' |
2 | --- src/server/integtests/test_action_queue.py 2015-09-26 13:02:01 +0000 |
3 | +++ src/server/integtests/test_action_queue.py 2016-02-27 20:39:13 +0000 |
4 | @@ -773,20 +773,20 @@ |
5 | d.addCallback(lambda _: self.wait_for_nirvana(.5)) |
6 | return d |
7 | |
8 | + @defer.inlineCallbacks |
9 | def test_connection_lost(self): |
10 | """Try to connect.""" |
11 | - d = self.connect() |
12 | dd = defer.Deferred() |
13 | - d.addCallback(lambda _: self.wait_for_nirvana(.5)) |
14 | - d.addCallback(lambda _: self.aq.connector.transport.loseConnection()) |
15 | - d.addCallback(lambda _: reactor.callLater(1, dd.callback, None)) |
16 | - d.addCallback(lambda _: dd) |
17 | + |
18 | + yield self.connect() |
19 | + yield self.wait_for_nirvana(.5) |
20 | + yield self.aq.connector.transport.loseConnection() |
21 | + yield reactor.callLater(1, dd.callback, None) |
22 | + yield dd |
23 | # check that the connection lost event is issued: |
24 | - d.addCallback(lambda _: self.assertIn(('SYS_CONNECTION_LOST', {}), |
25 | - self.listener.q)) |
26 | + yield self.assertIn(('SYS_CONNECTION_LOST', {}), self.listener.q) |
27 | # test that we reconnect: |
28 | - d.addCallback(lambda _: self.wait_for_nirvana(.5)) |
29 | - return d |
30 | + yield lambda _: self.wait_for_nirvana(.5) |
31 | |
32 | def test_init(self): |
33 | """Check that, when started, state is INIT.""" |
34 | |
35 | === modified file 'src/server/integtests/test_share_sync.py' |
36 | --- src/server/integtests/test_share_sync.py 2016-02-26 00:22:17 +0000 |
37 | +++ src/server/integtests/test_share_sync.py 2016-02-27 20:39:13 +0000 |
38 | @@ -33,7 +33,8 @@ |
39 | |
40 | |
41 | class TestSharesSync(test_sync.TestSync): |
42 | - """ Base class for shares tests. """ |
43 | + """Base class for shares tests.""" |
44 | + |
45 | called = 0 |
46 | |
47 | def handle_SYS_STATE_CHANGED(self, state): |
48 | |
49 | === modified file 'src/server/server.py' |
50 | --- src/server/server.py 2015-10-18 01:35:37 +0000 |
51 | +++ src/server/server.py 2016-02-27 20:39:13 +0000 |
52 | @@ -55,7 +55,6 @@ |
53 | from metrics import get_meter |
54 | from metrics.metricsconnector import MetricsConnector |
55 | from backends.filesync import errors as dataerror |
56 | -from backends.filesync.models import Share, StorageObject |
57 | from backends.filesync.notifier import notifier |
58 | from magicicada import settings |
59 | from ubuntuone.storage.server.logger import configure_logger, TRACE |
60 | @@ -1186,8 +1185,8 @@ |
61 | # these are the valid access levels and their translation from the |
62 | # protocol message |
63 | _valid_access_levels = { |
64 | - protocol_pb2.CreateShare.VIEW: Share.VIEW, |
65 | - protocol_pb2.CreateShare.MODIFY: Share.MODIFY, |
66 | + protocol_pb2.CreateShare.VIEW: 'View', |
67 | + protocol_pb2.CreateShare.MODIFY: 'Modify', |
68 | } |
69 | |
70 | user_activity = 'create_share' |
71 | @@ -2160,11 +2159,9 @@ |
72 | if self.source_message.type == protocol_pb2.Message.MAKE_DIR: |
73 | response_type = protocol_pb2.Message.NEW_DIR |
74 | create_method_name = 'make_dir' |
75 | - node_type = StorageObject.DIRECTORY |
76 | elif self.source_message.type == protocol_pb2.Message.MAKE_FILE: |
77 | response_type = protocol_pb2.Message.NEW_FILE |
78 | create_method_name = 'make_file' |
79 | - node_type = StorageObject.FILE |
80 | else: |
81 | raise request.StorageProtocolError( |
82 | 'Can not create from message ' |
83 | @@ -2188,7 +2185,7 @@ |
84 | # save data to be logged on operation end |
85 | extension = self._get_extension(name) |
86 | self.operation_data = 'type=%s vol_id=%s node_id=%s mime=%r ext=%r' % ( |
87 | - node_type, share_id, node_id, mimetype, extension) |
88 | + create_method_name, share_id, node_id, mimetype, extension) |
89 | |
90 | |
91 | class FreeSpaceResponse(SimpleRequestResponse): |
92 | |
93 | === modified file 'src/server/testing/testcase.py' |
94 | --- src/server/testing/testcase.py 2015-10-04 15:14:24 +0000 |
95 | +++ src/server/testing/testcase.py 2016-02-27 20:39:13 +0000 |
96 | @@ -92,9 +92,8 @@ |
97 | |
98 | |
99 | class BaseProtocolTestCase(TwistedTestCase): |
100 | - """ |
101 | - Reusable part of ProtocolTestCase |
102 | - """ |
103 | + """Reusable part of ProtocolTestCase.""" |
104 | + |
105 | # do we need to create oops files? |
106 | createOOPSFiles = False |
107 | heartbeat_interval = 0 |
108 | @@ -408,10 +407,10 @@ |
109 | yield super(TestWithDatabase, self).setUp() |
110 | |
111 | users = ( |
112 | - (0, u'usr0', 'pass0'), |
113 | - (1, u'usr1', 'pass1'), |
114 | + (0, u'usr0', 'open sesame'), |
115 | + (1, u'usr1', 'friend'), |
116 | (2, u'usr2', 'pass2'), |
117 | - (3, u'usr3', 'pass3'), |
118 | + (3, u'usr3', 'usr3'), |
119 | ) |
120 | for user_id, username, password in users: |
121 | user = create_test_user( |
122 | @@ -419,6 +418,9 @@ |
123 | setattr(self, username, user) |
124 | # set the password in the object just as a test simplifier |
125 | user.password = password |
126 | + dummy_tokens = getattr(self.auth_provider_class, '_allowed', None) |
127 | + if dummy_tokens: |
128 | + dummy_tokens[password] = user.id |
129 | |
130 | # tune the config for this tests |
131 | self.patch(settings.api_server, 'STORAGE_CHUNK_SIZE', 1024 * 64) |
132 | |
133 | === modified file 'src/server/tests/test_auth.py' |
134 | --- src/server/tests/test_auth.py 2015-09-27 16:59:15 +0000 |
135 | +++ src/server/tests/test_auth.py 2016-02-27 20:39:13 +0000 |
136 | @@ -26,7 +26,6 @@ |
137 | |
138 | from backends.filesync.errors import DoesNotExist |
139 | from ubuntuone.storage.server.auth import ( |
140 | - AuthenticationProvider, |
141 | DummyAuthProvider, |
142 | SimpleAuthProvider, |
143 | ) |
144 | @@ -47,19 +46,13 @@ |
145 | |
146 | return auth_d |
147 | |
148 | - |
149 | -class AuthenticationProviderTests(AuthenticationBaseTestCase): |
150 | - """Fixture for authentication provider tests.""" |
151 | - |
152 | - auth_provider_class = AuthenticationProvider |
153 | - |
154 | @defer.inlineCallbacks |
155 | def setUp(self): |
156 | - yield super(AuthenticationProviderTests, self).setUp() |
157 | - self.provider = self.auth_provider_class(self.service.factory) |
158 | - |
159 | - |
160 | -class DummyProviderTests(AuthenticationProviderTests): |
161 | + yield super(AuthenticationBaseTestCase, self).setUp() |
162 | + self.provider = self.service.factory.auth_provider |
163 | + |
164 | + |
165 | +class DummyProviderTests(AuthenticationBaseTestCase): |
166 | """Tests for the dummy authentication provider.""" |
167 | |
168 | auth_provider_class = DummyAuthProvider |
169 | @@ -69,7 +62,7 @@ |
170 | """The dummy authentication provider succeeds with a valid token.""" |
171 | auth_params = {"dummy_token": "open sesame"} |
172 | user = yield self.provider.authenticate(auth_params, None) |
173 | - self.assertEqual(user.id, 0) |
174 | + self.assertEqual(user.id, self.usr0.id) |
175 | # the same user is returned by repeated calls |
176 | user2 = yield self.provider.authenticate(auth_params, None) |
177 | self.assertEqual(user.id, user2.id) |
178 | @@ -88,7 +81,7 @@ |
179 | self.assertEqual(user, None) |
180 | |
181 | |
182 | -class SimpleAuthProviderTests(AuthenticationProviderTests): |
183 | +class SimpleAuthProviderTests(AuthenticationBaseTestCase): |
184 | """Tests for the simple authentication provider.""" |
185 | |
186 | auth_provider_class = SimpleAuthProvider |
187 | |
188 | === modified file 'src/server/tests/test_basic.py' |
189 | --- src/server/tests/test_basic.py 2015-09-27 21:33:56 +0000 |
190 | +++ src/server/tests/test_basic.py 2016-02-27 20:39:13 +0000 |
191 | @@ -409,6 +409,9 @@ |
192 | @defer.inlineCallbacks |
193 | def test_status_OK(self): |
194 | """Test the OK status response.""" |
195 | + status = self.site.resource.children['status'] |
196 | + # override user_id with a existing user |
197 | + status.user_id = self.usr0.id |
198 | response = yield client.getPage(self.url) |
199 | self.assertEqual(response, 'Status OK\n') |
200 | |
201 | |
202 | === modified file 'src/server/tests/test_content.py' |
203 | --- src/server/tests/test_content.py 2016-02-20 17:03:19 +0000 |
204 | +++ src/server/tests/test_content.py 2016-02-27 20:39:13 +0000 |
205 | @@ -590,7 +590,7 @@ |
206 | return request |
207 | |
208 | def read(innerself, cant): |
209 | - '''If second read, cancel and trigger test.''' |
210 | + """If second read, cancel and trigger test.""" |
211 | innerself.notifs += 1 |
212 | if innerself.notifs == 2: |
213 | innerself.request.cancel() |
214 | @@ -2099,10 +2099,6 @@ |
215 | # tune the config for this tests |
216 | self.patch(settings.api_server, 'STORAGE_CHUNK_SIZE', 1024 * 1024) |
217 | |
218 | - @defer.inlineCallbacks |
219 | - def tearDown(self): |
220 | - yield super(TestChunkedContent, self).tearDown() |
221 | - |
222 | def test_putcontent_chunked(self, put_fail=False, get_fail=False): |
223 | """Checks a chunked putcontent.""" |
224 | size = int(settings.api_server.STORAGE_CHUNK_SIZE * 1.5) |
225 | @@ -2170,13 +2166,13 @@ |
226 | return self.callback_test(auth, timeout=10) |
227 | |
228 | def test_putcontent_chunked_putfail(self): |
229 | - '''Assures that chunked putcontent fails with "try again".''' |
230 | + """Assures that chunked putcontent fails with "try again".""" |
231 | d = self.test_putcontent_chunked(put_fail=True) |
232 | self.assertFails(d, 'TRY_AGAIN') |
233 | return d |
234 | |
235 | def test_putcontent_chunked_getfail(self): |
236 | - '''Assures that chunked putcontent fails with "try again".''' |
237 | + """Assures that chunked putcontent fails with "try again".""" |
238 | d = self.test_putcontent_chunked(get_fail=True) |
239 | self.assertFails(d, 'NOT_AVAILABLE') |
240 | return d |
241 | @@ -2349,12 +2345,7 @@ |
242 | return reactor.callLater(0.1, x) |
243 | |
244 | self._cooperator = task.Cooperator(scheduler=slowScheduler) |
245 | - |
246 | - @defer.inlineCallbacks |
247 | - def tearDown(self): |
248 | - """Tear down.""" |
249 | - self._cooperator.stop() |
250 | - yield super(TestUploadJob, self).tearDown() |
251 | + self.addCleanup(self._cooperator.stop) |
252 | |
253 | @defer.inlineCallbacks |
254 | def make_upload(self, size): |
255 | @@ -2410,7 +2401,6 @@ |
256 | size = self.double_size |
257 | deflated_data, hash_value, upload_job = yield self.make_upload(size) |
258 | yield upload_job.connect() |
259 | - all_sent_deferred = defer.Deferred() |
260 | |
261 | # now let's upload some data |
262 | def data_iter(chunk_size=request.MAX_MESSAGE_SIZE): |
263 | @@ -2418,10 +2408,8 @@ |
264 | for part in range(0, len(deflated_data), chunk_size): |
265 | yield upload_job.add_data( |
266 | deflated_data[part:part + chunk_size]) |
267 | - all_sent_deferred.callback(True) |
268 | |
269 | - self._cooperator.coiterate(data_iter()) |
270 | - yield all_sent_deferred |
271 | + yield self._cooperator.coiterate(data_iter()) |
272 | yield upload_job.commit() |
273 | |
274 | # verify node content |
275 | |
276 | === modified file 'src/server/tests/test_fileops.py' |
277 | --- src/server/tests/test_fileops.py 2015-09-27 17:01:04 +0000 |
278 | +++ src/server/tests/test_fileops.py 2016-02-27 20:39:13 +0000 |
279 | @@ -67,23 +67,19 @@ |
280 | |
281 | def test_move_invalid_character(self): |
282 | """Try to move a dir to a name with invalid characters and fail.""" |
283 | + |
284 | + @defer.inlineCallbacks |
285 | def auth(client): |
286 | - d = client.dummy_authenticate("open sesame") |
287 | - d.addCallback(lambda r: client.get_root()) |
288 | - d.addCallback(self.save_req, 'root_id') |
289 | - d.addCallback(lambda r: client.make_dir(request.ROOT, r, "hola")) |
290 | - d.addCallback(lambda req: client.move(request.ROOT, req.new_id, |
291 | - self._state.root_id, |
292 | - "hola / ")) |
293 | - |
294 | - def check(failure): |
295 | - """Checks the error returned.""" |
296 | - self.assertIsInstance(failure.value, |
297 | - request.StorageRequestError) |
298 | - client.test_done(True) |
299 | - |
300 | - d.addCallbacks(client.test_fail, check) |
301 | - return self.callback_test(auth) |
302 | + yield client.dummy_authenticate("open sesame") |
303 | + root = yield client.get_root() |
304 | + self.save_req(root, 'root_id') |
305 | + req = yield client.make_dir(request.ROOT, root, "hola") |
306 | + d = client.move( |
307 | + request.ROOT, req.new_id, self._state.root_id, "hola / ") |
308 | + res = yield self.assertFailure(d, request.StorageRequestError) |
309 | + self.assertEqual(str(res), "INVALID_FILENAME") |
310 | + |
311 | + return self.callback_test(auth, add_default_callbacks=True) |
312 | |
313 | def test_move_file_overwrite(self): |
314 | """Rename over an existing file.""" |
315 | |
316 | === modified file 'src/server/tests/test_make.py' |
317 | --- src/server/tests/test_make.py 2015-09-27 16:59:15 +0000 |
318 | +++ src/server/tests/test_make.py 2016-02-27 20:39:13 +0000 |
319 | @@ -25,7 +25,7 @@ |
320 | |
321 | from StringIO import StringIO |
322 | |
323 | -from twisted.internet import threads, defer |
324 | +from twisted.internet import defer |
325 | |
326 | from backends.filesync import errors |
327 | from ubuntuone.storageprotocol import request, volumes |
328 | @@ -50,27 +50,23 @@ |
329 | return self.callback_test(auth) |
330 | |
331 | def build_mime_test(filename, file_mime): |
332 | - """create test cases for mime type checking.""" |
333 | + """Create test cases for mime type checking.""" |
334 | def test_mkfile_mime_type(self): |
335 | """Create a file.""" |
336 | + @defer.inlineCallbacks |
337 | def auth(client): |
338 | def check_file(result): |
339 | - def _check_file(): |
340 | - try: |
341 | - file = self.usr0.get_node(result.new_id) |
342 | - except errors.DoesNotExist: |
343 | - raise ValueError("storage object is missing") |
344 | - assert(file.mimetype == file_mime) |
345 | - d = threads.deferToThread(_check_file) |
346 | - return d |
347 | - d = client.dummy_authenticate("open sesame") |
348 | - d.addCallbacks(lambda r: client.get_root(), client.test_fail) |
349 | - d.addCallbacks( |
350 | - lambda r: client.make_file(request.ROOT, r, filename), |
351 | - client.test_fail) |
352 | - d.addCallback(check_file) |
353 | - d.addCallbacks(client.test_done, client.test_fail) |
354 | - return self.callback_test(auth) |
355 | + try: |
356 | + f = self.usr0.get_node(result.new_id) |
357 | + except errors.DoesNotExist: |
358 | + raise ValueError("storage object is missing") |
359 | + self.assertEqual(f.mimetype, file_mime) |
360 | + |
361 | + yield client.dummy_authenticate("open sesame") |
362 | + root = yield client.get_root() |
363 | + result = yield client.make_file(request.ROOT, root, filename) |
364 | + check_file(result) |
365 | + return self.callback_test(auth, add_default_callbacks=True) |
366 | return test_mkfile_mime_type |
367 | |
368 | test_mkfile_mime1 = build_mime_test("image.png", "image/png") |
369 | |
370 | === modified file 'src/server/tests/test_oops.py' |
371 | --- src/server/tests/test_oops.py 2015-09-18 23:36:43 +0000 |
372 | +++ src/server/tests/test_oops.py 2016-02-27 20:39:13 +0000 |
373 | @@ -125,21 +125,19 @@ |
374 | """Test that the user id and username is included in the extra data""" |
375 | @defer.inlineCallbacks |
376 | def poisoned_ping(client): |
377 | - try: |
378 | - pd = self.service.factory.protocols[0].wait_for_poison() |
379 | - self.service.factory.protocols[0].poison("ping") |
380 | - message = protocol_pb2.Message() |
381 | - message.id = 5 |
382 | - message.type = protocol_pb2.Message.PING |
383 | - client.sendMessage(message) |
384 | - yield pd |
385 | + pd = self.service.factory.protocols[0].wait_for_poison() |
386 | + self.service.factory.protocols[0].poison("ping") |
387 | + message = protocol_pb2.Message() |
388 | + message.id = 5 |
389 | + message.type = protocol_pb2.Message.PING |
390 | + client.sendMessage(message) |
391 | + yield pd |
392 | |
393 | - oops_data = self.get_oops_data() |
394 | - self.assertEqual("Service was poisoned with: ping", |
395 | - oops_data["value"]) |
396 | - self.assertEqual("0,0,usr0", oops_data["username"]) |
397 | - except Exception, e: |
398 | - raise e |
399 | + oops_data = self.get_oops_data() |
400 | + self.assertEqual("Service was poisoned with: ping", |
401 | + oops_data["value"]) |
402 | + self.assertEqual("%s,%s,usr0" % (self.usr0.id, self.usr0.id), |
403 | + oops_data["username"]) |
404 | |
405 | def auth(client): |
406 | d = client.dummy_authenticate("open sesame") |
407 | |
408 | === modified file 'src/server/tests/test_sharing.py' |
409 | --- src/server/tests/test_sharing.py 2016-02-27 00:01:05 +0000 |
410 | +++ src/server/tests/test_sharing.py 2016-02-27 20:39:13 +0000 |
411 | @@ -44,7 +44,7 @@ |
412 | """Test deletion of an offered by me share.""" |
413 | |
414 | @defer.inlineCallbacks |
415 | - def _do_delete(client): |
416 | + def do_delete(client): |
417 | """Callback to do delete.""" |
418 | # authenticate and create a root to share |
419 | yield client.dummy_authenticate("open sesame") |
420 | @@ -55,14 +55,8 @@ |
421 | yield client.delete_share(share_id) |
422 | self.assertRaises(errors.DoesNotExist, |
423 | self.usr1.get_share, share_id) |
424 | - client.test_done() |
425 | - |
426 | - def do_delete(client): |
427 | - """Test body callback.""" |
428 | - d = _do_delete(client) |
429 | - d.addErrback(client.test_fail) |
430 | - |
431 | - return self.callback_test(do_delete) |
432 | + |
433 | + return self.callback_test(do_delete, add_default_callbacks=True) |
434 | |
435 | def test_delete_volume(self): |
436 | """Test deletion of an offered to me and accepted share.""" |
437 | @@ -542,11 +536,11 @@ |
438 | subsubdir = subdir.make_subdirectory(u"subsubdir") |
439 | subsubfile = subsubdir.make_file(u"subsubfile") |
440 | |
441 | - share = root2.share(0, u"foo", readonly=True) |
442 | + share = root2.share(self.usr0.id, u"foo", readonly=True) |
443 | share_other = root2.share(self.usr1.id, u"foo", readonly=True) |
444 | - subshare = subdir.share(0, u"foo2", readonly=True) |
445 | - share_owner = root1.share(0, u"foo3", readonly=True) |
446 | - share_modify = rwdir.share(0, u"foo4") |
447 | + subshare = subdir.share(self.usr0.id, u"foo2", readonly=True) |
448 | + share_owner = root1.share(self.usr0.id, u"foo3", readonly=True) |
449 | + share_modify = rwdir.share(self.usr0.id, u"foo4") |
450 | for s in self.usr0.get_shared_to(accepted=False): |
451 | s.accept() |
452 | for s in self.usr1.get_shared_to(accepted=False): |
453 | @@ -835,7 +829,7 @@ |
454 | def _create_share(self, _, accepted=False): |
455 | """Creates a share, optionally accepted.""" |
456 | root = self.usr1.root.load() |
457 | - share = root.share(0, u"sharename", readonly=True) |
458 | + share = root.share(self.usr0.id, u"sharename", readonly=True) |
459 | if accepted: |
460 | self.usr0.get_share(share.id).accept() |
461 | # save the node id to be able to compare it later |
462 | @@ -1067,113 +1061,110 @@ |
463 | |
464 | def test_notify_shared_node(self): |
465 | """The notif should be sent to other users if the node is shared.""" |
466 | + |
467 | + d1 = defer.Deferred() |
468 | + d2 = defer.Deferred() |
469 | + |
470 | + @defer.inlineCallbacks |
471 | def login1(client): |
472 | """client1 login""" |
473 | - self._state.client1 = client |
474 | - d = client.dummy_authenticate("open sesame") # for user #0 |
475 | - d.addCallback(lambda _: new_client()) |
476 | - d.addCallback(make_notification) |
477 | + self.addCleanup(client.transport.loseConnection) |
478 | + yield client.dummy_authenticate("open sesame") # for user #0 |
479 | + # new client |
480 | + reactor.connectTCP('localhost', self.port, factory2) |
481 | + yield d2 |
482 | + # get the root |
483 | + root_id = yield client.get_root() |
484 | + # create the share |
485 | + yield client.create_share( |
486 | + root_id, self.usr1.username, u"name", Share.VIEW) |
487 | + # mark the share as accepted by hand, so we don't |
488 | + # have to emulate the whole process just for this test |
489 | + shares = [s for s in self.usr1.get_shared_to() |
490 | + if s.shared_by_id == self.usr0.id] |
491 | + share = shares[0] |
492 | + share.accept() |
493 | + # also store it in the state for further control |
494 | + self._state.share_id = share.id |
495 | + # create a file in the root |
496 | + yield client.make_file(request.ROOT, root_id, "hola") |
497 | |
498 | + @defer.inlineCallbacks |
499 | def login2(client): |
500 | """client2 login""" |
501 | - self._state.client2 = client |
502 | + self.addCleanup(client.transport.loseConnection) |
503 | client.set_volume_new_generation_callback(on_notification) |
504 | - d = client.dummy_authenticate("friend") # for user #1 |
505 | - d.addCallback(done_auth) |
506 | + yield client.dummy_authenticate("friend") # for user #1 |
507 | + d2.callback(None) |
508 | |
509 | # setup |
510 | factory = FactoryHelper(login1) |
511 | factory2 = FactoryHelper(login2) |
512 | - d1 = defer.Deferred() |
513 | - d2 = defer.Deferred() |
514 | timeout = reactor.callLater(3, d1.errback, Exception("timeout")) |
515 | |
516 | - def new_client(): |
517 | - """add the second client""" |
518 | - reactor.connectTCP('localhost', self.port, factory2) |
519 | - return d2 |
520 | - |
521 | def on_notification(volume, generation): |
522 | """notification arrived, check and cleanup""" |
523 | # check |
524 | self.assertEqual(volume, self._state.share_id) |
525 | - |
526 | # cleanup |
527 | factory.timeout.cancel() |
528 | factory2.timeout.cancel() |
529 | timeout.cancel() |
530 | d1.callback(True) |
531 | - self._state.client1.transport.loseConnection() |
532 | - self._state.client2.transport.loseConnection() |
533 | - |
534 | - def done_auth(result): |
535 | - """authentication done for client2, we can start making changes""" |
536 | - d2.callback(result) |
537 | - |
538 | - def mark_share(_): |
539 | - # mark the share as accepted by hand, so we don't |
540 | - # have to emulate the whole process just for this test |
541 | - shares = [s for s in self.usr1.get_shared_to() |
542 | - if s.shared_by_id == 0] |
543 | - share = shares[0] |
544 | - share.accept() |
545 | - # also store it in the state for further control |
546 | - self._state.share_id = share.id |
547 | - |
548 | - def make_notification(_): |
549 | - """create a change that should create a notification""" |
550 | - # create the share |
551 | - d = self._state.client1.get_root() |
552 | - d.addCallback(self.save_req, 'root_id') |
553 | - |
554 | - # create the share |
555 | - d.addCallback( |
556 | - lambda r: self._state.client1.create_share( |
557 | - r, self.usr1.username, u"name", Share.VIEW)) |
558 | - d.addCallback(mark_share) |
559 | - |
560 | - # create a file in the root |
561 | - d.addCallback( |
562 | - lambda _: self._state.client1.make_file( |
563 | - request.ROOT, self._state.root_id, "hola")) |
564 | |
565 | reactor.connectTCP('localhost', self.port, factory) |
566 | return d1 |
567 | |
568 | def test_share_node_deleted(self): |
569 | - '''Remove the node that was shared.''' |
570 | + """Remove the node that was shared.""" |
571 | + |
572 | + d1 = defer.Deferred() |
573 | + d2 = defer.Deferred() |
574 | + |
575 | + @defer.inlineCallbacks |
576 | def login1(client): |
577 | """client1 login""" |
578 | + self.addCleanup(client.transport.loseConnection) |
579 | self._state.client1 = client |
580 | - d = client.dummy_authenticate("open sesame") # for user #0 |
581 | - d.addCallback(new_client) |
582 | - d.addCallback(make_notification) |
583 | + yield client.dummy_authenticate("open sesame") # for user #0 |
584 | + reactor.connectTCP('localhost', self.port, factory2) |
585 | + yield d2 |
586 | + # create the share |
587 | + root_id = yield client.get_root() |
588 | + # create the dir to share |
589 | + req = yield client.make_dir(request.ROOT, root_id, "hi") |
590 | + # create the share |
591 | + yield client.create_share( |
592 | + req.new_id, self.usr1.username, u"name", Share.VIEW) |
593 | + # mark the share as accepted by hand, so we don't |
594 | + # have to emulate the whole process just for this test |
595 | + share = self.usr1.get_shared_to(accepted=False)[0] |
596 | + share.accept() |
597 | + # also store it in the state for further control |
598 | + self._state.share_id = share.id |
599 | + # remove the shared node |
600 | + yield client.unlink(request.ROOT, req.new_id) |
601 | |
602 | + @defer.inlineCallbacks |
603 | def login2(client): |
604 | """client2 login""" |
605 | + self.addCleanup(client.transport.loseConnection) |
606 | self._state.client2 = client |
607 | client.set_share_change_callback(notif1) |
608 | - d = client.dummy_authenticate("friend") # for user #1 |
609 | - d.addCallback(done_auth) |
610 | + yield client.dummy_authenticate("friend") # for user #1 |
611 | + d2.callback(True) |
612 | |
613 | # setup |
614 | factory = FactoryHelper(login1) |
615 | factory2 = FactoryHelper(login2) |
616 | - d1 = defer.Deferred() |
617 | - d2 = defer.Deferred() |
618 | timeout = reactor.callLater(3, d1.errback, Exception("timeout")) |
619 | |
620 | - def new_client(_): |
621 | - """add the second client""" |
622 | - reactor.connectTCP('localhost', self.port, factory2) |
623 | - return d2 |
624 | - |
625 | def notif1(share_info): |
626 | - '''First notification, for the created share.''' |
627 | + """First notification, for the created share.""" |
628 | self._state.client2.set_share_delete_callback(notif2) |
629 | |
630 | def notif2(share_id): |
631 | - '''Second notification, the tested one.''' |
632 | + """Second notification, the tested one.""" |
633 | # find the real share |
634 | self.assertRaises(errors.DoesNotExist, |
635 | self.usr1.get_share, self._state.share_id) |
636 | @@ -1182,50 +1173,13 @@ |
637 | factory.timeout.cancel() |
638 | factory2.timeout.cancel() |
639 | timeout.cancel() |
640 | - d1.callback((share_id)) |
641 | - self._state.client1.transport.loseConnection() |
642 | - self._state.client2.transport.loseConnection() |
643 | - |
644 | - def done_auth(result): |
645 | - """authentication done for client2, we can start making changes""" |
646 | - d2.callback(result) |
647 | - |
648 | - def mark_share(_): |
649 | - # mark the share as accepted by hand, so we don't |
650 | - # have to emulate the whole process just for this test |
651 | - share = self.usr1.get_shared_to(accepted=False)[0] |
652 | - share.accept() |
653 | - # also store it in the state for further control |
654 | - self._state.share_id = share.id |
655 | - |
656 | - def make_notification(_): |
657 | - """create a change that should create a notification""" |
658 | - # create the share |
659 | - client1 = self._state.client1 |
660 | - d = client1.get_root() |
661 | - d.addCallback(self.save_req, 'root_id') |
662 | - |
663 | - # create the dir to share |
664 | - d.addCallback(lambda r: client1.make_dir(request.ROOT, r, "hi")) |
665 | - d.addCallback(self.save_req, "req") |
666 | - |
667 | - # create the share |
668 | - d.addCallback( |
669 | - lambda _: client1.create_share( |
670 | - self._state.req.new_id, self.usr1.username, |
671 | - u"name", Share.VIEW)) |
672 | - d.addCallback(mark_share) |
673 | - |
674 | - # remove the shared node |
675 | - d.addCallback( |
676 | - lambda _: client1.unlink(request.ROOT, self._state.req.new_id)) |
677 | + d1.callback(share_id) |
678 | |
679 | reactor.connectTCP('localhost', self.port, factory) |
680 | return d1 |
681 | - test_share_node_deleted.skip = 'LP: #766088' |
682 | |
683 | def test_share_node_overwritten_with_move(self): |
684 | - '''Move something else over the node that was shared.''' |
685 | + """Move something else over the node that was shared.""" |
686 | def login1(client): |
687 | """client1 login""" |
688 | self._state.client1 = client |
689 | @@ -1253,11 +1207,11 @@ |
690 | return d2 |
691 | |
692 | def notif1(share_id): |
693 | - '''First notification, for the created share.''' |
694 | + """First notification, for the created share.""" |
695 | self._state.client2.set_share_delete_callback(notif2) |
696 | |
697 | def notif2(share_id): |
698 | - '''Second notification, the tested one.''' |
699 | + """Second notification, the tested one.""" |
700 | # find the real share |
701 | self.assertRaises(errors.DoesNotExist, |
702 | self.usr1.get_share, self._state.share_id) |
703 | |
704 | === modified file 'src/server/tests/test_volumes.py' |
705 | --- src/server/tests/test_volumes.py 2015-09-27 17:01:04 +0000 |
706 | +++ src/server/tests/test_volumes.py 2016-02-27 20:39:13 +0000 |
707 | @@ -92,8 +92,10 @@ |
708 | d.addCallbacks(client.test_done, client.test_fail) |
709 | return self.callback_test(auth) |
710 | |
711 | - def _create_share(self, _, accept=False, dead=False, from_id=1): |
712 | + def _create_share(self, _, accept=False, dead=False, from_id=None): |
713 | """Create the share to me.""" |
714 | + if from_id is None: |
715 | + from_id = self.usr1.id |
716 | fromusr = get_storage_user(from_id) |
717 | node = fromusr.root.load() |
718 | share = node.share(self.usr0.id, u"name", readonly=True) |
719 | @@ -324,28 +326,29 @@ |
720 | self.assertEqual(share.free_bytes, |
721 | self.usr1.get_quota().free_bytes) |
722 | |
723 | + @defer.inlineCallbacks |
724 | def auth(client): |
725 | """Authenticate and test.""" |
726 | - d = client.dummy_authenticate("open sesame") |
727 | - d.addCallback(lambda r: client.get_root()) |
728 | - d.addCallback(self.save_req, "root") |
729 | + client.dummy_authenticate("open sesame") |
730 | + root = yield client.get_root() |
731 | + self.save_req(root, "root") |
732 | |
733 | # create two udfs, kill one |
734 | - d.addCallback(lambda _: client.create_udf(u"~/ñ", u"foo")) |
735 | - d.addCallback(self.save_req, "udf") |
736 | - d.addCallback(lambda _: client.create_udf(u"~/moño", u"groovy")) |
737 | - d.addCallback(lambda r: client.delete_volume(r.volume_id)) |
738 | + udf = yield client.create_udf(u"~/ñ", u"foo") |
739 | + self.save_req(udf, "udf") |
740 | + result = yield client.create_udf(u"~/moño", u"groovy") |
741 | + yield client.delete_volume(result.volume_id) |
742 | |
743 | # create two shares, one dead (the second one should be the live |
744 | # one because the helper function stores data for comparison) |
745 | - d.addCallback(self._create_share, accept=True, dead=True) |
746 | - d.addCallback(self._create_share, accept=True, from_id=2) |
747 | + self._create_share(None, accept=True, dead=True) |
748 | + self._create_share(None, accept=True, from_id=self.usr2.id) |
749 | |
750 | # list the volumes and check |
751 | - d.addCallback(lambda _: client.list_volumes()) |
752 | - d.addCallback(check) |
753 | - d.addCallbacks(client.test_done, client.test_fail) |
754 | - return self.callback_test(auth) |
755 | + req = yield client.list_volumes() |
756 | + check(req) |
757 | + |
758 | + return self.callback_test(auth, add_default_callbacks=True) |
759 | |
760 | |
761 | class TestDataWithVolumes(TestWithDatabase): |
src/server/ tests/test_ sharing. py:28:1: F401 'dbmanager' imported but unused tests/test_ sharing. py:29:1: F401 'StorageObject' imported but unused
src/server/
make: *** [lint] Error 1