17
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
"""Tests for the protocol client."""
23
25
from twisted.internet.defer import Deferred
26
from twisted.trial.unittest import TestCase as TwistedTestCase
25
28
from ubuntuone.storageprotocol import protocol_pb2, sharersp, delta, request
26
29
from ubuntuone.storageprotocol.client import (
27
StorageClient, CreateUDF, ListVolumes, DeleteVolume, GetDelta,
28
Authenticate, MakeFile, MakeDir, PutContent, Move, Unlink)
30
StorageClient, CreateUDF, ListVolumes, DeleteVolume, GetDelta, Unlink,
31
Authenticate, MakeFile, MakeDir, PutContent, Move, BytesMessageProducer,
29
33
from ubuntuone.storageprotocol import volumes
30
34
from tests import test_delta_info
169
173
self.client = None
175
def test_init_maxpayloadsize(self):
176
"""Get the value from the constant at init time."""
177
self.assertEqual(self.client.max_payload_size,
178
request.MAX_PAYLOAD_SIZE)
171
180
# client to server
172
181
def test_client_get_delta(self):
173
182
"""Get a delta."""
805
814
return Move(FakedProtocol(), None, None, None, None)
817
class PutContentTestCase(TwistedTestCase):
818
"""Test cases for PutContent op."""
820
def test_max_payload_size(self):
821
"""Get the value from the protocol."""
822
self.protocol = FakedProtocol()
823
assert 12345 != self.protocol.max_payload_size
824
self.protocol.max_payload_size = 12345
825
pc = PutContent(self.protocol, None, None, None, None,
826
None, None, None, None)
827
self.assertEqual(pc.max_payload_size, 12345)
829
def test_bytesmessageproducer_maxpayloadsize(self):
830
"""The producer uses the payload size from the request."""
831
# set up the PutContent
832
pc = PutContent(FakedProtocol(), None, None, None, None,
833
None, None, None, None)
834
assert 12345 != pc.max_payload_size
835
pc.max_payload_size = 12345
837
# set up the producer
838
fake_file = StringIO.StringIO(os.urandom(100000))
839
producer = BytesMessageProducer(pc, fake_file, 0)
840
producer.producing = True
842
# set up a function to check and go!
847
self.assertEqual(len(message.bytes.bytes), 12345)
848
producer.producing = False
851
pc.sendMessage = check
808
856
if __name__ == '__main__':