1
1
# ubuntuone.storageprotocol.tests.test_upload_offset -
2
# tests for the offset argument of BeginContent messages of upload requests
2
# tests for the PutContent request
4
4
# Author: John R. Lenton <john.lenton@canonical.com>
5
# Guillermo Gonzalez <guillermo.gonzalez@canonical.com>
6
# Copyright (C) 2009 Canonical
7
# Copyright (C) 2009-2011 Canonical
8
9
# This program is free software: you can redistribute it and/or modify it
9
10
# under the terms of the GNU Affero General Public License version 3,
17
18
# You should have received a copy of the GNU Affero General Public License
18
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""Tests for begin_content.offset"""
20
"""Tests for PutContent request"""
24
from StringIO import StringIO
26
from twisted.test.proto_helpers import StringTransport
22
28
from ubuntuone.storageprotocol.request import RequestHandler
23
29
from ubuntuone.storageprotocol.client import PutContent
24
30
from ubuntuone.storageprotocol import protocol_pb2
78
84
message.type = protocol_pb2.Message.BEGIN_CONTENT
80
86
pc.processMessage(message)
89
class TestUploadId(unittest.TestCase):
90
"""Tests for BEGIN_CONTENT and PUT_CONTENT upload_id attribute."""
93
unittest.TestCase.setUp(self)
94
transport = StringTransport()
95
self.protocol = RequestHandler()
96
self.protocol.transport = transport
98
def test_server_upload_id(self):
99
"""Test that, if the server specify an upload_id, we save it."""
102
pc = PutContent(self.protocol, 'share', 'node', '', '',
103
0, 0, 0, StringIO(''), upload_id_cb=called.append)
104
message = protocol_pb2.Message()
105
message.type = protocol_pb2.Message.BEGIN_CONTENT
106
message.begin_content.upload_id = upload_id
108
pc.processMessage(message)
109
self.assertEqual(len(called), 1)
110
self.assertEqual(called[0], 'foo')
112
def test_server_upload_id_no_cb(self):
113
"""Test that, if the server specify an upload_id, we save it.
115
Only if we have the upload_id_cb defined.
118
# just to check something
121
fd.seek(offset) # this is really all I care about
127
pc = PutContent(self.protocol, 'share', 'node', '', '',
129
message = protocol_pb2.Message()
130
message.type = protocol_pb2.Message.BEGIN_CONTENT
131
message.begin_content.upload_id = upload_id
132
message.begin_content.offset = offset
134
pc.processMessage(message)
136
def test_server_upload_id_none(self):
137
"""Test that if there is no upload_id we ignore it."""
139
pc = PutContent(self.protocol, 'share', 'node', '', '',
140
0, 0, 0, StringIO(''), upload_id_cb=called.append)
141
message = protocol_pb2.Message()
142
message.type = protocol_pb2.Message.BEGIN_CONTENT
144
pc.processMessage(message)
145
self.assertEqual(len(called), 0)
147
def test_client_upload_id(self):
148
"""Test that, we send the upload id to the server."""
149
pc = PutContent(self.protocol, 'share', 'node', '', '',
150
0, 0, 0, StringIO(''), upload_id='foo')
152
pc_msg = protocol_pb2.Message()
153
pc_msg.ParseFromString(self.protocol.transport.value())
154
self.assertEqual(pc_msg.put_content.upload_id, 'foo')