-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
executable file
·79 lines (62 loc) · 2.09 KB
/
test.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
# -*- coding: utf-8 -*-
import unittest
from datetime import datetime
from kido import app, csrf
from kido.models import db, Child, User
class ChildViewTestCase(unittest.TestCase):
def test_child_view(self):
first_name = "Martha"
last_name = "Sosa"
birth_date = datetime.strptime("2009-02-02", "%Y-%m-%d")
test_child_view = Child(
first_name=first_name, last_name=last_name, birth_date=birth_date
)
currenttime = datetime.now()
expected_age = (currenttime - birth_date).days / 365
self.assertEqual(test_child_view.age, expected_age)
class AuthTestCase(unittest.TestCase):
def setUp(self):
self.client = app.test_client()
def test_can_login(self):
password = "testpass"
user = User(
first_name="Testuser",
last_name="Tester",
email="[email protected]",
password=password,
)
db.session.add(user)
db.session.commit()
response = self.client.post(
"/login",
data=dict(email=user.email, password=password),
follow_redirects=True,
)
self.assertEqual(response.status_code, 200)
self.assertIn("Log Out", response.data.decode())
db.session.delete(user)
db.session.commit()
def test_can_sign_out(self):
password = "testpass"
user = User(
first_name="Testuser",
last_name="Tester",
email="[email protected]",
password=password,
)
db.session.add(user)
db.session.commit()
response = self.client.post(
"/", data=dict(email=user.email, password=password), follow_redirects=True
)
response = self.client.get("/logout", follow_redirects=True)
self.assertEqual(response.status_code, 200)
self.assertIn("Login", response.data.decode())
db.session.delete(user)
db.session.commit()
if __name__ == "__main__":
app.testing = True
csrf._csrf_disable = True
db.init_app(app)
db.create_all()
unittest.main()