~ubuntu-branches/ubuntu/precise/ubuntuone-storage-protocol/precise-security

« back to all changes in this revision

Viewing changes to tests/test_client.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-04-27 13:58:59 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110427135859-gp92qwvomwkcuqit
Tags: 1.6.1-0ubuntu1
* New upstream release.
  - Uploads fail due to starvation (LP: #767466)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
"""Tests for the protocol client."""
19
19
 
 
20
import StringIO
 
21
import os
20
22
import unittest
21
23
import uuid
22
24
 
23
25
from twisted.internet.defer import Deferred
 
26
from twisted.trial.unittest import TestCase as TwistedTestCase
24
27
 
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,
 
32
)
29
33
from ubuntuone.storageprotocol import volumes
30
34
from tests import test_delta_info
31
35
 
168
172
        """Clean up."""
169
173
        self.client = None
170
174
 
 
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)
 
179
 
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)
806
815
 
807
816
 
 
817
class PutContentTestCase(TwistedTestCase):
 
818
    """Test cases for PutContent op."""
 
819
 
 
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)
 
828
 
 
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
 
836
 
 
837
        # set up the producer
 
838
        fake_file = StringIO.StringIO(os.urandom(100000))
 
839
        producer = BytesMessageProducer(pc, fake_file, 0)
 
840
        producer.producing = True
 
841
 
 
842
        # set up a function to check and go!
 
843
        d = Deferred()
 
844
 
 
845
        def check(message):
 
846
            """Check."""
 
847
            self.assertEqual(len(message.bytes.bytes), 12345)
 
848
            producer.producing = False
 
849
            d.callback(True)
 
850
 
 
851
        pc.sendMessage = check
 
852
        producer.go()
 
853
        return d
 
854
 
 
855
 
808
856
if __name__ == '__main__':
809
857
    unittest.main()