-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
74 lines (55 loc) · 2.24 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
import unittest
from server import app
from model import Line, Song, Character, example_data, connect_to_db, db
# from comparisons import comp_songs, make_json
class BasicTests(unittest.TestCase):
"""Flask tests that do not use the database."""
def setUp(self):
self.client = app.test_client()
app.config['TESTING'] = True
def test_homepage(self):
result = self.client.get("/") # <- response object
self.assertIn("<h3></h3>", result.data)
print "Tested Homepage"
def test_song_data(self):
result = self.client.get("/bundle_data.json")
self.assertIn("Alexander Hamilton", result.data)
print "Tested jsonified song data"
class PartyTestsDatabase(unittest.TestCase):
"""Flask tests that use the database."""
def setUp(self):
"""Do before every test."""
self.client = app.test_client()
app.config['TESTING'] = True
# Connect to test database
connect_to_db(app, "postgresql:///travis_ci_test")
# Create tables and add sample data
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_get_lyrics(self):
result = self.client.get("/get_lyrics.json?title=song1")
self.assertIn("Look around!", result.data)
self.assertIn("Hamilton", result.data)
print "Tested song lyrics request"
def test_compare_songs(self):
result = self.client.get("/compare_songs.json?title1=song1&title2=song2")
self.assertIn("Look around!", result.data)
self.assertIn("Burr", result.data)
print "Tested song comparison request"
def test_bar_data_lower(self):
result = self.client.get("/bar_data.json?search=bastard")
self.assertIn("orphan", result.data)
self.assertIn("1", result.data)
print "Tested bar data (lower) request"
def test_bar_data_upper(self):
result = self.client.get("/bar_data.json?search=Bastard")
self.assertIn("orphan", result.data)
self.assertIn("1", result.data)
print "Tested bar data (upper) request"
if __name__ == "__main__":
unittest.main()