Merge lp:~facundo/magicicada-protocol/callback-upload-offset into lp:magicicada-protocol

Proposed by Facundo Batista
Status: Merged
Approved by: Natalia Bidart
Approved revision: 168
Merged at revision: 168
Proposed branch: lp:~facundo/magicicada-protocol/callback-upload-offset
Merge into: lp:magicicada-protocol
Diff against target: 88 lines (+32/-10)
2 files modified
tests/test_putcontent.py (+29/-7)
ubuntuone/storageprotocol/client.py (+3/-3)
To merge this branch: bzr merge lp:~facundo/magicicada-protocol/callback-upload-offset
Reviewer Review Type Date Requested Status
Natalia Bidart Approve
Review via email: mp+308180@code.launchpad.net

Commit message

Callback on BEGIN_CONTENT also with offset.

Description of the change

Callback on BEGIN_CONTENT also with offset.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/test_putcontent.py'
2--- tests/test_putcontent.py 2012-04-27 13:02:32 +0000
3+++ tests/test_putcontent.py 2016-10-11 19:04:38 +0000
4@@ -45,9 +45,14 @@
5
6
7 class TestOffset(unittest.TestCase):
8- """
9- Tests for BEGIN_CONTENT's offset attribute
10- """
11+ """Tests for BEGIN_CONTENT's offset attribute."""
12+
13+ def setUp(self):
14+ super(TestOffset, self).setUp()
15+ transport = StringTransport()
16+ self.protocol = StorageClient()
17+ self.protocol.transport = transport
18+
19 def test_offset(self):
20 """
21 Test that, if the server's BEGIN_CONTENT message specifies an offset,
22@@ -98,12 +103,28 @@
23 pc.start()
24 pc.processMessage(message)
25
26+ def test_callback(self):
27+ """Test that, if the server specify an offset, we call back with it."""
28+ upload_id = 'foo'
29+ offset = 123456
30+ called = []
31+ pc = PutContent(self.protocol, 'share', 'node', '', '', 0, 0, 0,
32+ StringIO(''), upload_id_cb=lambda *a: called.append(a))
33+ message = protocol_pb2.Message()
34+ message.type = protocol_pb2.Message.BEGIN_CONTENT
35+ message.begin_content.upload_id = upload_id
36+ message.begin_content.offset = offset
37+ pc.start()
38+ pc.processMessage(message)
39+ self.assertEqual(len(called), 1)
40+ self.assertEqual(called[0], (upload_id, offset))
41+
42
43 class TestUploadId(unittest.TestCase):
44 """Tests for BEGIN_CONTENT and PUT_CONTENT upload_id attribute."""
45
46 def setUp(self):
47- unittest.TestCase.setUp(self)
48+ super(TestUploadId, self).setUp()
49 transport = StringTransport()
50 self.protocol = StorageClient()
51 self.protocol.transport = transport
52@@ -112,15 +133,16 @@
53 """Test that, if the server specify an upload_id, we save it."""
54 upload_id = "foo"
55 called = []
56- pc = PutContent(self.protocol, 'share', 'node', '', '',
57- 0, 0, 0, StringIO(''), upload_id_cb=called.append)
58+ pc = PutContent(self.protocol, 'share', 'node', '', '', 0, 0, 0,
59+ StringIO(''), upload_id_cb=lambda *a: called.append(a))
60 message = protocol_pb2.Message()
61 message.type = protocol_pb2.Message.BEGIN_CONTENT
62 message.begin_content.upload_id = upload_id
63+ message.begin_content.offset = 0
64 pc.start()
65 pc.processMessage(message)
66 self.assertEqual(len(called), 1)
67- self.assertEqual(called[0], 'foo')
68+ self.assertEqual(called[0], ('foo', 0))
69
70 def test_server_upload_id_no_cb(self):
71 """Test that, if the server specify an upload_id, we save it.
72
73=== modified file 'ubuntuone/storageprotocol/client.py'
74--- ubuntuone/storageprotocol/client.py 2016-09-19 02:00:32 +0000
75+++ ubuntuone/storageprotocol/client.py 2016-10-11 19:04:38 +0000
76@@ -1229,9 +1229,9 @@
77 """Handle messages."""
78 if message.type == protocol_pb2.Message.BEGIN_CONTENT:
79 # call the upload_id_cb (if the upload_id it's in the message)
80- if message.begin_content.upload_id \
81- and self.upload_id_cb:
82- self.upload_id_cb(message.begin_content.upload_id)
83+ if message.begin_content.upload_id and self.upload_id_cb:
84+ self.upload_id_cb(message.begin_content.upload_id,
85+ message.begin_content.offset)
86 message_producer = BytesMessageProducer(
87 self, self.fd, message.begin_content.offset)
88 self.registerProducer(message_producer, streaming=True)

Subscribers

People subscribed via source and target branches

to all changes: