-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
120 lines (87 loc) · 3.81 KB
/
tests.py
File metadata and controls
120 lines (87 loc) · 3.81 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import unittest
from server import app
from model import db, connect_to_db, example_data
class Test(unittest.TestCase):
"""Tests for public pages."""
def setUp(self):
"""Do this before each test."""
self.client = app.test_client()
app.config['TESTING'] = True
# Connect to test database
connect_to_db(app, "postgresql:///test_database")
# Create tables and add sample data
db.create_all()
example_data()
def tearDown(self):
"""Do this after every test."""
# End session and delete tables
db.session.close()
db.drop_all()
def test_signup_page_render(self):
"""Tests that signup page loads."""
result = self.client.get("/signup")
self.assertEqual(result.status_code, 200)
self.assertIn("Create your", result.data)
def test_signin_page_render(self):
"""Tests that sign-in page loads."""
result = self.client.get("/signin")
self.assertEqual(result.status_code, 200)
self.assertIn("to your account", result.data)
# def test_create_new_user(self):
# """Tests database for existence of user created using create_new_user
# helper function."""
# result = User.query.filter(User.email == 'hb-student@hackbright.com').one()
# self.assertIn('with user_id', result.data)
class Test_Signed_In(unittest.TestCase):
"""Tests for pages requiring sign in."""
def setUp(self):
"""Do this before each test."""
self.client = app.test_client()
app.config['TESTING'] = True
app.config['SECRET_KEY'] = 'key'
# Store a value for user_id in the session to mimic signed-in user
with self.client as c:
with c.session_transaction() as sess:
sess['user_id'] = 1
# Connect to test database
connect_to_db(app, "postgresql:///test_database")
# Create tables and add sample data
db.create_all()
example_data()
def tearDown(self):
"""Do this after every test."""
# End session and delete tables
db.session.close()
db.drop_all()
def test_request_activity_types(self):
"""Tests activity setup page loads."""
result = self.client.get("/setup")
self.assertEqual(result.status_code, 200)
self.assertIn('usually ideal', result.data)
def test_create_activity_types(self):
"""Tests user can specify an activity type for tracking using every
available field on the setup page."""
result = self.client.post("/setup",
data={"activity_1": "coding",
"activity_2": "sports",
"activity_3": "shopping",
"activity_4": "friends",
"activity_5": "studying",
"activity_6": "meditation",
"activity_7": "family",
"activity_8": "napping",
"activity_9": "piano",
"activity_10": "writing"},
follow_redirects=True)
self.assertEqual(result.status_code, 200)
self.assertIn('Plan an Activity', result.data)
def test_main_page_render(self):
"""Tests that main page loads."""
result = self.client.get("/main")
self.assertEqual(result.status_code, 200)
self.assertIn("activity to begin tracking", result.data)
def test_get_table_sizes(self):
"""Tests get_table_sizes function."""
self.assertEqual(get_table_sizes((['name'] * 11), [(5, 1), (3, 2)])
if __name__ == '__main__':
unittest.main()