~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-09 17:04:46 UTC
  • mfrom: (6055.1.3 822571-bzr-home-unicode)
  • Revision ID: pqm@pqm.ubuntu.com-20110809170446-f1wc1a8fhgnxi4cn
(vila) Decode BZR_HOME with fs encoding to allow unicode homes. (Vincent
 Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
        self.assertRaises(errors.ReadError, a_file.read, 40)
139
139
        a_file.close()
140
140
 
 
141
    def test__combine_paths(self):
 
142
        t = transport.Transport('/')
 
143
        self.assertEqual('/home/sarah/project/foo',
 
144
                         t._combine_paths('/home/sarah', 'project/foo'))
 
145
        self.assertEqual('/etc',
 
146
                         t._combine_paths('/home/sarah', '../../etc'))
 
147
        self.assertEqual('/etc',
 
148
                         t._combine_paths('/home/sarah', '../../../etc'))
 
149
        self.assertEqual('/etc',
 
150
                         t._combine_paths('/home/sarah', '/etc'))
 
151
 
141
152
    def test_local_abspath_non_local_transport(self):
142
153
        # the base implementation should throw
143
154
        t = memory.MemoryTransport()
701
712
        self.assertIsInstance(t, local.LocalTransport)
702
713
        self.assertEquals(t.base.rstrip("/"), url)
703
714
 
704
 
    def test_with_url_and_segment_parameters(self):
705
 
        url = urlutils.local_path_to_url(self.test_dir)+",branch=foo"
706
 
        t = transport.get_transport_from_url(url)
707
 
        self.assertIsInstance(t, local.LocalTransport)
708
 
        self.assertEquals(t.base.rstrip("/"), url)
709
 
        with open(os.path.join(self.test_dir, "afile"), 'w') as f:
710
 
            f.write("data")
711
 
        self.assertTrue(t.has("afile"))
712
 
 
713
715
 
714
716
class TestLocalTransports(tests.TestCase):
715
717
 
782
784
    def test_parse_url(self):
783
785
        t = transport.ConnectedTransport(
784
786
            'http://simple.example.com/home/source')
785
 
        self.assertEquals(t._parsed_url.host, 'simple.example.com')
786
 
        self.assertEquals(t._parsed_url.port, None)
787
 
        self.assertEquals(t._parsed_url.path, '/home/source/')
788
 
        self.assertTrue(t._parsed_url.user is None)
789
 
        self.assertTrue(t._parsed_url.password is None)
 
787
        self.assertEquals(t._host, 'simple.example.com')
 
788
        self.assertEquals(t._port, None)
 
789
        self.assertEquals(t._path, '/home/source/')
 
790
        self.assertTrue(t._user is None)
 
791
        self.assertTrue(t._password is None)
790
792
 
791
793
        self.assertEquals(t.base, 'http://simple.example.com/home/source/')
792
794
 
793
795
    def test_parse_url_with_at_in_user(self):
794
796
        # Bug 228058
795
797
        t = transport.ConnectedTransport('ftp://user@host.com@www.host.com/')
796
 
        self.assertEquals(t._parsed_url.user, 'user@host.com')
 
798
        self.assertEquals(t._user, 'user@host.com')
797
799
 
798
800
    def test_parse_quoted_url(self):
799
801
        t = transport.ConnectedTransport(
800
802
            'http://ro%62ey:h%40t@ex%41mple.com:2222/path')
801
 
        self.assertEquals(t._parsed_url.host, 'exAmple.com')
802
 
        self.assertEquals(t._parsed_url.port, 2222)
803
 
        self.assertEquals(t._parsed_url.user, 'robey')
804
 
        self.assertEquals(t._parsed_url.password, 'h@t')
805
 
        self.assertEquals(t._parsed_url.path, '/path/')
 
803
        self.assertEquals(t._host, 'exAmple.com')
 
804
        self.assertEquals(t._port, 2222)
 
805
        self.assertEquals(t._user, 'robey')
 
806
        self.assertEquals(t._password, 'h@t')
 
807
        self.assertEquals(t._path, '/path/')
806
808
 
807
809
        # Base should not keep track of the password
808
 
        self.assertEquals(t.base, 'http://ro%62ey@ex%41mple.com:2222/path/')
 
810
        self.assertEquals(t.base, 'http://robey@exAmple.com:2222/path/')
809
811
 
810
812
    def test_parse_invalid_url(self):
811
813
        self.assertRaises(errors.InvalidURL,
835
837
 
836
838
    def test_connection_sharing_propagate_credentials(self):
837
839
        t = transport.ConnectedTransport('ftp://user@host.com/abs/path')
838
 
        self.assertEquals('user', t._parsed_url.user)
839
 
        self.assertEquals('host.com', t._parsed_url.host)
 
840
        self.assertEquals('user', t._user)
 
841
        self.assertEquals('host.com', t._host)
840
842
        self.assertIs(None, t._get_connection())
841
 
        self.assertIs(None, t._parsed_url.password)
 
843
        self.assertIs(None, t._password)
842
844
        c = t.clone('subdir')
843
845
        self.assertIs(None, c._get_connection())
844
 
        self.assertIs(None, t._parsed_url.password)
 
846
        self.assertIs(None, t._password)
845
847
 
846
848
        # Simulate the user entering a password
847
849
        password = 'secret'
1056
1058
 
1057
1059
class TestLocationToUrl(tests.TestCase):
1058
1060
 
1059
 
    def get_base_location(self):
1060
 
        path = osutils.abspath('/foo/bar')
1061
 
        if path.startswith('/'):
1062
 
            url = 'file://%s' % (path,)
1063
 
        else:
1064
 
            # On Windows, abspaths start with the drive letter, so we have to
1065
 
            # add in the extra '/'
1066
 
            url = 'file:///%s' % (path,)
1067
 
        return path, url
1068
 
 
1069
1061
    def test_regular_url(self):
1070
1062
        self.assertEquals("file://foo", location_to_url("file://foo"))
1071
1063
 
1079
1071
            "http://fo/\xc3\xaf".decode("utf-8"))
1080
1072
 
1081
1073
    def test_unicode_path(self):
1082
 
        path, url = self.get_base_location()
1083
 
        location = path + "\xc3\xaf".decode("utf-8")
1084
 
        url += '%C3%AF'
1085
 
        self.assertEquals(url, location_to_url(location))
 
1074
        self.assertEquals("file:///foo/bar%C3%AF",
 
1075
            location_to_url("/foo/bar\xc3\xaf".decode("utf-8")))
1086
1076
 
1087
1077
    def test_path(self):
1088
 
        path, url = self.get_base_location()
1089
 
        self.assertEquals(url, location_to_url(path))
 
1078
        self.assertEquals("file:///foo/bar", location_to_url("/foo/bar"))
1090
1079
 
1091
1080
    def test_relative_file_url(self):
1092
1081
        self.assertEquals(urlutils.local_path_to_url(".") + "/bar",