1
import sys, unittest, os
2
sys.path.insert(0, "../src")
3
import backends, path, log, file_naming, dup_time, globals, gpg
8
"""Contains methods that help test any backend"""
9
def try_basic(self, backend):
10
"""Try basic operations with given backend.
12
Requires backend be empty at first, and all operations are
17
"""Assert that backend.list is same as l"""
18
blist = backend.list()
20
("Got list: %s\nWanted: %s\n" % (repr(blist), repr(l)))
22
assert not os.system("rm -rf testfiles/backend_tmp")
23
assert not os.system("mkdir testfiles/backend_tmp")
25
regpath = path.Path("testfiles/various_file_types/regular_file")
26
colonfile = "file:with.colons_and:some-other::chars"
27
tmpregpath = path.Path("testfiles/backend_tmp/regfile")
31
backend.put(regpath, colonfile)
35
regfilebuf = regpath.open("rb").read()
36
backend.get(colonfile, tmpregpath)
37
backendbuf = tmpregpath.open("rb").read()
38
assert backendbuf == regfilebuf
41
self.assertRaises(backends.BackendException,
42
backend.delete, ["aoeuaoeu"])
43
backend.delete([colonfile])
46
def try_fileobj_filename(self, backend, filename):
47
"""Use get_fileobj_write and get_fileobj_read on filename around"""
48
fout = backend.get_fileobj_write(filename)
49
fout.write("hello, world!")
51
assert filename in backend.list()
53
fin = backend.get_fileobj_read(filename)
56
assert buf == "hello, world!", buf
58
def try_fileobj_ops(self, backend):
59
"""Test above try_fileobj_filename with a few filenames"""
60
# Must set dup_time strings because they are used by file_naming
61
dup_time.setcurtime(2000)
62
dup_time.setprevtime(1000)
63
# Also set profile for encryption
64
globals.gpg_profile = gpg.GPGProfile(passphrase = "foobar")
66
filename1 = file_naming.get('full', manifest = 1, gzipped = 1)
67
self.try_fileobj_filename(backend, filename1)
69
filename2 = file_naming.get('new-sig', encrypted = 1)
70
self.try_fileobj_filename(backend, filename2)
73
"""Delete and create testfiles/output"""
74
assert not os.system("rm -rf testfiles/output")
75
assert not os.system("mkdir testfiles/output")
77
class LocalTest(unittest.TestCase, UnivTest):
78
"""Test the Local backend"""
80
"""Test basic backend operations"""
82
self.try_basic(backends.LocalBackend("testfiles/output"))
84
def test_fileobj_ops(self):
85
"""Test fileobj operations"""
86
self.try_fileobj_ops(backends.LocalBackend("testfiles/output"))
88
class scpTest(unittest.TestCase, UnivTest):
89
"""Test the SSH backend"""
91
"""Test backends - ssh into local host"""
93
url_string = "ssh://localhost//home/ben/prog/python/" \
94
"duplicity/testing/testfiles/output"
95
self.try_basic(backends.get_backend(url_string))
97
def test_fileobj_ops(self):
98
"""Test fileobj operations"""
99
url_string = "ssh://localhost//home/ben/prog/python/" \
100
"duplicity/testing/testfiles/output"
101
self.try_fileobj_ops(backends.get_backend(url_string))
104
if __name__ == "__main__": unittest.main()