-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_lib.py
More file actions
executable file
·159 lines (133 loc) · 3.95 KB
/
test_lib.py
File metadata and controls
executable file
·159 lines (133 loc) · 3.95 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/local/bin/python3
from client_lib import DFS_client
from bson.objectid import ObjectId
from pprint import pprint
"""Provides a suite to tests the functionality of the project"""
def test_setup():
global cli
cli = DFS_client('admin', 'admin')
print('CREATEING RICHIE')
cli.create_user(**{
'username': 'richie',
'password': 'pass',
'admin': False
})
cli = DFS_client('richie', 'pass')
print('GENERATING TOKEN')
cli.generate_token()
print('CHECKING AUTH')
cli.check_auth()
print('TESTING TEMP')
cli2 = DFS_client('temp', 'nah')
print('CHECKING AUTH')
cli2.check_auth()
print("GETTING ALL")
cli.get_all_files()
def test_adding():
print("ADDING")
cli.add_file(name='test.txt', content='hello world')
cli.add_file(name='test2.txt', content='goobye world')
def test_get_all():
global r
print("GETTING ALL")
r = cli.get_all_files()
print('GETTING INDIVIDUAL')
try:
if r['status'] == 200:
msg = r['message']
files = msg['files']
for f in files:
cli.get_file(**{'_id': f['_id']})
except Exception as e:
print('error', e)
def test_edits():
global r
print("GETTING")
r = cli.get_all_files()
print('TRYING GOOD EDITS')
try:
if r['status'] == 200:
msg = r['message']
files = msg['files']
for f in files:
f['content'] = 'please no!'
cli.edit_file(**f)
except Exception as e:
print('error', e)
print('TRYING BAD EDITS')
try:
if r['status'] == 200:
msg = r['message']
files = msg['files']
for f in files:
f['content'] = 'please yes!'
cli.edit_file(**f)
except Exception as e:
print('error', e)
print('CHECKING EDITS')
try:
if r['status'] == 200:
msg = r['message']
files = msg['files']
for f in files:
cli.get_file(**{'_id': f['_id']})
except Exception as e:
print('error', e)
def test_search():
print('SEARCHING')
cli.search_for_file(**{'name': 'test.txt'})
def test_delete():
global r
print("GETTING")
r = cli.get_all_files()
print('DELETING INDIVIDUAL')
try:
if r['status'] == 200:
msg = r['message']
files = msg['files']
for f in files:
cli.del_file(**{'_id': f['_id']})
except Exception as e:
print('error', e)
print("GETTING")
r = cli.get_all_files()
def test_lock():
global r
print("GETTING")
r = cli.get_all_files()
print('LOCKING ALL')
try:
if r['status'] == 200:
msg = r['message']
files = msg['files']
print('CHECKING LOCK STATUS')
for f in files:
cli.check_lock_file(**{'uri': f['uri'], '_fid': f['_id']})
print("LOCKING")
for f in files:
cli.lock_file(**{'uri': f['uri'], '_fid': f['_id']})
print('CHECKING LOCK STATUS')
for f in files:
cli.check_lock_file(**{'uri': f['uri'], '_fid': f['_id']})
print('TRYING TO RE-LOCK')
for f in files:
cli.lock_file(**{'uri': f['uri'], '_fid': f['_id']})
print('CHECKING LOCK STATUS')
for f in files:
cli.check_lock_file(**{'uri': f['uri'], '_fid': f['_id']})
print('UNLOCKING')
for f in files:
cli.unlock_file(**{'uri': f['uri'], '_fid': f['_id']})
print('CHECKING LOCK STATUS')
for f in files:
cli.check_lock_file(**{'uri': f['uri'], '_fid': f['_id']})
except Exception as e:
print('error', e)
if __name__ == "__main__":
test_setup()
test_adding()
test_get_all()
test_search()
test_edits()
test_lock()
test_delete()