-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
94 lines (86 loc) · 3.14 KB
/
tests.py
File metadata and controls
94 lines (86 loc) · 3.14 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
import unittest
import requests
import random
# Information:
TOKEN = 'IrAw7YRknJ4mYG2kBFdx'
DISTANT_URL = 'biofeed.vitavault.fr'
DISTANT_PORT = 443
LOCAL_URL = 'localhost'
LOCAL_PORT = 5000
def send_post_request(url, data):
headers = {'Content-Type': 'application/json'}
response = requests.post(url, json=data, headers=headers)
return response
class MyTestCase(unittest.TestCase):
def test_local_post_request(self):
argv = input('Local ? [Y|n] > ')
r = random.randint(0, 10000)
print('Random number: ', r)
if (len(argv) == 0) or (argv[0].lower() == 'y'):
url, port, protocol = LOCAL_URL, LOCAL_PORT, 'http'
else:
url, port, protocol = DISTANT_URL, DISTANT_PORT, 'https'
url = f'{protocol}://{url}:{port}'
tests = [
(
{"name": "carotte", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
# (
# {"command": "clear", "token": TOKEN},
# '/command'
# ),
(
{"name": "carotte1", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "carotte2", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "courgette", "date": r, "photo": "base64ici", "token": "wrong_token", "test": True},
'/store_data'
),
(
{"name": "carotte3", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "carotte4", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "carotte5", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "carotte6", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "carotte7", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "carotte8", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "carotte9", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "carotte10", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
),
(
{"name": "tomate", "date": r, "photo": "base64ici", "token": TOKEN, "test": True},
'/store_data'
)
]
for x in tests:
response = send_post_request(url + x[1], x[0])
self.assertEqual(response.status_code, 200)
if __name__ == '__main__':
unittest.main()