-
Notifications
You must be signed in to change notification settings - Fork 920
/
Copy pathtest_flaskr.py
45 lines (35 loc) · 1.33 KB
/
test_flaskr.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
import os
import unittest
from flaskr import create_app
from models import db, Question, Category
class TriviaTestCase(unittest.TestCase):
"""This class represents the trivia test case"""
def setUp(self):
"""Define test variables and initialize app."""
self.database_name = "trivia_test"
self.database_user = "postgres"
self.database_password = "password"
self.database_host = "localhost:5432"
self.database_path = f"postgresql://{self.database_user}:{self.database_password}@{self.database_host}/{self.database_name}"
# Create app with the test configuration
self.app = create_app({
"SQLALCHEMY_DATABASE_URI": self.database_path,
"SQLALCHEMY_TRACK_MODIFICATIONS": False,
"TESTING": True
})
self.client = self.app.test_client()
# Bind the app to the current context and create all tables
with self.app.app_context():
db.create_all()
def tearDown(self):
"""Executed after each test"""
with self.app.app_context():
db.session.remove()
db.drop_all()
"""
TODO
Write at least one test for each test for successful operation and for expected errors.
"""
# Make the tests conveniently executable
if __name__ == "__main__":
unittest.main()