-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.py
135 lines (90 loc) · 3.63 KB
/
testing.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from server import app
from unittest import TestCase
from flask import session
from model import *
from helpers import *
from testing_seed_data import *
class MoonPhaseTrackerTests(TestCase):
"""Tests Moon Phase Tracker site"""
def setUp(self):
"""Code to run before every test."""
self.client = app.test_client()
app.config['TESTING'] = True
def test_homepage(self):
"""Tests homepage"""
result = self.client.get('/')
self.assertEqual(result.status_code, 200)
self.assertIn(b'<h3>Track the moon', result.data)
def test_calendar(self):
"""Tests page that displays calendar"""
result = self.client.get('/calendar')
self.assertEqual(result.status_code, 200)
self.assertIn(b'<h5 class="subheading">Click on any moon phase', result.data)
class TestMoonPhaseDatabase(TestCase):
"""Tests moon phase database"""
def setUp(self):
"""Code to run before every test."""
self.client = app.test_client()
app.config['TESTING'] = True
connect_to_db(app, db_uri='postgresql:///testdb')
db.create_all()
test_data()
def test_homepage(self):
"""Tests homepage"""
result = self.client.get('/')
self.assertEqual(result.status_code, 200)
self.assertIn(b'<title>Moon Phase Tracker</title>', result.data)
def tearDown(self):
"""Code to run after every test"""
db.session.remove()
db.drop_all()
db.engine.dispose()
class TestMoonPhaseLoggedIn(TestCase):
"""Tests site with user logged into session"""
def setUp(self):
"""Code to run before every test."""
app.config['TESTING'] = True
self.client = app.test_client()
connect_to_db(app, db_uri='postgresql:///testdb')
db.create_all()
test_data()
with self.client as c:
with c.session_transaction() as sess:
sess['email'] = '[email protected]'
def test_login(self):
"""Tests user log in"""
with self.client as c:
result = c.post('/login',
data={'email': '[email protected]', 'password': 'password'},
follow_redirects=True
)
self.assertEqual(result.status_code, 200)
self.assertIn(b'<title>Moon Phase Tracker</title>', result.data)
def test_process_registration(self):
"""Tests continuation of registration with email in session"""
with self.client as c:
result = c.post('/register', follow_redirects=True)
self.assertEqual(result.status_code, 200)
self.assertIn(b'<h3>Complete the form below to sign up for texts</h3>', result.data)
def test_settings(self):
"""Tests display settings with email in session"""
with self.client as c:
result = c.get('/display-settings', follow_redirects=True)
self.assertEqual(result.status_code, 200)
self.assertIn(b'<h3>Manage Settings</h3>', result.data)
def test_logout(self):
"""Tests logout route"""
with self.client as c:
with c.session_transaction() as sess:
sess['email'] = '[email protected]'
result = self.client.get('/logout', follow_redirects=True)
self.assertNotIn(b'email', sess)
self.assertIn(b'<title>Moon Phase Tracker</title>', result.data)
def tearDown(self):
"""Code to run after every test"""
db.session.remove()
db.drop_all()
db.engine.dispose()
if __name__ == '__main__':
import unittest
unittest.main()