79
75
_clear_protocol_handlers()
80
76
register_transport_proto('foo')
81
register_lazy_transport('foo', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler')
77
register_lazy_transport('foo', 'bzrlib.tests.test_transport',
78
'TestTransport.SampleHandler')
82
79
register_transport_proto('bar')
83
register_lazy_transport('bar', 'bzrlib.tests.test_transport', 'TestTransport.SampleHandler')
84
self.assertEqual([SampleHandler.__module__, 'bzrlib.transport.chroot'],
80
register_lazy_transport('bar', 'bzrlib.tests.test_transport',
81
'TestTransport.SampleHandler')
82
self.assertEqual([SampleHandler.__module__,
83
'bzrlib.transport.chroot'],
85
84
_get_transport_modules())
87
86
_set_protocol_handlers(handlers)
716
715
self.assertIsNot(t1, t2)
719
class TestRemoteTCPTransport(TestCase):
720
"""Tests for bzr:// transport (RemoteTCPTransport)."""
722
def test_relpath_with_implicit_port(self):
723
"""Connected transports with the same URL are the same, even if the
726
So t.relpath(url) should always be '' if t.base is the same as url, or
727
if the only difference is that one explicitly specifies the default
728
port and the other doesn't specify a port.
730
t_implicit_port = RemoteTCPTransport('bzr://host.com/')
731
self.assertEquals('', t_implicit_port.relpath('bzr://host.com/'))
732
self.assertEquals('', t_implicit_port.relpath('bzr://host.com:4155/'))
733
t_explicit_port = RemoteTCPTransport('bzr://host.com:4155/')
734
self.assertEquals('', t_explicit_port.relpath('bzr://host.com/'))
735
self.assertEquals('', t_explicit_port.relpath('bzr://host.com:4155/'))
737
def test_construct_uses_default_port(self):
738
"""If no port is specified, then RemoteTCPTransport uses
741
t = get_transport('bzr://host.com/')
742
self.assertEquals(BZR_DEFAULT_PORT, t._port)
744
def test_url_omits_default_port(self):
745
"""If a RemoteTCPTransport uses the default port, then its base URL
748
This is like how ":80" is omitted from "http://example.com/".
750
t = get_transport('bzr://host.com:4155/')
751
self.assertEquals('bzr://host.com/', t.base)
753
def test_url_includes_non_default_port(self):
754
"""Non-default ports are included in the transport's URL.
756
Contrast this to `test_url_omits_default_port`.
758
t = get_transport('bzr://host.com:666/')
759
self.assertEquals('bzr://host.com:666/', t.base)
762
class SSHPortTestMixin(object):
763
"""Mixin class for testing SSH-based transports' use of ports in URLs.
765
Unlike other connected transports, SSH-based transports (sftp, bzr+ssh)
766
don't have a default port, because the user may have OpenSSH configured to
767
use a non-standard port.
770
def make_url(self, netloc):
771
"""Make a url for the given netloc, using the scheme defined on the
774
return '%s://%s/' % (self.scheme, netloc)
776
def test_relpath_with_implicit_port(self):
777
"""SSH-based transports with the same URL are the same.
779
Note than an unspecified port number is different to port 22 (because
780
OpenSSH may be configured to use a non-standard port).
782
So t.relpath(url) should always be '' if t.base is the same as url, but
783
raise PathNotChild if the ports in t and url are not both specified (or
786
url_implicit_port = self.make_url('host.com')
787
url_explicit_port = self.make_url('host.com:22')
789
t_implicit_port = get_transport(url_implicit_port)
790
self.assertEquals('', t_implicit_port.relpath(url_implicit_port))
792
PathNotChild, t_implicit_port.relpath, url_explicit_port)
794
t_explicit_port = get_transport(url_explicit_port)
796
PathNotChild, t_explicit_port.relpath, url_implicit_port)
797
self.assertEquals('', t_explicit_port.relpath(url_explicit_port))
799
def test_construct_with_no_port(self):
800
"""If no port is specified, then the SSH-based transport's _port will
803
t = get_transport(self.make_url('host.com'))
804
self.assertEquals(None, t._port)
806
def test_url_with_no_port(self):
807
"""If no port was specified, none is shown in the base URL."""
808
t = get_transport(self.make_url('host.com'))
809
self.assertEquals(self.make_url('host.com'), t.base)
811
def test_url_includes_port(self):
812
"""An SSH-based transport's base will show the port if one was
813
specified, even if that port is 22, because we do not assume 22 is the
816
# 22 is the "standard" port for SFTP.
817
t = get_transport(self.make_url('host.com:22'))
818
self.assertEquals(self.make_url('host.com:22'), t.base)
819
# 666 is not a standard port.
820
t = get_transport(self.make_url('host.com:666'))
821
self.assertEquals(self.make_url('host.com:666'), t.base)
824
class SFTPTransportPortTest(TestCase, SSHPortTestMixin):
825
"""Tests for sftp:// transport (SFTPTransport)."""
830
class BzrSSHTransportPortTest(TestCase, SSHPortTestMixin):
831
"""Tests for bzr+ssh:// transport (RemoteSSHTransport)."""
836
718
class TestTransportTrace(TestCase):
838
720
def test_get(self):