/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
7204.2.1 by Jelmer Vernooij
Move location_to_url to its own module.
1
# Copyright (C) 2005-2011, 2015, 2016 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Tests for breezy.location."""
18
19
from .. import (
20
    osutils,
21
    tests,
22
    urlutils,
23
    )
24
from ..directory_service import directories
25
from ..location import (
26
    location_to_url,
27
    )
28
29
30
class SomeDirectory(object):
31
32
    def look_up(self, name, url):
33
        return "http://bar"
34
35
36
class TestLocationToUrl(tests.TestCase):
37
38
    def get_base_location(self):
39
        path = osutils.abspath('/foo/bar')
40
        if path.startswith('/'):
41
            url = 'file://%s' % (path,)
42
        else:
43
            # On Windows, abspaths start with the drive letter, so we have to
44
            # add in the extra '/'
45
            url = 'file:///%s' % (path,)
46
        return path, url
47
48
    def test_regular_url(self):
49
        self.assertEqual("file://foo", location_to_url("file://foo"))
50
51
    def test_directory(self):
52
        directories.register("bar:", SomeDirectory, "Dummy directory")
53
        self.addCleanup(directories.remove, "bar:")
54
        self.assertEqual("http://bar", location_to_url("bar:"))
55
56
    def test_unicode_url(self):
57
        self.assertRaises(urlutils.InvalidURL, location_to_url,
58
                          b"http://fo/\xc3\xaf".decode("utf-8"))
59
60
    def test_unicode_path(self):
61
        path, url = self.get_base_location()
62
        location = path + b"\xc3\xaf".decode("utf-8")
63
        url += '%C3%AF'
64
        self.assertEqual(url, location_to_url(location))
65
66
    def test_path(self):
67
        path, url = self.get_base_location()
68
        self.assertEqual(url, location_to_url(path))
69
70
    def test_relative_file_url(self):
71
        self.assertEqual(urlutils.local_path_to_url(".") + "/bar",
72
                         location_to_url("file:bar"))
73
74
    def test_absolute_file_url(self):
75
        self.assertEqual("file:///bar", location_to_url("file:/bar"))