1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2002 Ben Escoto <ben@emerose.org>
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
#
# This file is part of duplicity.
#
# Duplicity is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# Duplicity is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with duplicity; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import config
import sys, unittest, os
sys.path.insert(0, "../")
import duplicity.backend
import duplicity.backends
from duplicity.errors import *
from duplicity import path, log, file_naming, dup_time, globals, gpg
config.setup()
class UnivTest:
"""Contains methods that help test any backend"""
def del_tmp(self):
"""Remove all files from test directory"""
config.set_environ("FTP_PASSWORD", self.password)
backend = duplicity.backend.get_backend(self.url_string)
backend.delete(backend.list())
backend.close()
"""Delete and create testfiles/output"""
assert not os.system("rm -rf testfiles/output")
assert not os.system("mkdir testfiles/output")
def test_basic(self):
"""Test basic backend operations"""
if not self.url_string:
print "No URL for test %s...skipping... " % self.my_test_id,
return 0
config.set_environ("FTP_PASSWORD", self.password)
self.del_tmp()
self.try_basic(duplicity.backend.get_backend(self.url_string))
def test_fileobj_ops(self):
"""Test fileobj operations"""
if not self.url_string:
print "No URL for test %s...skipping... " % self.my_test_id,
return 0
config.set_environ("FTP_PASSWORD", self.password)
self.try_fileobj_ops(duplicity.backend.get_backend(self.url_string))
def try_basic(self, backend):
"""Try basic operations with given backend.
Requires backend be empty at first, and all operations are
allowed.
"""
def cmp_list(l):
"""Assert that backend.list is same as l"""
blist = backend.list()
blist.sort()
l.sort()
assert blist == l, \
("Got list: %s\nWanted: %s\n" % (repr(blist), repr(l)))
# Identify test that's running
print self.my_test_id, "... ",
assert not os.system("rm -rf testfiles/backend_tmp")
assert not os.system("mkdir testfiles/backend_tmp")
regpath = path.Path("testfiles/various_file_types/regular_file")
normal_file = "testfile"
colonfile = ("file%swith.%scolons_-and%s%setc" %
((globals.time_separator,) * 4))
tmpregpath = path.Path("testfiles/backend_tmp/regfile")
# Test list and put
cmp_list([])
backend.put(regpath, normal_file)
cmp_list([normal_file])
backend.put(regpath, colonfile)
cmp_list([normal_file, colonfile])
# Test get
regfilebuf = regpath.open("rb").read()
backend.get(colonfile, tmpregpath)
backendbuf = tmpregpath.open("rb").read()
assert backendbuf == regfilebuf
# Test delete
backend.delete([colonfile, normal_file])
cmp_list([])
def try_fileobj_filename(self, backend, filename):
"""Use get_fileobj_write and get_fileobj_read on filename around"""
fout = backend.get_fileobj_write(filename)
fout.write("hello, world!")
fout.close()
assert filename in backend.list()
fin = backend.get_fileobj_read(filename)
buf = fin.read()
fin.close()
assert buf == "hello, world!", buf
backend.delete ([filename])
def try_fileobj_ops(self, backend):
"""Test above try_fileobj_filename with a few filenames"""
# Must set dup_time strings because they are used by file_naming
dup_time.setcurtime(2000)
dup_time.setprevtime(1000)
# Also set profile for encryption
globals.gpg_profile = gpg.GPGProfile(passphrase = "foobar")
filename1 = file_naming.get('full', manifest = 1, gzipped = 1)
self.try_fileobj_filename(backend, filename1)
filename2 = file_naming.get('new-sig', encrypted = 1)
self.try_fileobj_filename(backend, filename2)
class LocalTest(unittest.TestCase, UnivTest):
""" Test the Local backend """
my_test_id = "local"
url_string = config.file_url
password = config.file_password
class scpTest(unittest.TestCase, UnivTest):
""" Test the SSH backend """
my_test_id = "ssh/scp"
url_string = config.ssh_url
password = config.ssh_password
class ftpTest(unittest.TestCase, UnivTest):
""" Test the ftp backend """
my_test_id = "ftp"
url_string = config.ftp_url
password = config.ftp_password
class rsyncAbsPathTest(unittest.TestCase, UnivTest):
""" Test the rsync abs path backend """
my_test_id = "rsync_abspath"
url_string = config.rsync_abspath_url
password = config.rsync_password
class rsyncRelPathTest(unittest.TestCase, UnivTest):
""" Test the rsync relative path backend """
my_test_id = "rsync_relpath"
url_string = config.rsync_relpath_url
password = config.rsync_password
class rsyncModuleTest(unittest.TestCase, UnivTest):
""" Test the rsync module backend """
my_test_id = "rsync_module"
url_string = config.rsync_module_url
password = config.rsync_password
class s3ModuleTest(unittest.TestCase, UnivTest):
""" Test the s3 module backend """
my_test_id = "s3/boto"
url_string = config.s3_url
password = None
class webdavModuleTest(unittest.TestCase, UnivTest):
""" Test the webdav module backend """
my_test_id = "webdav"
url_string = config.webdav_url
password = config.webdav_password
class webdavsModuleTest(unittest.TestCase, UnivTest):
""" Test the webdavs module backend """
my_test_id = "webdavs"
url_string = config.webdavs_url
password = config.webdavs_password
if __name__ == "__main__":
unittest.main()
|