-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_main.py
98 lines (70 loc) · 2.53 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import random
import requests
import pytest
# Define the base URL of your server
BASE_URL = 'http://localhost:8000'
# define a random url path (to ensure clean uploads)
prefix = random.getrandbits(32)
BASE_URL += f'/{prefix}'
###
# Tests
###
def test_put_inline_data():
url = BASE_URL + '/f1/test_2'
data = 'Not Super Content!'
response = requests.put(url, data=data)
assert response.status_code == 200
assert response.json() == {"created": True, "size": 24, "size_human": "24 Bytes"}
def test_change_put_inline_data():
url = BASE_URL + '/f1/test_2'
data = 'Super Content!'
response = requests.put(url, data=data)
assert response.status_code == 200
assert response.json() == {"created": False, "size": 20, "size_human": "20 Bytes"}
def test_put_inline_data_folder():
url = BASE_URL + '/f1'
data = 'FOLDER'
response = requests.put(url, data=data)
assert response.status_code == 409
def test_put_upload_file():
url = BASE_URL + 'file.txt'
files = {'file': ('file.txt', open('file.txt', 'rb'))}
response = requests.put(url, files=files)
assert response.status_code == 200
assert response.json() == {"created": True, "size": 364, "size_human": "364 Bytes"}
def test_get_metadata():
url = BASE_URL + '/f1/test_2'
response = requests.get(url)
assert response.status_code == 200
data = response.json()
assert data['size'] == 20
assert data['size_human'] == "20 Bytes"
assert 'timestamp' in data
assert 'content' in data
def test_get_metadata_base64():
url = BASE_URL + '/f1/test_2?b64=true'
response = requests.get(url)
assert response.status_code == 200
data = response.json()
assert data['size'] == 20
assert data['size_human'] == "20 Bytes"
assert 'timestamp' in data
assert 'content' in data
assert data['content'] == "U3VwZXIgQ29udGVudCE="
def test_get_plain_data():
url = BASE_URL + '/f1/test_2?plain=true'
response = requests.get(url)
assert response.status_code == 200
assert response.headers['content-type'] == 'text/plain; charset=utf-8'
assert response.text == 'Super Content!'
def test_cors_headers_present():
url = BASE_URL + '/f1/test_2?plain=true'
headers = {
"Origin": "localhost"
}
response = requests.options(url, headers=headers)
assert 'Access-Control-Allow-Origin' in response.headers
assert 'Access-Control-Allow-Methods' in response.headers
assert 'Access-Control-Allow-Headers' in response.headers
if __name__ == '__main__':
pytest.main()