~ed.so/duplicity/reuse-passphrase-for-signing-fix

« back to all changes in this revision

Viewing changes to testing/backendtest.py

  • Committer: bescoto
  • Date: 2002-10-29 01:49:46 UTC
  • Revision ID: vcs-imports@canonical.com-20021029014946-3m4rmm5plom7pl6q
Initial checkin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys, unittest, os
 
2
sys.path.insert(0, "../src")
 
3
import backends, path, log, file_naming, dup_time, globals, gpg
 
4
 
 
5
log.setverbosity(7)
 
6
 
 
7
class UnivTest:
 
8
        """Contains methods that help test any backend"""
 
9
        def try_basic(self, backend):
 
10
                """Try basic operations with given backend.
 
11
 
 
12
                Requires backend be empty at first, and all operations are
 
13
                allowed.
 
14
 
 
15
                """
 
16
                def cmp_list(l):
 
17
                        """Assert that backend.list is same as l"""
 
18
                        blist = backend.list()
 
19
                        assert blist == l, \
 
20
                                   ("Got list: %s\nWanted: %s\n" % (repr(blist), repr(l)))
 
21
 
 
22
                assert not os.system("rm -rf testfiles/backend_tmp")
 
23
                assert not os.system("mkdir testfiles/backend_tmp")
 
24
 
 
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")
 
28
 
 
29
                # Test list and put
 
30
                cmp_list([])
 
31
                backend.put(regpath, colonfile)
 
32
                cmp_list([colonfile])
 
33
 
 
34
                # Test get
 
35
                regfilebuf = regpath.open("rb").read()
 
36
                backend.get(colonfile, tmpregpath)
 
37
                backendbuf = tmpregpath.open("rb").read()
 
38
                assert backendbuf == regfilebuf
 
39
                
 
40
                # Test delete
 
41
                self.assertRaises(backends.BackendException,
 
42
                                                  backend.delete, ["aoeuaoeu"])
 
43
                backend.delete([colonfile])
 
44
                cmp_list([])
 
45
 
 
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!")
 
50
                fout.close()
 
51
                assert filename in backend.list()
 
52
 
 
53
                fin = backend.get_fileobj_read(filename)
 
54
                buf = fin.read()
 
55
                fin.close()
 
56
                assert buf == "hello, world!", buf
 
57
 
 
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")
 
65
 
 
66
                filename1 = file_naming.get('full', manifest = 1, gzipped = 1)
 
67
                self.try_fileobj_filename(backend, filename1)
 
68
 
 
69
                filename2 = file_naming.get('new-sig', encrypted = 1)
 
70
                self.try_fileobj_filename(backend, filename2)
 
71
 
 
72
        def del_tmp(self):
 
73
                """Delete and create testfiles/output"""
 
74
                assert not os.system("rm -rf testfiles/output")
 
75
                assert not os.system("mkdir testfiles/output")
 
76
 
 
77
class LocalTest(unittest.TestCase, UnivTest):
 
78
        """Test the Local backend"""
 
79
        def test_basic(self):
 
80
                """Test basic backend operations"""
 
81
                self.del_tmp()
 
82
                self.try_basic(backends.LocalBackend("testfiles/output"))
 
83
 
 
84
        def test_fileobj_ops(self):
 
85
                """Test fileobj operations"""
 
86
                self.try_fileobj_ops(backends.LocalBackend("testfiles/output"))
 
87
 
 
88
class scpTest(unittest.TestCase, UnivTest):
 
89
        """Test the SSH backend"""
 
90
        def test_basic(self):
 
91
                """Test backends - ssh into local host"""
 
92
                self.del_tmp()
 
93
                url_string = "ssh://localhost//home/ben/prog/python/" \
 
94
                                         "duplicity/testing/testfiles/output"
 
95
                self.try_basic(backends.get_backend(url_string))
 
96
                
 
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))
 
102
 
 
103
 
 
104
if __name__ == "__main__": unittest.main()
 
105