/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_transport.py

1st cut merge of bzr.dev r3907

Show diffs side-by-side

added added

removed removed

Lines of Context:
992
992
        smart_server.start_background_thread('-' + self.id())
993
993
        try:
994
994
            transport = remote.RemoteTCPTransport(smart_server.get_url())
995
 
            try:
996
 
                transport.get('something')
997
 
            except errors.TransportError, e:
998
 
                self.assertContainsRe(str(e), 'some random exception')
999
 
            else:
1000
 
                self.fail("get did not raise expected error")
 
995
            err = self.assertRaises(errors.UnknownErrorFromSmartServer,
 
996
                transport.get, 'something')
 
997
            self.assertContainsRe(str(err), 'some random exception')
1001
998
            transport.disconnect()
1002
999
        finally:
1003
1000
            smart_server.stop_background_thread()
1091
1088
        # asked for by the client. This gives meaningful and unsurprising errors
1092
1089
        # for users.
1093
1090
        self._captureVar('BZR_NO_SMART_VFS', None)
1094
 
        try:
1095
 
            self.transport.get('not%20a%20file')
1096
 
        except errors.NoSuchFile, e:
1097
 
            self.assertEqual('not%20a%20file', e.path)
1098
 
        else:
1099
 
            self.fail("get did not raise expected error")
 
1091
        err = self.assertRaises(
 
1092
            errors.NoSuchFile, self.transport.get, 'not%20a%20file')
 
1093
        self.assertEqual('not%20a%20file', err.path)
1100
1094
 
1101
1095
    def test_simple_clone_conn(self):
1102
1096
        """Test that cloning reuses the same connection."""
1400
1394
        client_medium = medium.SmartSimplePipesClientMedium(None, None, 'base')
1401
1395
        transport = remote.RemoteTransport(
1402
1396
            'bzr://localhost/', medium=client_medium)
 
1397
        err = errors.ErrorFromSmartServer(("ReadOnlyError", ))
1403
1398
        self.assertRaises(errors.TransportNotPossible,
1404
 
            transport._translate_error, ("ReadOnlyError", ))
 
1399
            transport._translate_error, err)
1405
1400
 
1406
1401
 
1407
1402
class TestSmartProtocol(tests.TestCase):
2267
2262
    def test_construct_version_three_server_protocol(self):
2268
2263
        smart_protocol = protocol.ProtocolThreeDecoder(None)
2269
2264
        self.assertEqual('', smart_protocol.unused_data)
2270
 
        self.assertEqual('', smart_protocol._in_buffer)
 
2265
        self.assertEqual([], smart_protocol._in_buffer_list)
 
2266
        self.assertEqual(0, smart_protocol._in_buffer_len)
2271
2267
        self.assertFalse(smart_protocol._has_dispatched)
2272
2268
        # The protocol starts by expecting four bytes, a length prefix for the
2273
2269
        # headers.
3361
3357
        # requests for child URLs of that to the original URL.  i.e., we want to
3362
3358
        # POST to "bzr+http://host/foo/.bzr/smart" and never something like
3363
3359
        # "bzr+http://host/foo/.bzr/branch/.bzr/smart".  So, a cloned
3364
 
        # RemoteHTTPTransport remembers the initial URL, and adjusts the relpaths
3365
 
        # it sends in smart requests accordingly.
 
3360
        # RemoteHTTPTransport remembers the initial URL, and adjusts the
 
3361
        # relpaths it sends in smart requests accordingly.
3366
3362
        base_transport = remote.RemoteHTTPTransport('bzr+http://host/path')
3367
3363
        new_transport = base_transport.clone('child_dir')
3368
3364
        self.assertEqual(base_transport._http_transport,
3388
3384
            'c/',
3389
3385
            new_transport._client.remote_path_from_transport(new_transport))
3390
3386
 
3391
 
        
 
3387
    def test__redirect_to(self):
 
3388
        t = remote.RemoteHTTPTransport('bzr+http://www.example.com/foo')
 
3389
        r = t._redirected_to('http://www.example.com/foo',
 
3390
                             'http://www.example.com/bar')
 
3391
        self.assertEquals(type(r), type(t))
 
3392
 
 
3393
    def test__redirect_sibling_protocol(self):
 
3394
        t = remote.RemoteHTTPTransport('bzr+http://www.example.com/foo')
 
3395
        r = t._redirected_to('http://www.example.com/foo',
 
3396
                             'https://www.example.com/bar')
 
3397
        self.assertEquals(type(r), type(t))
 
3398
        self.assertStartsWith(r.base, 'bzr+https')
 
3399
 
 
3400
    def test__redirect_to_with_user(self):
 
3401
        t = remote.RemoteHTTPTransport('bzr+http://joe@www.example.com/foo')
 
3402
        r = t._redirected_to('http://www.example.com/foo',
 
3403
                             'http://www.example.com/bar')
 
3404
        self.assertEquals(type(r), type(t))
 
3405
        self.assertEquals('joe', t._user)
 
3406
        self.assertEquals(t._user, r._user)
 
3407
 
 
3408
    def test_redirected_to_same_host_different_protocol(self):
 
3409
        t = remote.RemoteHTTPTransport('bzr+http://joe@www.example.com/foo')
 
3410
        r = t._redirected_to('http://www.example.com/foo',
 
3411
                             'ftp://www.example.com/foo')
 
3412
        self.assertNotEquals(type(r), type(t))
 
3413
 
 
3414
 
3392
3415
# TODO: Client feature that does get_bundle and then installs that into a
3393
3416
# branch; this can be used in place of the regular pull/fetch operation when
3394
3417
# coming from a smart server.