/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 breezy/tests/test_transport.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-23 23:51:34 UTC
  • mto: This revision was merged to the branch mainline in revision 7219.
  • Revision ID: jelmer@jelmer.uk-20181123235134-rbvofmn792ogx2ix
Move location_to_url to its own module.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    transport,
29
29
    urlutils,
30
30
    )
31
 
from ..directory_service import directories
32
31
from ..sixish import (
33
32
    BytesIO,
34
33
    )
37
36
    fakenfs,
38
37
    http,
39
38
    local,
40
 
    location_to_url,
41
39
    memory,
42
40
    pathfilter,
43
41
    readonly,
1107
1105
        result = http.unhtml_roughly(fake_html)
1108
1106
        self.assertEqual(len(result), 1000)
1109
1107
        self.assertStartsWith(result, " something!")
1110
 
 
1111
 
 
1112
 
class SomeDirectory(object):
1113
 
 
1114
 
    def look_up(self, name, url):
1115
 
        return "http://bar"
1116
 
 
1117
 
 
1118
 
class TestLocationToUrl(tests.TestCase):
1119
 
 
1120
 
    def get_base_location(self):
1121
 
        path = osutils.abspath('/foo/bar')
1122
 
        if path.startswith('/'):
1123
 
            url = 'file://%s' % (path,)
1124
 
        else:
1125
 
            # On Windows, abspaths start with the drive letter, so we have to
1126
 
            # add in the extra '/'
1127
 
            url = 'file:///%s' % (path,)
1128
 
        return path, url
1129
 
 
1130
 
    def test_regular_url(self):
1131
 
        self.assertEqual("file://foo", location_to_url("file://foo"))
1132
 
 
1133
 
    def test_directory(self):
1134
 
        directories.register("bar:", SomeDirectory, "Dummy directory")
1135
 
        self.addCleanup(directories.remove, "bar:")
1136
 
        self.assertEqual("http://bar", location_to_url("bar:"))
1137
 
 
1138
 
    def test_unicode_url(self):
1139
 
        self.assertRaises(urlutils.InvalidURL, location_to_url,
1140
 
                          b"http://fo/\xc3\xaf".decode("utf-8"))
1141
 
 
1142
 
    def test_unicode_path(self):
1143
 
        path, url = self.get_base_location()
1144
 
        location = path + b"\xc3\xaf".decode("utf-8")
1145
 
        url += '%C3%AF'
1146
 
        self.assertEqual(url, location_to_url(location))
1147
 
 
1148
 
    def test_path(self):
1149
 
        path, url = self.get_base_location()
1150
 
        self.assertEqual(url, location_to_url(path))
1151
 
 
1152
 
    def test_relative_file_url(self):
1153
 
        self.assertEqual(urlutils.local_path_to_url(".") + "/bar",
1154
 
                         location_to_url("file:bar"))
1155
 
 
1156
 
    def test_absolute_file_url(self):
1157
 
        self.assertEqual("file:///bar", location_to_url("file:/bar"))