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
1=== modified file 'tests/syncdaemon/test_action_queue.py'
2--- tests/syncdaemon/test_action_queue.py 2011-06-30 15:01:42 +0000
3+++ tests/syncdaemon/test_action_queue.py 2011-07-11 20:34:03 +0000
4@@ -3642,6 +3642,31 @@
5 finally:
6 self.command.action_queue.client = None
7
8+ def test_uses_rb_flags_when_creating_temp_file(self):
9+ """When creating the temp file, the open_file helper is used.
10+
11+ Also, check that the 'rb' flag is passed.
12+
13+ """
14+ mh = content_hash.magic_hash_factory()
15+ self.command.magic_hash = mh.content_hash()
16+
17+ called = []
18+ self.patch(action_queue, 'open_file', lambda *a: called.append(a))
19+
20+ self.command.tempfile = NamedTemporaryFile()
21+ expected_name = self.command.tempfile.name
22+
23+ # fake the self.command.client so put_content_request does not fail
24+ self.command.action_queue.client = FakeClient()
25+ self.command._run()
26+
27+ self.assertEqual(called, [(expected_name, 'rb')])
28+
29+ # unset self.command.client so the client is not tried to be disconnected
30+ self.command.action_queue.client = None
31+
32+
33 class CreateShareTestCase(ConnectedBaseTestCase):
34 """Test for CreateShare ActionQueueCommand."""
35
36@@ -5660,4 +5685,4 @@
37 tmp.write(data)
38 tmp.seek(0)
39 self.assertEqual(data, tmp.read(len(data)))
40- tmp.close()
41\ No newline at end of file
42+ tmp.close()
43
44=== modified file 'tests/syncdaemon/test_hashqueue.py'
45--- tests/syncdaemon/test_hashqueue.py 2011-02-28 15:53:29 +0000
46+++ tests/syncdaemon/test_hashqueue.py 2011-07-11 20:34:03 +0000
47@@ -32,8 +32,7 @@
48 from contrib.testing import testcase
49 from ubuntuone.devtools.handlers import MementoHandler
50 from ubuntuone.syncdaemon import hash_queue
51-from ubuntuone.storageprotocol.content_hash import \
52- content_hash_factory, crc32
53+from ubuntuone.storageprotocol.content_hash import content_hash_factory, crc32
54
55
56 # this is a unit test we need to access protected members
57@@ -41,16 +40,13 @@
58 class HasherTests(testcase.BaseTwistedTestCase):
59 """Test the whole stuff to receive signals."""
60
61+ @defer.inlineCallbacks
62 def setUp(self):
63 """Setup the test."""
64- testcase.BaseTwistedTestCase.setUp(self)
65+ yield testcase.BaseTwistedTestCase.setUp(self)
66 self.test_dir = self.mktemp('test_dir')
67 self.timeout = 2
68
69- def tearDown(self):
70- """Clean up the tests."""
71- testcase.BaseTwistedTestCase.tearDown(self)
72-
73 def test_live_process(self):
74 """Check that the hasher lives and dies."""
75 # create the hasher
76@@ -276,6 +272,42 @@
77 queue.put((testfile, "mdid"))
78 return d
79
80+ @defer.inlineCallbacks
81+ def test_open_file_with_rb(self):
82+ """Check that the file to hash is opened with 'rb' mode."""
83+ called = []
84+
85+ orig = hash_queue.open_file
86+ def faked_open_file(*a):
87+ called.append(a)
88+ return orig(*a)
89+
90+ self.patch(hash_queue, 'open_file', faked_open_file)
91+
92+ queue = hash_queue.UniqueQueue()
93+ testfile = os.path.join(self.test_dir, "testfile")
94+ with open(testfile, "w") as fh:
95+ fh.write("foobar")
96+ queue.put((testfile, "mdid"))
97+
98+ d = defer.Deferred()
99+
100+ class FakeEventQueue(object):
101+ """Helper class."""
102+ def push(inner_self, event, **kwargs):
103+ """Callback."""
104+ d.callback(event)
105+
106+ eq = FakeEventQueue()
107+
108+ hasher = hash_queue._Hasher(queue=queue, end_mark='end-mark', event_queue=eq)
109+ hasher.start()
110+
111+ yield d
112+ hasher.stop()
113+
114+ self.assertEqual(called, [(testfile, 'rb')])
115+
116
117 class HashQueueTests(testcase.BaseTwistedTestCase):
118 """Test the whole stuff to receive signals."""
119@@ -713,6 +745,7 @@
120 reactor.callLater(0.1, queue.clear)
121 return d
122
123+
124 def test_suite():
125 # pylint: disable-msg=C0111
126 return unittest.TestLoader().loadTestsFromName(__name__)
127
128=== modified file 'ubuntuone/syncdaemon/action_queue.py'
129--- ubuntuone/syncdaemon/action_queue.py 2011-06-30 13:55:22 +0000
130+++ ubuntuone/syncdaemon/action_queue.py 2011-07-11 20:34:03 +0000
131@@ -49,6 +49,7 @@
132 from twisted.python.failure import Failure, DefaultException
133
134 from oauth import oauth
135+from ubuntuone.platform import open_file
136 from ubuntuone.storageprotocol import protocol_pb2, content_hash
137 from ubuntuone.storageprotocol import errors as protocol_errors
138 from ubuntuone.storageprotocol.client import (
139@@ -250,7 +251,8 @@
140 else:
141 return ('start - processMessage: %s',
142 str(message).replace("\n", " "))
143-
144+
145+
146 class LoggingStorageClient(ThrottlingStorageClient):
147 """A subclass of StorageClient that logs.
148
149@@ -2470,7 +2472,7 @@
150 hash=self.hash)
151
152 if getattr(self.tempfile, 'name', None) is not None:
153- self.tempfile = open(self.tempfile.name)
154+ self.tempfile = open_file(self.tempfile.name, 'rb')
155 f = UploadProgressWrapper(self.tempfile, self)
156
157 # access here the magic hash value, don't log anywhere, and
158
159=== modified file 'ubuntuone/syncdaemon/hash_queue.py'
160--- ubuntuone/syncdaemon/hash_queue.py 2011-02-28 15:53:29 +0000
161+++ ubuntuone/syncdaemon/hash_queue.py 2011-07-11 20:34:03 +0000
162@@ -115,7 +115,7 @@
163 size = 0
164 try:
165 initial_stat = stat_path(path)
166- with open_file(path) as fh:
167+ with open_file(path, 'rb') as fh:
168 while True:
169 # stop hashing if path_to_cancel == path or _stopped is True
170 with self.mutex:
171@@ -196,8 +196,7 @@
172
173
174 class UniqueQueue(Queue.Queue):
175- """Variant of Queue that only inserts unique items in the Queue
176- """
177+ """Variant of Queue that only inserts unique items in the Queue."""
178
179 def __init__(self, *args, **kwargs):
180 """create the instance"""

Subscribers

People subscribed via source and target branches