Merge lp:~nataliabidart/ubuntuone-client/fix-803984 into lp:ubuntuone-client

Proposed by Natalia Bidart
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 1061
Merged at revision: 1051
Proposed branch: lp:~nataliabidart/ubuntuone-client/fix-803984
Merge into: lp:ubuntuone-client
Diff against target: 180 lines (+72/-13)
4 files modified
tests/syncdaemon/test_action_queue.py (+26/-1)
tests/syncdaemon/test_hashqueue.py (+40/-7)
ubuntuone/syncdaemon/action_queue.py (+4/-2)
ubuntuone/syncdaemon/hash_queue.py (+2/-3)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/fix-803984
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Facundo Batista (community) Approve
Review via email: mp+67613@code.launchpad.net

Commit message

- Hasher class should open files with the 'rb' mode when hashing (LP: #803984).

- Upload command should open temp files using os_helper.open_file and 'rb' mode (LP: #803984).

To post a comment you must log in.
1061. By Natalia Bidart

Attaching bug #803984.

Revision history for this message
Facundo Batista (facundo) wrote :

Like it

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/syncdaemon/test_action_queue.py'
--- tests/syncdaemon/test_action_queue.py 2011-06-30 15:01:42 +0000
+++ tests/syncdaemon/test_action_queue.py 2011-07-11 20:34:03 +0000
@@ -3642,6 +3642,31 @@
3642 finally:3642 finally:
3643 self.command.action_queue.client = None3643 self.command.action_queue.client = None
36443644
3645 def test_uses_rb_flags_when_creating_temp_file(self):
3646 """When creating the temp file, the open_file helper is used.
3647
3648 Also, check that the 'rb' flag is passed.
3649
3650 """
3651 mh = content_hash.magic_hash_factory()
3652 self.command.magic_hash = mh.content_hash()
3653
3654 called = []
3655 self.patch(action_queue, 'open_file', lambda *a: called.append(a))
3656
3657 self.command.tempfile = NamedTemporaryFile()
3658 expected_name = self.command.tempfile.name
3659
3660 # fake the self.command.client so put_content_request does not fail
3661 self.command.action_queue.client = FakeClient()
3662 self.command._run()
3663
3664 self.assertEqual(called, [(expected_name, 'rb')])
3665
3666 # unset self.command.client so the client is not tried to be disconnected
3667 self.command.action_queue.client = None
3668
3669
3645class CreateShareTestCase(ConnectedBaseTestCase):3670class CreateShareTestCase(ConnectedBaseTestCase):
3646 """Test for CreateShare ActionQueueCommand."""3671 """Test for CreateShare ActionQueueCommand."""
36473672
@@ -5660,4 +5685,4 @@
5660 tmp.write(data)5685 tmp.write(data)
5661 tmp.seek(0)5686 tmp.seek(0)
5662 self.assertEqual(data, tmp.read(len(data)))5687 self.assertEqual(data, tmp.read(len(data)))
5663 tmp.close()
5664\ No newline at end of file5688\ No newline at end of file
5689 tmp.close()
56655690
=== modified file 'tests/syncdaemon/test_hashqueue.py'
--- tests/syncdaemon/test_hashqueue.py 2011-02-28 15:53:29 +0000
+++ tests/syncdaemon/test_hashqueue.py 2011-07-11 20:34:03 +0000
@@ -32,8 +32,7 @@
32from contrib.testing import testcase32from contrib.testing import testcase
33from ubuntuone.devtools.handlers import MementoHandler33from ubuntuone.devtools.handlers import MementoHandler
34from ubuntuone.syncdaemon import hash_queue34from ubuntuone.syncdaemon import hash_queue
35from ubuntuone.storageprotocol.content_hash import \35from ubuntuone.storageprotocol.content_hash import content_hash_factory, crc32
36 content_hash_factory, crc32
3736
3837
39# this is a unit test we need to access protected members38# this is a unit test we need to access protected members
@@ -41,16 +40,13 @@
41class HasherTests(testcase.BaseTwistedTestCase):40class HasherTests(testcase.BaseTwistedTestCase):
42 """Test the whole stuff to receive signals."""41 """Test the whole stuff to receive signals."""
4342
43 @defer.inlineCallbacks
44 def setUp(self):44 def setUp(self):
45 """Setup the test."""45 """Setup the test."""
46 testcase.BaseTwistedTestCase.setUp(self)46 yield testcase.BaseTwistedTestCase.setUp(self)
47 self.test_dir = self.mktemp('test_dir')47 self.test_dir = self.mktemp('test_dir')
48 self.timeout = 248 self.timeout = 2
4949
50 def tearDown(self):
51 """Clean up the tests."""
52 testcase.BaseTwistedTestCase.tearDown(self)
53
54 def test_live_process(self):50 def test_live_process(self):
55 """Check that the hasher lives and dies."""51 """Check that the hasher lives and dies."""
56 # create the hasher52 # create the hasher
@@ -276,6 +272,42 @@
276 queue.put((testfile, "mdid"))272 queue.put((testfile, "mdid"))
277 return d273 return d
278274
275 @defer.inlineCallbacks
276 def test_open_file_with_rb(self):
277 """Check that the file to hash is opened with 'rb' mode."""
278 called = []
279
280 orig = hash_queue.open_file
281 def faked_open_file(*a):
282 called.append(a)
283 return orig(*a)
284
285 self.patch(hash_queue, 'open_file', faked_open_file)
286
287 queue = hash_queue.UniqueQueue()
288 testfile = os.path.join(self.test_dir, "testfile")
289 with open(testfile, "w") as fh:
290 fh.write("foobar")
291 queue.put((testfile, "mdid"))
292
293 d = defer.Deferred()
294
295 class FakeEventQueue(object):
296 """Helper class."""
297 def push(inner_self, event, **kwargs):
298 """Callback."""
299 d.callback(event)
300
301 eq = FakeEventQueue()
302
303 hasher = hash_queue._Hasher(queue=queue, end_mark='end-mark', event_queue=eq)
304 hasher.start()
305
306 yield d
307 hasher.stop()
308
309 self.assertEqual(called, [(testfile, 'rb')])
310
279311
280class HashQueueTests(testcase.BaseTwistedTestCase):312class HashQueueTests(testcase.BaseTwistedTestCase):
281 """Test the whole stuff to receive signals."""313 """Test the whole stuff to receive signals."""
@@ -713,6 +745,7 @@
713 reactor.callLater(0.1, queue.clear)745 reactor.callLater(0.1, queue.clear)
714 return d746 return d
715747
748
716def test_suite():749def test_suite():
717 # pylint: disable-msg=C0111750 # pylint: disable-msg=C0111
718 return unittest.TestLoader().loadTestsFromName(__name__)751 return unittest.TestLoader().loadTestsFromName(__name__)
719752
=== modified file 'ubuntuone/syncdaemon/action_queue.py'
--- ubuntuone/syncdaemon/action_queue.py 2011-06-30 13:55:22 +0000
+++ ubuntuone/syncdaemon/action_queue.py 2011-07-11 20:34:03 +0000
@@ -49,6 +49,7 @@
49from twisted.python.failure import Failure, DefaultException49from twisted.python.failure import Failure, DefaultException
5050
51from oauth import oauth51from oauth import oauth
52from ubuntuone.platform import open_file
52from ubuntuone.storageprotocol import protocol_pb2, content_hash53from ubuntuone.storageprotocol import protocol_pb2, content_hash
53from ubuntuone.storageprotocol import errors as protocol_errors54from ubuntuone.storageprotocol import errors as protocol_errors
54from ubuntuone.storageprotocol.client import (55from ubuntuone.storageprotocol.client import (
@@ -250,7 +251,8 @@
250 else:251 else:
251 return ('start - processMessage: %s',252 return ('start - processMessage: %s',
252 str(message).replace("\n", " "))253 str(message).replace("\n", " "))
253 254
255
254class LoggingStorageClient(ThrottlingStorageClient):256class LoggingStorageClient(ThrottlingStorageClient):
255 """A subclass of StorageClient that logs.257 """A subclass of StorageClient that logs.
256258
@@ -2470,7 +2472,7 @@
2470 hash=self.hash)2472 hash=self.hash)
24712473
2472 if getattr(self.tempfile, 'name', None) is not None:2474 if getattr(self.tempfile, 'name', None) is not None:
2473 self.tempfile = open(self.tempfile.name)2475 self.tempfile = open_file(self.tempfile.name, 'rb')
2474 f = UploadProgressWrapper(self.tempfile, self)2476 f = UploadProgressWrapper(self.tempfile, self)
24752477
2476 # access here the magic hash value, don't log anywhere, and2478 # access here the magic hash value, don't log anywhere, and
24772479
=== modified file 'ubuntuone/syncdaemon/hash_queue.py'
--- ubuntuone/syncdaemon/hash_queue.py 2011-02-28 15:53:29 +0000
+++ ubuntuone/syncdaemon/hash_queue.py 2011-07-11 20:34:03 +0000
@@ -115,7 +115,7 @@
115 size = 0115 size = 0
116 try:116 try:
117 initial_stat = stat_path(path)117 initial_stat = stat_path(path)
118 with open_file(path) as fh:118 with open_file(path, 'rb') as fh:
119 while True:119 while True:
120 # stop hashing if path_to_cancel == path or _stopped is True120 # stop hashing if path_to_cancel == path or _stopped is True
121 with self.mutex:121 with self.mutex:
@@ -196,8 +196,7 @@
196196
197197
198class UniqueQueue(Queue.Queue):198class UniqueQueue(Queue.Queue):
199 """Variant of Queue that only inserts unique items in the Queue199 """Variant of Queue that only inserts unique items in the Queue."""
200 """
201200
202 def __init__(self, *args, **kwargs):201 def __init__(self, *args, **kwargs):
203 """create the instance"""202 """create the instance"""

Subscribers

People subscribed via source and target branches