forked from tsileo/bakthat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bakthat_swift.py
128 lines (92 loc) · 4.75 KB
/
test_bakthat_swift.py
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
# -*- encoding: utf-8 -*-
import bakthat
import tempfile
import hashlib
import os
import time
import unittest
import logging
log = logging.getLogger()
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
handler.addFilter(bakthat.BakthatFilter())
handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
log.addHandler(handler)
log.setLevel(logging.DEBUG)
class BakthatSwiftBackendTestCase(unittest.TestCase):
"""This test cases use profile test_swift """
def setUp(self):
self.test_file = tempfile.NamedTemporaryFile()
self.test_file.write("Bakthat Test File")
self.test_file.seek(0)
self.test_filename = self.test_file.name.split("/")[-1]
self.test_hash = hashlib.sha1(self.test_file.read()).hexdigest()
self.password = "bakthat_encrypted_test"
self.test_profile = "test_swift"
def test_swift_backup_restore(self):
backup_data = bakthat.backup(self.test_file.name, "swift", password="",
profile=self.test_profile)
log.info(backup_data)
#self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
# profile=self.test_profile
# )[0]["filename"],
# self.test_filename)
bakthat.restore(self.test_filename, "swift", profile=self.test_profile)
restored_hash = hashlib.sha1(
open(self.test_filename).read()).hexdigest()
self.assertEqual(self.test_hash, restored_hash)
os.remove(self.test_filename)
bakthat.delete(backup_data["stored_filename"], "swift", profile=self.test_profile)
#self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
# profile=self.test_profile), [])
def test_swift_delete_older_than(self):
backup_res = bakthat.backup(self.test_file.name, "swift", password="",
profile=self.test_profile)
#self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
# profile=self.test_profile
# )[0]["filename"],
# self.test_filename)
bakthat.restore(self.test_filename, "swift",
profile=self.test_profile)
restored_hash = hashlib.sha1(
open(self.test_filename).read()).hexdigest()
self.assertEqual(self.test_hash, restored_hash)
os.remove(self.test_filename)
test_deleted = bakthat.delete_older_than(self.test_filename, "1Y",
"swift",
profile=self.test_profile)
self.assertEqual(test_deleted, [])
time.sleep(10)
test_deleted = bakthat.delete_older_than(self.test_filename, "9s",
"swift",
profile=self.test_profile)
key_deleted = test_deleted[0]
self.assertEqual(key_deleted, backup_res["stored_filename"])
#self.assertEqual(bakthat.match_filename(self.test_filename,
# "swift",
# profile=self.test_profile),
# [])
def test_swift_encrypted_backup_restore(self):
backup_data = bakthat.backup(self.test_file.name, "swift", password=self.password,
profile=self.test_profile)
#self.assertEqual(bakthat.match_filename(self.test_filename, "swift",
# profile=self.test_profile)
# [0]["filename"], self.test_filename)
# Check if stored file is encrypted
#self.assertTrue(bakthat.match_filename(self.test_filename, "swift",
# profile=self.test_profile)
# [0]["is_enc"])
bakthat.restore(self.test_filename, "swift", password=self.password,
profile=self.test_profile)
restored_hash = hashlib.sha1(
open(self.test_filename).read()).hexdigest()
self.assertEqual(self.test_hash, restored_hash)
os.remove(self.test_filename)
bakthat.delete(backup_data["stored_filename"], "swift",
profile=self.test_profile)
#self.assertEqual(bakthat.match_filename(self.test_filename,
# "swift",
# profile=self.test_profile),
# [])
if __name__ == '__main__':
unittest.main()