-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_unittest.py
66 lines (45 loc) · 1.74 KB
/
test_unittest.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
from server import app
from model import db, connect_to_db
import unittest
import test_db
import testing.postgresql
from sqlalchemy import create_engine
import os
class ServerTests(unittest.TestCase):
"""Runs tests on routes/page render"""
def setUp(self):
"""Code to run before every test."""
self.client = app.test_client() # test_client from Werkzeug library returns a "browser" to "run" app
app.config['TESTING'] = True
def test_homepage(self):
"""Does homepage load?"""
result = self.client.get("/")
self.assertEqual(result.status_code, 200)
self.assertIn(b'<h1 class="text-center main-title">Cello<br>Tree</h1>', result.data)
# TODO: test what renders based on user login
class TestDb(unittest.TestCase):
"""Runs tests on database"""
def setUp(self):
"""Code to run before every test."""
self.client = app.test_client()
os.system('dropdb testdb')
os.system('createdb testdb')
self.postgresql = testing.postgresql.Postgresql(name="testdb", port=7654)
create_engine(self.postgresql.url())
app.config['TESTING'] = True
connect_to_db(app, db_uri="postgresql:///testdb")
db.create_all()
test_db.test_all()
def test_homepage(self):
"""Can I add everything to my db?"""
result = self.client.get('/')
self.assertEqual(result.status_code, 200)
self.assertIn(b'<h1 class="text-center main-title">Cello<br>Tree</h1>', result.data)
def tearDown(self):
"""Code to run after every test"""
db.session.remove()
db.drop_all()
db.engine.dispose()
self.postgresql.stop()
if __name__ == "__main__":
unittest.main(verbosity=2)