forked from kmicinski/file-server-group
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_post_file.py
34 lines (30 loc) · 945 Bytes
/
test_post_file.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
import os
import requests
import filecmp
from io import BytesIO
# Or 8080
port = "5000"
def test_post_file(path_to_file,filename):
files = {'file': open(path_to_file, 'rb')}
r = requests.post("http://localhost:" + port + "/" + filename, files=files)
if (r.ok):
print("POST returned OK result")
else:
print("POST result not OK")
exit(1)
print("Now getting it back")
r = requests.get("http://localhost:" + port + "/" + filename)
if (r.ok):
print("Test returned OK result")
else:
print("Result not OK")
exit(1)
open("output", "wb").write(r.content)
if filecmp.cmp('output', path_to_file):
print("File is the same (passed): ", filename)
else:
print("File is different (failed), result in output ", filename)
exit(1)
pairs = [["example-files/sample.pdf", "examplepdf.pdf"]]
for pair in pairs:
test_post_file(pair[0], pair[1])