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 ( |
|
|
7268.11.1
by Jelmer Vernooij
Add rewrite_url hook. |
26 |
hooks as location_hooks, |
|
7204.2.1
by Jelmer Vernooij
Move location_to_url to its own module. |
27 |
location_to_url, |
|
7265.6.2
by Jelmer Vernooij
Support rsync-style URLs. |
28 |
rcp_location_to_url, |
|
7204.2.1
by Jelmer Vernooij
Move location_to_url to its own module. |
29 |
)
|
30 |
||
31 |
||
32 |
class SomeDirectory(object): |
|
33 |
||
|
7268.11.2
by Jelmer Vernooij
Add purpose argument. |
34 |
def look_up(self, name, url, purpose=None): |
|
7204.2.1
by Jelmer Vernooij
Move location_to_url to its own module. |
35 |
return "http://bar" |
36 |
||
37 |
||
38 |
class TestLocationToUrl(tests.TestCase): |
|
39 |
||
40 |
def get_base_location(self): |
|
41 |
path = osutils.abspath('/foo/bar') |
|
42 |
if path.startswith('/'): |
|
43 |
url = 'file://%s' % (path,) |
|
44 |
else: |
|
45 |
# On Windows, abspaths start with the drive letter, so we have to
|
|
46 |
# add in the extra '/'
|
|
47 |
url = 'file:///%s' % (path,) |
|
48 |
return path, url |
|
49 |
||
50 |
def test_regular_url(self): |
|
51 |
self.assertEqual("file://foo", location_to_url("file://foo")) |
|
52 |
||
53 |
def test_directory(self): |
|
54 |
directories.register("bar:", SomeDirectory, "Dummy directory") |
|
55 |
self.addCleanup(directories.remove, "bar:") |
|
56 |
self.assertEqual("http://bar", location_to_url("bar:")) |
|
57 |
||
58 |
def test_unicode_url(self): |
|
59 |
self.assertRaises(urlutils.InvalidURL, location_to_url, |
|
60 |
b"http://fo/\xc3\xaf".decode("utf-8")) |
|
61 |
||
62 |
def test_unicode_path(self): |
|
63 |
path, url = self.get_base_location() |
|
64 |
location = path + b"\xc3\xaf".decode("utf-8") |
|
65 |
url += '%C3%AF' |
|
66 |
self.assertEqual(url, location_to_url(location)) |
|
67 |
||
68 |
def test_path(self): |
|
69 |
path, url = self.get_base_location() |
|
70 |
self.assertEqual(url, location_to_url(path)) |
|
71 |
||
72 |
def test_relative_file_url(self): |
|
73 |
self.assertEqual(urlutils.local_path_to_url(".") + "/bar", |
|
74 |
location_to_url("file:bar")) |
|
75 |
||
76 |
def test_absolute_file_url(self): |
|
77 |
self.assertEqual("file:///bar", location_to_url("file:/bar")) |
|
|
7265.6.2
by Jelmer Vernooij
Support rsync-style URLs. |
78 |
|
|
7413.5.1
by Jelmer Vernooij
CVS pserver URLs indicate that the pserver protocol is not supported. |
79 |
def test_pserver(self): |
80 |
self.assertEqual( |
|
81 |
'cvs+pserver://anonymous@odessa.cvs.sourceforge.net/cvsroot/odess', |
|
82 |
location_to_url( |
|
83 |
':pserver:anonymous@odessa.cvs.sourceforge.net:/cvsroot/odess')) |
|
84 |
self.assertRaises(ValueError, location_to_url, ':pserver:blah') |
|
85 |
||
|
7490.149.1
by Jelmer Vernooij
Add support for converting extssh CVS URLs. |
86 |
def test_extssh(self): |
87 |
self.assertEqual( |
|
88 |
'cvs+ssh://anonymous@odessa.cvs.sourceforge.net/cvsroot/odess', |
|
89 |
location_to_url( |
|
90 |
':extssh:anonymous@odessa.cvs.sourceforge.net:/cvsroot/odess')) |
|
91 |
||
|
7490.75.1
by Jelmer Vernooij
some refactoring. |
92 |
def test_missing_scheme(self): |
93 |
self.skipTest('need clever guessing of scheme') |
|
94 |
self.assertEqual( |
|
95 |
'cvs+pserver://anonymous@savi.cvs.sourceforge.net:/cvsroot/savi', |
|
96 |
location_to_url( |
|
97 |
'anonymous@savi.cvs.sourceforge.net:/cvsroot/savi')) |
|
98 |
||
|
7265.6.2
by Jelmer Vernooij
Support rsync-style URLs. |
99 |
def test_rcp_url(self): |
100 |
self.assertEqual( |
|
101 |
"ssh://example.com/srv/git/bar", |
|
102 |
location_to_url("example.com:/srv/git/bar")) |
|
103 |
||
|
7268.11.1
by Jelmer Vernooij
Add rewrite_url hook. |
104 |
def test_rewrite_hook(self): |
105 |
self.assertEqual( |
|
106 |
'http://foo.example.com/blah', location_to_url('http://foo.example.com/blah')) |
|
|
7268.11.2
by Jelmer Vernooij
Add purpose argument. |
107 |
def rewrite_url(url, purpose=None): |
|
7268.11.1
by Jelmer Vernooij
Add rewrite_url hook. |
108 |
return url.replace('foo', 'bar') |
109 |
self.addCleanup(location_hooks.uninstall_named_hook, 'rewrite_url', 'test') |
|
110 |
location_hooks.install_named_hook('rewrite_url', rewrite_url, 'test') |
|
111 |
self.assertEqual( |
|
112 |
'http://bar.example.com/bar', location_to_url('http://foo.example.com/foo')) |
|
|
7265.6.3
by Jelmer Vernooij
Merge trunk. |
113 |
|
|
7265.6.2
by Jelmer Vernooij
Support rsync-style URLs. |
114 |
|
115 |
class RCPLocationTests(tests.TestCase): |
|
116 |
||
117 |
def test_without_user(self): |
|
118 |
self.assertEqual( |
|
119 |
"git+ssh://example.com/srv/git/bar", |
|
120 |
rcp_location_to_url("example.com:/srv/git/bar", scheme='git+ssh')) |
|
121 |
self.assertEqual( |
|
122 |
"ssh://example.com/srv/git/bar", |
|
123 |
rcp_location_to_url("example.com:/srv/git/bar")) |
|
124 |
||
125 |
def test_with_user(self): |
|
126 |
self.assertEqual( |
|
127 |
"git+ssh://foo@example.com/srv/git/bar", |
|
128 |
rcp_location_to_url("foo@example.com:/srv/git/bar", scheme='git+ssh')) |
|
129 |
||
130 |
def test_invalid(self): |
|
131 |
self.assertRaises(ValueError, rcp_location_to_url, "http://srv/git/bar") |
|
132 |
self.assertRaises(ValueError, rcp_location_to_url, "git/bar") |