-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtests.py
68 lines (50 loc) · 1.78 KB
/
tests.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
import unittest
import sys
from flask_testing import TestCase
from flask import abort, url_for
from app import create_app, db
from models.user import User
class TestBase(TestCase):
def create_app(self):
config_name="testing"
app = create_app(config_name)
app.config.update(
SQLALCHEMY_DATABASE_URI='mysql://admin@localhost/covidx_test'
)
return app
def setUp(self):
"""
called at the start of every test
"""
db.create_all()
test_user = User(user_id="1", display_name="john doe", email="[email protected]")
db.session.add(test_user)
# sys.stdout.write("Hello")
db.session.commit()
def tearDown(self):
"""
called after every test
"""
db.session.remove()
db.drop_all()
class TestModels(TestBase):
def test_user_model(self):
self.assertEqual(User.query.count(), 1)
class TestViews(TestBase):
def test_auth_login(self):
response = self.client.get(url_for("auth.login_user"))
self.assertEqual(response.status_code, 200)
def test_auth_create(self):
response = self.client.post(url_for("auth.create_user"),
data=dict(
user_id="2",
display_name="jane doe",
email="[email protected]")
)
self.assertEqual(response.status_code, 200)
def test_auth_update(self):
response = self.client.put(url_for("auth.update_user"),
data = dict(user_id="1", sex="female"))
self.assertEqual(response.status_code, 200)
if __name__ == '__main__':
unittest.main()