~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_transport.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-29 08:46:23 UTC
  • mto: (2018.18.6 hpss-faster-copy)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: andrew.bennetts@canonical.com-20070329084623-ruqx0po8q3lxw0b7
Be strict about unicode passed to transport.put_{bytes,file} and SmartClient.call_with_body_bytes, fixing part of TestLockableFiles_RemoteLockDir.test_read_write.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1307
1307
            [('a', 'b', '34')])
1308
1308
 
1309
1309
    def test_client_call_with_body_bytes_uploads(self):
1310
 
        # protocol.call_with_upload should length-prefix the bytes onto the 
 
1310
        # protocol.call_with_body_bytes should length-prefix the bytes onto the
1311
1311
        # wire.
1312
1312
        expected_bytes = "foo\n7\nabcdefgdone\n"
1313
1313
        input = StringIO("\n")
1382
1382
            errors.ReadingCompleted, smart_protocol.read_body_bytes)
1383
1383
 
1384
1384
 
 
1385
class TestSmartClientUnicode(tests.TestCase):
 
1386
    """SmartClient tests for unicode arguments.
 
1387
 
 
1388
    Unicode arguments to call_with_body_bytes are not correct (remote method
 
1389
    names, arguments, and bodies must all be expressed as byte strings), but
 
1390
    SmartClient should gracefully reject them, rather than getting into a broken
 
1391
    state that prevents future correct calls from working.  That is, it should
 
1392
    be possible to issue more requests on the medium afterwards, rather than
 
1393
    allowing one bad call to call_with_body_bytes to cause later calls to
 
1394
    mysteriously fail with TooManyConcurrentRequests.
 
1395
    """
 
1396
 
 
1397
    def assertCallDoesNotBreakMedium(self, method, args, body):
 
1398
        """Call a medium with the given method, args and body, then assert that
 
1399
        the medium is left in a sane state, i.e. is capable of allowing further
 
1400
        requests.
 
1401
        """
 
1402
        input = StringIO("\n")
 
1403
        output = StringIO()
 
1404
        client_medium = medium.SmartSimplePipesClientMedium(input, output)
 
1405
        smart_client = client.SmartClient(client_medium)
 
1406
        self.assertRaises(TypeError,
 
1407
            smart_client.call_with_body_bytes, method, args, body)
 
1408
        self.assertEqual("", output.getvalue())
 
1409
        self.assertEqual(None, client_medium._current_request)
 
1410
 
 
1411
    def test_call_with_body_bytes_unicode_method(self):
 
1412
        self.assertCallDoesNotBreakMedium(u'method', ('args',), 'body')
 
1413
 
 
1414
    def test_call_with_body_bytes_unicode_args(self):
 
1415
        self.assertCallDoesNotBreakMedium('method', (u'args',), 'body')
 
1416
 
 
1417
    def test_call_with_body_bytes_unicode_body(self):
 
1418
        self.assertCallDoesNotBreakMedium('method', ('args',), u'body')
 
1419
 
 
1420
 
1385
1421
class LengthPrefixedBodyDecoder(tests.TestCase):
1386
1422
 
1387
1423
    # XXX: TODO: make accept_reading_trailer invoke translate_response or