1
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
3
# Copyright 2002 Ben Escoto <ben@emerose.org>
4
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
6
# This file is part of duplicity.
8
# Duplicity is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by the
10
# Free Software Foundation; either version 2 of the License, or (at your
11
# option) any later version.
13
# Duplicity is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
# General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with duplicity; if not, write to the Free Software Foundation,
20
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
sys.path.insert(0, "../")
26
import duplicity.backend
27
import duplicity.backends #@UnusedImport
28
from duplicity.errors import * #@UnusedWildImport
32
class ParsedUrlTest(unittest.TestCase):
33
"""Test the ParsedUrl class"""
35
"""Test various url strings"""
36
pu = duplicity.backend.ParsedUrl("scp://ben@foo.bar:1234/a/b")
37
assert pu.scheme == "scp", pu.scheme
38
assert pu.netloc == "ben@foo.bar:1234", pu.netloc
39
assert pu.path =="/a/b", pu.path
40
assert pu.username == "ben", pu.username
41
assert pu.port == 1234, pu.port
42
assert pu.hostname == "foo.bar", pu.hostname
44
pu = duplicity.backend.ParsedUrl("ftp://foo.bar:1234/")
45
assert pu.scheme == "ftp", pu.scheme
46
assert pu.netloc == "foo.bar:1234", pu.netloc
47
assert pu.path == "/", pu.path
48
assert pu.username is None, pu.username
49
assert pu.port == 1234, pu.port
50
assert pu.hostname == "foo.bar", pu.hostname
52
pu = duplicity.backend.ParsedUrl("file:///home")
53
assert pu.scheme == "file", pu.scheme
54
assert pu.netloc == "", pu.netloc
55
assert pu.path == "///home", pu.path
56
assert pu.username is None, pu.username
57
assert pu.port is None, pu.port
59
pu = duplicity.backend.ParsedUrl("ftp://foo@bar:pass@example.com:123/home")
60
assert pu.scheme == "ftp", pu.scheme
61
assert pu.netloc == "foo@bar:pass@example.com:123", pu.netloc
62
assert pu.hostname == "example.com", pu.hostname
63
assert pu.path == "/home", pu.path
64
assert pu.username == "foo@bar", pu.username
65
assert pu.password == "pass", pu.password
66
assert pu.port == 123, pu.port
68
pu = duplicity.backend.ParsedUrl("ftp://foo%40bar:pass@example.com:123/home")
69
assert pu.scheme == "ftp", pu.scheme
70
assert pu.netloc == "foo%40bar:pass@example.com:123", pu.netloc
71
assert pu.hostname == "example.com", pu.hostname
72
assert pu.path == "/home", pu.path
73
assert pu.username == "foo@bar", pu.username
74
assert pu.password == "pass", pu.password
75
assert pu.port == 123, pu.port
77
pu = duplicity.backend.ParsedUrl("imap://foo@bar:pass@example.com:123/home")
78
assert pu.scheme == "imap", pu.scheme
79
assert pu.netloc == "foo@bar:pass@example.com:123", pu.netloc
80
assert pu.hostname == "example.com", pu.hostname
81
assert pu.path == "/home", pu.path
82
assert pu.username == "foo@bar", pu.username
83
assert pu.password == "pass", pu.password
84
assert pu.port == 123, pu.port
86
pu = duplicity.backend.ParsedUrl("imap://foo@bar@example.com:123/home")
87
assert pu.scheme == "imap", pu.scheme
88
assert pu.netloc == "foo@bar@example.com:123", pu.netloc
89
assert pu.hostname == "example.com", pu.hostname
90
assert pu.path == "/home", pu.path
91
assert pu.username == "foo@bar", pu.username
92
assert pu.password == None, pu.password
93
assert pu.port == 123, pu.port
95
pu = duplicity.backend.ParsedUrl("imap://foo@bar@example.com/home")
96
assert pu.scheme == "imap", pu.scheme
97
assert pu.netloc == "foo@bar@example.com", pu.netloc
98
assert pu.hostname == "example.com", pu.hostname
99
assert pu.path == "/home", pu.path
100
assert pu.username == "foo@bar", pu.username
101
assert pu.password == None, pu.password
102
assert pu.port == None, pu.port
104
pu = duplicity.backend.ParsedUrl("imap://foo@bar.com@example.com/home")
105
assert pu.scheme == "imap", pu.scheme
106
assert pu.netloc == "foo@bar.com@example.com", pu.netloc
107
assert pu.hostname == "example.com", pu.hostname
108
assert pu.path == "/home", pu.path
109
assert pu.username == "foo@bar.com", pu.username
110
assert pu.password == None, pu.password
111
assert pu.port == None, pu.port
113
pu = duplicity.backend.ParsedUrl("imap://foo%40bar.com@example.com/home")
114
assert pu.scheme == "imap", pu.scheme
115
assert pu.netloc == "foo%40bar.com@example.com", pu.netloc
116
assert pu.hostname == "example.com", pu.hostname
117
assert pu.path == "/home", pu.path
118
assert pu.username == "foo@bar.com", pu.username
119
assert pu.password == None, pu.password
120
assert pu.port == None, pu.port
122
def test_errors(self):
123
"""Test various url errors"""
124
self.assertRaises(InvalidBackendURL, duplicity.backend.ParsedUrl,
125
"ssh://foo@bar:pass@example.com:/home")
126
self.assertRaises(UnsupportedBackendScheme, duplicity.backend.get_backend,
127
"foo://foo@bar:pass@example.com/home")
130
if __name__ == "__main__":