-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
77 lines (67 loc) · 2.17 KB
/
test_main.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
import main
import tempfile
import json
'''
In an actual production environment, we would have integration tests.
However, for local testing purposes this suffices.
'''
def test_directoryHunt():
with tempfile.TemporaryDirectory() as directory:
print('The created temporary directory is %s' % directory)
with open(directory + '/randomfile.txt', 'w') as writer:
writer.write("Random file with random text in it!")
response = main.directoryHunt(directory, "")
assert json.loads(response) == [
{
"permission":"drwx------",
"owner":"rebeccahsieh",
"group":"staff",
"size":"96",
"name":"."
},
{
"permission":"drwx------@",
"owner":"rebeccahsieh",
"group":"staff",
"size":"3968",
"name":".."
},
{
"permission":"-rw-r--r--",
"owner":"rebeccahsieh",
"group":"staff",
"size":"35",
"name":"randomfile.txt"
}
]
def test_directoryHunt_nofile():
with tempfile.TemporaryDirectory() as directory:
print('The created temporary directory is %s' % directory)
response = main.directoryHunt(directory, "")
assert json.loads(response) == [
{
"permission":"drwx------",
"owner":"rebeccahsieh",
"group":"staff",
"size":"64",
"name":"."
},
{
"permission":"drwx------@",
"owner":"rebeccahsieh",
"group":"staff",
"size":"3968",
"name":".."
}
]
def test_directoryHunt_periodinput():
response = main.directoryHunt(".")
assert json.loads(response) == {
"error": "Please put in a valid path"
}
def test_directoryHunt_multiperiodinput():
response = main.directoryHunt("..")
print("!! response is ", response)
assert json.loads(response) == {
"error": "Please put in a valid path"
}