-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.py
88 lines (65 loc) · 2.69 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
84
85
86
87
88
from server import app
from model import db
from model import User, Brew
from seed import seed_db
import feeder
import unittest
import doctest
# def load_tests(loader, tests, ignore):
# tests.addTests(doctest.DocTestSuite(feeder))
# tests.addTests(doctest.DocFileSuite("tests.txt"))
# return tests
class MyAppIntegrationTestCase(unittest.TestCase):
def setUp(self):
"""
Setup a testing only database
"""
self.app = app.test_client()
app.config['TESTING'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testingdb'
db.app = app
db.init_app(app)
db.create_all()
seed_db()
u = User(first_name='Jane', last_name='Smith', email='[email protected]', username='jsmith', password='test')
db.session.add(u)
db.session.commit()
self.login('jsmith', 'test')
def login(self, username, password):
return self.app.post('/login', data=dict(
username=username,
password=password
), follow_redirects=True)
def tearDown(self):
"""
Delete our testing database
"""
db.session.remove()
db.drop_all()
def test_upload(self):
self.assertEqual(feeder.load_recipes("olddata/samplerecipe.xml"), ("success", "Tester Recipe"))
def test_recipe(self):
result = self.app.get("/recipe/Nate's%20Citrus%20Bomb%20IPA")
self.assertIn("Citrus Bomb IPA</h3>", result.data)
self.assertIn('<div style="display: inline; width: 50px; height: 20px; background-color: #f39c00"> </div>',
result.data)
# TODO: Add tests for color calc on Explore page
def test_myrecipes(self):
result = self.app.get('/myrecipes')
self.assertIn('Beer Styles', result.data)
def test_brew(self):
result = self.app.get("/addbrew/Nate's%20Citrus%20Bomb%20IPA", follow_redirects=True)
# Does the correct color display for Nate's Citrus Bomb?
self.assertIn('<div style="width: 25px; height: 25px; background-color: #f39c00;">',
result.data)
result = self.app.get("/brew/1")
self.assertIn('<div style="width: 25px; height: 25px; background-color: #f39c00;">',
result.data)
def test_mybrews_color(self):
self.app.get("/addbrew/Nate's%20Citrus%20Bomb%20IPA")
result = self.app.get("/mybrews")
self.assertIn('<td rowspan="5" style="width: 5px; background-color: #f39c00;"></td>', result.data)
# TODO: Add test for ajax call trying color calculation display.
if __name__ == '__main__':
# If called like a script, run our tests
unittest.main()