~mterry/duplicity/gdrive

« back to all changes in this revision

Viewing changes to testing/finaltest.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, os, unittest
 
2
sys.path.insert(0, "../src")
 
3
import path
 
4
 
 
5
class FinalTest(unittest.TestCase):
 
6
        """Test backup/restore using duplicity binary"""
 
7
        def run_duplicity(self, arglist, options = [], current_time = None):
 
8
                """Run duplicity binary with given arguments and options"""
 
9
                cmd_list = ["../duplicity-bin"]
 
10
                cmd_list.extend(options + ["-v3", "--allow-source-mismatch"])
 
11
                if current_time: cmd_list.append("--current-time %s" % (current_time,))
 
12
                cmd_list.extend(arglist)
 
13
                cmdline = " ".join(cmd_list)
 
14
                print "Running '%s'." % cmdline
 
15
                if not os.environ.has_key('PASSPHRASE'):
 
16
                        os.environ['PASSPHRASE'] = 'foobar'
 
17
                assert not os.system(cmdline)
 
18
 
 
19
        def backup(self, type, input_dir, options = [], current_time = None):
 
20
                """Run duplicity backup to default directory"""
 
21
                options = options[:]
 
22
                if type == "full": options.append('--full')
 
23
                args = [input_dir, "file://testfiles/output"]
 
24
                self.run_duplicity(args, options, current_time)
 
25
 
 
26
        def restore(self, file_to_restore = None, time = None, options = [],
 
27
                                current_time = None):
 
28
                options = options[:] # just nip any mutability problems in bud
 
29
                assert not os.system("rm -rf testfiles/restore_out")
 
30
                args = ["file://testfiles/output", "testfiles/restore_out"]
 
31
                if file_to_restore:
 
32
                        options.extend(['--file-to-restore', file_to_restore])
 
33
                if time: options.extend(['--restore-time', str(time)])
 
34
                self.run_duplicity(args, options, current_time)
 
35
 
 
36
        def deltmp(self):
 
37
                """Delete temporary directories"""
 
38
                assert not os.system("rm -rf testfiles/output "
 
39
                                                         "testfiles/restore_out testfiles/tmp_archive")
 
40
                assert not os.system("mkdir testfiles/output testfiles/tmp_archive")
 
41
 
 
42
        def runtest(self, dirlist, backup_options = [], restore_options = []):
 
43
                """Run backup/restore test on directories in dirlist"""
 
44
                assert len(dirlist) > 1
 
45
                self.deltmp()
 
46
 
 
47
                # Back up directories to local backend
 
48
                current_time = 100000
 
49
                self.backup("full", dirlist[0], current_time = current_time,
 
50
                                        options = backup_options)
 
51
                for new_dir in dirlist[1:]:
 
52
                        current_time += 100000
 
53
                        self.backup("inc", new_dir, current_time = current_time,
 
54
                                                options = backup_options)
 
55
 
 
56
                # Restore each and compare them
 
57
                for i in range(len(dirlist)):
 
58
                        dirname = dirlist[i]
 
59
                        current_time = 100000*(i + 1)
 
60
                        self.restore(time = current_time, options = restore_options)
 
61
                        self.check_same(dirname, "testfiles/restore_out")
 
62
 
 
63
        def check_same(self, filename1, filename2):
 
64
                """Verify two filenames are the same"""
 
65
                path1, path2 = path.Path(filename1), path.Path(filename2)
 
66
                assert path1.compare_recursive(path2, verbose = 1)
 
67
 
 
68
        def test_basic_cycle(self, backup_options = [], restore_options = []):
 
69
                """Run backup/restore test on basic directories"""
 
70
                self.runtest(["testfiles/dir1", "testfiles/dir2",
 
71
                                          "testfiles/dir3", "testfiles/empty_dir"],
 
72
                                         backup_options = backup_options,
 
73
                                         restore_options = restore_options)
 
74
 
 
75
                # Test restoring various sub files
 
76
                for filename, time, dir in [('symbolic_link', 99999, 'dir1'),
 
77
                                                                        ('directory_to_file', 100100, 'dir1'),
 
78
                                                                        ('directory_to_file', 200100, 'dir2'),
 
79
                                                                        ('largefile', 300000, 'dir3')]:
 
80
                        self.restore(filename, time)
 
81
                        self.check_same('testfiles/%s/%s' % (dir, filename),
 
82
                                                        'testfiles/restore_out')
 
83
 
 
84
        def test_asym_cycle(self):
 
85
                """Like test_basic_cycle but use asymmetric encryption and signing"""
 
86
                backup_options = ["--encrypt-key AA0E73D2", "--sign-key AA0E73D2"]
 
87
                restore_options = ['--sign-key AA0E73D2']
 
88
                self.test_basic_cycle(backup_options = backup_options,
 
89
                                                          restore_options = restore_options)
 
90
 
 
91
        def test_archive_dir(self):
 
92
                """Like test_basic_cycle, but use a local archive dir"""
 
93
                options = ["--archive-dir testfiles/tmp_archive"]
 
94
                self.test_basic_cycle(backup_options = options,
 
95
                                                          restore_options = options)
 
96
 
 
97
if __name__ == "__main__": unittest.main()