-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api.py
69 lines (49 loc) · 1.6 KB
/
test_api.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
import unittest
from main import create_app
from config import TestConfig
from exts import db
class APITestCase(unittest.TestCase):
def setUp(self):
self.app = create_app(TestConfig)
self.client = self.app.test_client(self)
with self.app.app_context():
db.init_app(self.app)
db.create_all()
def test_hello_world(self):
hello_response = self.client.get("/hello")
json = hello_response.json
# print(json)
self.assertEqual(json, {"message": "Hello World"})
def test_signup(self):
signup_response = self.client.post(
"/auth/signup",
json={
"username": "testuser",
"email": "[email protected]",
"password": "password",
},
)
status_code = signup_response.status_code
self.assertEqual(status_code, 201)
def test_login(self):
signup_response = self.client.post(
"/auth/signup",
json={
"username": "testuser",
"email": "[email protected]",
"password": "password",
},
)
login_response = self.client.post(
"auth/login", json={"username": "testuser", "password": "password"}
)
status_code = login_response.status_code
json = login_response.json
# print(json)
self.assertEqual(status_code, 200)
def tearDown(self):
with self.app.app_context():
db.session.remove()
db.drop_all()
if __name__ == "__main__":
unittest.main()