forked from cybersecurity-team/TorBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_savetofile.py
More file actions
40 lines (31 loc) · 1014 Bytes
/
Copy pathtest_savetofile.py
File metadata and controls
40 lines (31 loc) · 1014 Bytes
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
"""
Test module for saving data to file
"""
import json
import os
from ..savefile import saveJson
def test_save_json_successful():
"""
Sucessfully create and dump JSON object of links
"""
mock_data = ['http://aff.ironsocket.com/SH7L',
'http://aff.ironsocket.com/SH7L',
'http://wsrs.net/',
'http://cmsgear.com/']
try:
file_name = saveJson('Links', mock_data)
mock_output = {'Links': mock_data}
with open('test_file.json', 'w+') as test_file:
json.dump(mock_output, test_file, indent=2)
os.chdir(os.getcwd())
assert os.path.isfile(file_name) is True
mock_file = open(file_name, 'r')
test_file = open('test_file.json', 'r')
mock_data = mock_file.read()
test_data = test_file.read()
finally:
os.remove(file_name)
os.remove('test_file.json')
assert mock_data == test_data
if __name__ == '__main__':
test_save_json_successful()