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

« back to all changes in this revision

Viewing changes to testing/collectionstest.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, random, unittest
 
2
sys.path.insert(0, "../src")
 
3
import collections, backends, path, gpg, globals
 
4
 
 
5
filename_list1 = ["duplicity-full.2002-08-17T16:17:01-07:00.manifest.gpg",
 
6
                                  "duplicity-full.2002-08-17T16:17:01-07:00.vol1.difftar.gpg",
 
7
                                  "duplicity-full.2002-08-17T16:17:01-07:00.vol2.difftar.gpg",
 
8
                                  "duplicity-full.2002-08-17T16:17:01-07:00.vol3.difftar.gpg",
 
9
                                  "duplicity-full.2002-08-17T16:17:01-07:00.vol4.difftar.gpg",
 
10
                                  "duplicity-full.2002-08-17T16:17:01-07:00.vol5.difftar.gpg",
 
11
                                  "duplicity-full.2002-08-17T16:17:01-07:00.vol6.difftar.gpg",
 
12
                                  "duplicity-inc.2002-08-17T16:17:01-07:00.to.2002-08-18T00:04:30-07:00.manifest.gpg",
 
13
                                  "duplicity-inc.2002-08-17T16:17:01-07:00.to.2002-08-18T00:04:30-07:00.vol1.difftar.gpg",
 
14
                                  "Extra stuff to be ignored"]
 
15
 
 
16
remote_sigchain_filename_list = ["duplicity-full-signatures.2002-08-17T16:17:01-07:00.sigtar.gpg",
 
17
                                                                 "duplicity-new-signatures.2002-08-17T16:17:01-07:00.to.2002-08-18T00:04:30-07:00.sigtar.gpg",
 
18
                                                                 "duplicity-new-signatures.2002-08-18T00:04:30-07:00.to.2002-08-20T00:00:00-07:00.sigtar.gpg"]
 
19
 
 
20
local_sigchain_filename_list =  ["duplicity-full-signatures.2002-08-17T16:17:01-07:00.sigtar.gz",
 
21
                                                                 "duplicity-new-signatures.2002-08-17T16:17:01-07:00.to.2002-08-18T00:04:30-07:00.sigtar.gz",
 
22
                                                                 "duplicity-new-signatures.2002-08-18T00:04:30-07:00.to.2002-08-20T00:00:00-07:00.sigtar.gz"]
 
23
 
 
24
 
 
25
col_test_dir = path.Path("testfiles/collectionstest")
 
26
archive_dir = col_test_dir.append("archive_dir")
 
27
archive_dir_backend = backends.get_backend("file://testfiles/collectionstest"
 
28
                                                                                   "/archive_dir")
 
29
 
 
30
dummy_backend = None
 
31
real_backend = backends.LocalBackend(col_test_dir.append("remote_dir").name)
 
32
 
 
33
 
 
34
class CollectionTest(unittest.TestCase):
 
35
        """Test collections"""
 
36
        def set_gpg_profile(self):
 
37
                """Set gpg profile to standard "foobar" sym"""
 
38
                globals.gpg_profile = gpg.GPGProfile(passphrase = "foobar")
 
39
 
 
40
        def test_backup_chains(self):
 
41
                """Test basic backup chain construction"""
 
42
                random.shuffle(filename_list1)
 
43
                cs = collections.CollectionsStatus(dummy_backend, archive_dir)
 
44
                chains, orphaned, incomplete = cs.get_backup_chains(filename_list1)
 
45
                if len(chains) != 1 or len(orphaned) != 0:
 
46
                        print chains
 
47
                        print orphaned
 
48
                        assert 0
 
49
 
 
50
                chain = chains[0]
 
51
                assert chain.end_time == 1029654270L
 
52
                assert chain.fullset.time == 1029626221L
 
53
 
 
54
        def test_collections_status(self):
 
55
                """Test CollectionStatus object's set_values()"""
 
56
                def check_cs(cs):
 
57
                        """Check values of collections status"""
 
58
                        assert cs.values_set
 
59
 
 
60
                        assert cs.matched_chain_pair
 
61
                        assert cs.matched_chain_pair[0].end_time == 1029826800L
 
62
                        assert len(cs.all_backup_chains) == 1, cs.all_backup_chains
 
63
 
 
64
                cs1 = collections.CollectionsStatus(real_backend).set_values()
 
65
                check_cs(cs1)
 
66
                assert not cs1.matched_chain_pair[0].islocal()
 
67
 
 
68
                cs2 = collections.CollectionsStatus(real_backend, archive_dir).set_values()
 
69
                check_cs(cs2)
 
70
                assert cs2.matched_chain_pair[0].islocal()
 
71
 
 
72
        def test_sig_chain(self):
 
73
                """Test a single signature chain"""
 
74
                chain = collections.SignatureChain(1, archive_dir)
 
75
                for filename in local_sigchain_filename_list:
 
76
                        assert chain.add_filename(filename)
 
77
                assert not chain.add_filename("duplicity-new-signatures.2002-08-18T00:04:30-07:00.to.2002-08-20T00:00:00-07:00.sigtar.gpg")
 
78
 
 
79
        def test_sig_chains(self):
 
80
                """Test making signature chains from filename list"""
 
81
                cs = collections.CollectionsStatus(dummy_backend, archive_dir)
 
82
                chains, orphaned_paths = cs.get_signature_chains(local = 1)
 
83
                self.sig_chains_helper(chains, orphaned_paths)
 
84
 
 
85
        def test_sig_chains2(self):
 
86
                """Test making signature chains from filename list on backend"""
 
87
                cs = collections.CollectionsStatus(archive_dir_backend)
 
88
                chains, orphaned_paths = cs.get_signature_chains(local = None)
 
89
                self.sig_chains_helper(chains, orphaned_paths)
 
90
 
 
91
        def sig_chains_helper(self, chains, orphaned_paths):
 
92
                """Test chains and orphaned_paths values for two above tests"""
 
93
                if orphaned_paths:
 
94
                        for op in orphaned_paths: print op
 
95
                        assert 0
 
96
                assert len(chains) == 1, chains
 
97
                assert chains[0].end_time == 1029826800L
 
98
 
 
99
        def sigchain_fileobj_get(self, local):
 
100
                """Return chain, local if local is true with filenames added"""
 
101
                if local:
 
102
                        chain = collections.SignatureChain(1, archive_dir)
 
103
                        for filename in local_sigchain_filename_list:
 
104
                                assert chain.add_filename(filename)
 
105
                else:
 
106
                        chain = collections.SignatureChain(None, real_backend)
 
107
                        for filename in remote_sigchain_filename_list:
 
108
                                assert chain.add_filename(filename)
 
109
                return chain
 
110
 
 
111
        def sigchain_fileobj_testlist(self, chain):
 
112
                """Make sure the list of file objects in chain has right contents
 
113
 
 
114
                The contents of the testfiles/collectiontest/remote_dir have
 
115
                to be coordinated with this test.
 
116
 
 
117
                """
 
118
                fileobjlist = chain.get_fileobjs()
 
119
                assert len(fileobjlist) == 3
 
120
                def test_fileobj(i, s):
 
121
                        buf = fileobjlist[i].read()
 
122
                        fileobjlist[i].close()
 
123
                        assert buf == s, (buf, s)
 
124
                test_fileobj(0, "Hello, world!")
 
125
                test_fileobj(1, "hello 1")
 
126
                test_fileobj(2, "Hello 2")
 
127
 
 
128
        def test_sigchain_fileobj(self):
 
129
                """Test getting signature chain fileobjs from archive_dir"""
 
130
                self.set_gpg_profile()
 
131
                self.sigchain_fileobj_testlist(self.sigchain_fileobj_get(1))
 
132
                self.sigchain_fileobj_testlist(self.sigchain_fileobj_get(None))         
 
133
 
 
134
                
 
135
 
 
136
if __name__ == "__main__": unittest.main()