1
# Copyright (C) 2005-2011, 2015, 2016 Canonical Ltd
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.
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.
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
17
"""Tests for breezy.location."""
24
from ..directory_service import directories
25
from ..location import (
30
class SomeDirectory(object):
32
def look_up(self, name, url):
36
class TestLocationToUrl(tests.TestCase):
38
def get_base_location(self):
39
path = osutils.abspath('/foo/bar')
40
if path.startswith('/'):
41
url = 'file://%s' % (path,)
43
# On Windows, abspaths start with the drive letter, so we have to
44
# add in the extra '/'
45
url = 'file:///%s' % (path,)
48
def test_regular_url(self):
49
self.assertEqual("file://foo", location_to_url("file://foo"))
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:"))
56
def test_unicode_url(self):
57
self.assertRaises(urlutils.InvalidURL, location_to_url,
58
b"http://fo/\xc3\xaf".decode("utf-8"))
60
def test_unicode_path(self):
61
path, url = self.get_base_location()
62
location = path + b"\xc3\xaf".decode("utf-8")
64
self.assertEqual(url, location_to_url(location))
67
path, url = self.get_base_location()
68
self.assertEqual(url, location_to_url(path))
70
def test_relative_file_url(self):
71
self.assertEqual(urlutils.local_path_to_url(".") + "/bar",
72
location_to_url("file:bar"))
74
def test_absolute_file_url(self):
75
self.assertEqual("file:///bar", location_to_url("file:/bar"))