-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_server.py
104 lines (72 loc) · 3.55 KB
/
test_server.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""test suite for testing track well's server.py"""
from server import app
import unittest
from model import db, example_data, connect_to_db
class MyAppIntegrationTestCase(unittest.TestCase):
"""testing Flask server"""
def setUp(self):
self.client = app.test_client()
app.config['TESTING'] = True
def test_index(self):
result = self.client.get('/')
self.assertIn('<h1>Welcome to track well</h1>', result.data)
def my_stats(self):
result = self.client.get('/my_stats')
self.assertIn(' <p>Out of all the activities you are tracking,', result.data)
def test_add_info_page(self):
with self.client as c:
with c.session_transaction() as sess:
sess['current_user'] = "Leroy"
result = self.client.get('/record_daily_input')
self.assertIn('Record what you did and how you felt yesterday', result.data)
class WellnessTrackerTestsDatabase(unittest.TestCase):
"""Flask tests that use the database."""
def setUp(self):
"""Stuff to do before every test."""
self.client = app.test_client()
app.config['TESTING'] = True
connect_to_db(app, "postgresql:///example_database")
db.create_all()
example_data()
def test_login_and_logout(self):
result = self.client.post("/login",
data={"email_input": "Leroy",
"pw_input": "bad"},
follow_redirects=True)
self.assertIn('Out of all the activities you are tracking', result.data)
result = self.client.get("/logout", follow_redirects=True)
self.assertIn('Welcome to track well', result.data)
result = self.client.post("/login",
data={"email_input": "Leroy",
"pw_input": "cheese"},
follow_redirects=True)
self.assertIn('Invalid password. Please try again.', result.data)
result = self.client.post("/login",
data={"email_input": "Heroy",
"pw_input": "cheese"},
follow_redirects=True)
self.assertIn('That email is not in our database. Please check your spelling, or use the form below to register', result.data)
def test_registration(self):
result = self.client.post('/register', data={'email_input':'[email protected]', 'pw_input':'scrtvwls', 'name':'Tony'},
follow_redirects=True)
self.assertIn('We have your email as [email protected]', result.data)
def test_registration_confirmation(self):
with self.client as c:
with c.session_transaction() as sess:
sess['current_user'] = "Leroy"
result = self.client.get('/registration_confirmation')
self.assertIn('Welcome, Brown!', result.data)
def test_rsquared(self):
with self.client as c:
with c.session_transaction() as sess:
sess['current_user'] = "Leroy"
result = self.client.get("/my_stats")
self.assertIn("Out of all the activities you are tracking, exercise is the most relevent to your sense of well-being.", result.data)
#sleep r2 should be 0.07409284
#exercise r2 should be 0.19998784
def tearDown(self):
"""Do at end of every test."""
db.session.close()
db.drop_all()
if __name__ == "__main__":
unittest.main()