-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
77 lines (52 loc) · 2.19 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
69
70
71
72
73
74
75
76
77
import unittest
from party import app
from model import db, example_data, connect_to_db
class PartyTests(unittest.TestCase):
"""Tests for my party site."""
def setUp(self):
self.client = app.test_client()
app.config['TESTING'] = True
app.config['SECRET_KEY'] = 'key'
with self.client as c:
with c.session_transaction() as sess:
sess['user_id'] = 1
def test_homepage(self):
result = self.client.get("/")
self.assertIn("board games, rainbows, and ice cream sundaes", result.data)
def test_no_rsvp_yet(self):
"""Test if user is not logged in with a session variable."""
result = self.client.get("/")
self.assertIn("Please RSVP", result.data)
self.assertNotIn("Party Details", result.data)
def test_rsvp(self):
result = self.client.post("/rsvp",
data={'name': "Jane", 'email': "jane@jane.com"},
follow_redirects=True)
self.assertIn("123 Magic Unicorn Way", result.data)
class PartyTestsDatabase(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
# adding a session variable to signify user has RSVP'd, since all tests
# in PartyTestsDatabases class assumes user has RSVP'd
with self.client as c:
with c.session_transaction() as sess:
sess['RSVP'] = True
# Connect to test database (uncomment when testing database)
connect_to_db(app, "postgresql:///testdb")
# Create tables and add sample data (uncomment when testing database)
db.create_all()
example_data()
def tearDown(self):
"""Do at end of every test."""
# (uncomment when testing database)
db.session.close()
db.drop_all()
def test_games(self):
#FIXME: test that the games page displays the game from example_data()
result = self.client.get('/games')
self.assertIn("chicken", result.data)
if __name__ == "__main__":
unittest.main()