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

Proposed by Facundo Batista on 2016-10-11
Status: Merged
Approved by: Natalia Bidart on 2016-10-12
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 2016-10-11 Approve on 2016-10-12
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.
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
=== modified file 'tests/test_putcontent.py'
--- tests/test_putcontent.py 2012-04-27 13:02:32 +0000
+++ tests/test_putcontent.py 2016-10-11 19:04:38 +0000
@@ -45,9 +45,14 @@
4545
4646
47class TestOffset(unittest.TestCase):47class TestOffset(unittest.TestCase):
48 """48 """Tests for BEGIN_CONTENT's offset attribute."""
49 Tests for BEGIN_CONTENT's offset attribute49
50 """50 def setUp(self):
51 super(TestOffset, self).setUp()
52 transport = StringTransport()
53 self.protocol = StorageClient()
54 self.protocol.transport = transport
55
51 def test_offset(self):56 def test_offset(self):
52 """57 """
53 Test that, if the server's BEGIN_CONTENT message specifies an offset,58 Test that, if the server's BEGIN_CONTENT message specifies an offset,
@@ -98,12 +103,28 @@
98 pc.start()103 pc.start()
99 pc.processMessage(message)104 pc.processMessage(message)
100105
106 def test_callback(self):
107 """Test that, if the server specify an offset, we call back with it."""
108 upload_id = 'foo'
109 offset = 123456
110 called = []
111 pc = PutContent(self.protocol, 'share', 'node', '', '', 0, 0, 0,
112 StringIO(''), upload_id_cb=lambda *a: called.append(a))
113 message = protocol_pb2.Message()
114 message.type = protocol_pb2.Message.BEGIN_CONTENT
115 message.begin_content.upload_id = upload_id
116 message.begin_content.offset = offset
117 pc.start()
118 pc.processMessage(message)
119 self.assertEqual(len(called), 1)
120 self.assertEqual(called[0], (upload_id, offset))
121
101122
102class TestUploadId(unittest.TestCase):123class TestUploadId(unittest.TestCase):
103 """Tests for BEGIN_CONTENT and PUT_CONTENT upload_id attribute."""124 """Tests for BEGIN_CONTENT and PUT_CONTENT upload_id attribute."""
104125
105 def setUp(self):126 def setUp(self):
106 unittest.TestCase.setUp(self)127 super(TestUploadId, self).setUp()
107 transport = StringTransport()128 transport = StringTransport()
108 self.protocol = StorageClient()129 self.protocol = StorageClient()
109 self.protocol.transport = transport130 self.protocol.transport = transport
@@ -112,15 +133,16 @@
112 """Test that, if the server specify an upload_id, we save it."""133 """Test that, if the server specify an upload_id, we save it."""
113 upload_id = "foo"134 upload_id = "foo"
114 called = []135 called = []
115 pc = PutContent(self.protocol, 'share', 'node', '', '',136 pc = PutContent(self.protocol, 'share', 'node', '', '', 0, 0, 0,
116 0, 0, 0, StringIO(''), upload_id_cb=called.append)137 StringIO(''), upload_id_cb=lambda *a: called.append(a))
117 message = protocol_pb2.Message()138 message = protocol_pb2.Message()
118 message.type = protocol_pb2.Message.BEGIN_CONTENT139 message.type = protocol_pb2.Message.BEGIN_CONTENT
119 message.begin_content.upload_id = upload_id140 message.begin_content.upload_id = upload_id
141 message.begin_content.offset = 0
120 pc.start()142 pc.start()
121 pc.processMessage(message)143 pc.processMessage(message)
122 self.assertEqual(len(called), 1)144 self.assertEqual(len(called), 1)
123 self.assertEqual(called[0], 'foo')145 self.assertEqual(called[0], ('foo', 0))
124146
125 def test_server_upload_id_no_cb(self):147 def test_server_upload_id_no_cb(self):
126 """Test that, if the server specify an upload_id, we save it.148 """Test that, if the server specify an upload_id, we save it.
127149
=== modified file 'ubuntuone/storageprotocol/client.py'
--- ubuntuone/storageprotocol/client.py 2016-09-19 02:00:32 +0000
+++ ubuntuone/storageprotocol/client.py 2016-10-11 19:04:38 +0000
@@ -1229,9 +1229,9 @@
1229 """Handle messages."""1229 """Handle messages."""
1230 if message.type == protocol_pb2.Message.BEGIN_CONTENT:1230 if message.type == protocol_pb2.Message.BEGIN_CONTENT:
1231 # call the upload_id_cb (if the upload_id it's in the message)1231 # call the upload_id_cb (if the upload_id it's in the message)
1232 if message.begin_content.upload_id \1232 if message.begin_content.upload_id and self.upload_id_cb:
1233 and self.upload_id_cb:1233 self.upload_id_cb(message.begin_content.upload_id,
1234 self.upload_id_cb(message.begin_content.upload_id)1234 message.begin_content.offset)
1235 message_producer = BytesMessageProducer(1235 message_producer = BytesMessageProducer(
1236 self, self.fd, message.begin_content.offset)1236 self, self.fd, message.begin_content.offset)
1237 self.registerProducer(message_producer, streaming=True)1237 self.registerProducer(message_producer, streaming=True)

Subscribers

People subscribed via source and target branches

to all changes: