-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
83 lines (58 loc) · 2.33 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
78
79
80
81
82
83
import unittest
from party import app
from model import db, example_data, connect_to_db, Game
class PartyTests(unittest.TestCase):
"""Tests for my party site."""
def setUp(self):
self.client = app.test_client()
app.config['TESTING'] = True
def test_homepage(self):
result = self.client.get("/")
self.assertIn(b"board games, rainbows, and ice cream sundaes", result.data)
def test_no_rsvp_yet(self):
# FIXME: Add a test to show we see the RSVP form, but NOT the
# party details
result = self.client.get("/")
self.assertIn(b"RSVP", result.data)
self.assertNotIn(b"Party Details", result.data)
def test_rsvp(self):
result = self.client.post("/rsvp",
data={"name": "Jane",
"email": "jane@jane.com"},
follow_redirects=True)
# FIXME: Once we RSVP, we should see the party details, but
# not the RSVP form
result = self.client.get("/")
self.assertNotIn(b"RSVP", result.data)
self.assertIn(b"Party Details", 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
# reset our sample database
# Game.query.delete()
# db.session.commit()
# 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("Chess", "A 2-person game of strategy.")
with self.client as c:
with c.session_transaction() as sess:
sess['RSVP'] = True
def tearDown(self):
"""Do at end of every test."""
# (uncomment when testing database)
db.session.close()
db.drop_all()
db.engine.dispose()
def test_games(self):
""" test that the games page displays the game from example_data()
"""
result = self.client.get("/games")
# print(result.data)
self.assertIn(b"Chess", result.data)
if __name__ == "__main__":
unittest.main()