-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck2_tester.py
89 lines (75 loc) · 3.39 KB
/
check2_tester.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
import unittest
import requests
import subprocess
import time
import sys
def fail(msg):
print('error:', msg)
def main():
print('Running signup tests...')
test_signup()
print('Finished signup tests')
print('Running signin tests...')
test_signin()
print('Finished signin tests')
print('Running logout tests...')
test_logout()
print('Finished logout tests')
print('Running verify tests...')
test_verify()
print('Finished verify tests')
def test_signup():
url = "http://localhost:80/api/auth/signup"
payload = {'username': 'test_user', 'email': '[email protected]', 'password': 'test_password'}
response = requests.post(url, json=payload)
if response.status_code != 201:
fail('expected status code 201 but was {}'.format(response.status_code))
if len(response.cookies) != 2:
fail('expected 2 cookies but got {}'.format(len(response.cookies)))
if 'access_token' not in response.cookies:
fail('access_token not in cookies')
if 'refresh_token' not in response.cookies:
fail('refresh_token not in cookies')
url = "http://localhost:80/api/auth/signup"
payload = {'username': 'test_user', 'email': '[email protected]', 'password': 'test_password'}
response = requests.post(url, json=payload)
if response.status_code != 409:
fail('expected status code 409 but was {}'.format(response.status_code))
url = "http://localhost:80/api/auth/signup"
payload = {'username': 'test_user2', 'email': '[email protected]', 'password': 'test_password'}
response = requests.post(url, json=payload)
if response.status_code != 409:
fail('expected status code 409 but was {}'.format(response.status_code))
def test_signin():
url = "http://localhost:80/api/auth/signup"
payload = {'username': 'test_user2', 'email': '[email protected]', 'password': 'test_password2'}
response = requests.post(url, json=payload)
url = "http://localhost:80/api/auth/signin"
payload = {'username': 'test_user2', 'email': '[email protected]', 'password': 'test_password2'}
response = requests.post(url, json=payload)
if response.status_code != 200:
fail('expected status code 200 but was {}'.format(response.status_code))
if len(response.cookies) != 2:
fail('expected 2 cookies but got {}'.format(len(response.cookies)))
if 'access_token' not in response.cookies:
fail('access_token not in cookies')
if 'refresh_token' not in response.cookies:
fail('refresh_token not in cookies')
def test_logout():
url = "http://localhost:80/api/auth/signup"
payload = {'username': 'test_user3', 'email': '[email protected]', 'password': 'test_password3'}
response = requests.post(url, json=payload)
url = "http://localhost:80/api/auth/logout"
response = requests.post(url, cookies=dict(response.cookies))
if response.status_code != 200:
fail('expected status code 200 but was {}'.format(response.status_code))
if len(response.cookies) != 0:
fail('expected 0 cookies but got {}'.format(len(response.cookies)))
def test_verify():
url = "http://localhost:80/api/auth/verify"
params = {'token': 'dummy'}
response = requests.post(url, params=params)
if response.status_code != 400:
fail('expected status code 400 but was {}'.format(response.status_code))
if __name__ == '__main__':
main()