Skip to content

Commit f1dfc51

Browse files
authored
Merge pull request #43 from jungleBadger/main
Update test script to support Python 3.10 syntax
2 parents a0ffcc3 + c08730b commit f1dfc51

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

backend/test_flaskr.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import os
22
import unittest
3-
import json
4-
from flask_sqlalchemy import SQLAlchemy
53

64
from flaskr import create_app
7-
from models import setup_db, Question, Category
5+
from models import db, Question, Category
86

97

108
class TriviaTestCase(unittest.TestCase):
@@ -13,18 +11,28 @@ class TriviaTestCase(unittest.TestCase):
1311
def setUp(self):
1412
"""Define test variables and initialize app."""
1513
self.database_name = "trivia_test"
16-
self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name)
17-
14+
self.database_user = "postgres"
15+
self.database_password = "password"
16+
self.database_host = "localhost:5432"
17+
self.database_path = f"postgresql://{self.database_user}:{self.database_password}@{self.database_host}/{self.database_name}"
18+
19+
# Create app with the test configuration
1820
self.app = create_app({
19-
"SQLALCHEMY_DATABASE_URI": self.database_path
21+
"SQLALCHEMY_DATABASE_URI": self.database_path,
22+
"SQLALCHEMY_TRACK_MODIFICATIONS": False,
23+
"TESTING": True
2024
})
25+
self.client = self.app.test_client()
2126

22-
self.client = self.app.test_client
27+
# Bind the app to the current context and create all tables
28+
with self.app.app_context():
29+
db.create_all()
2330

24-
2531
def tearDown(self):
26-
"""Executed after reach test"""
27-
pass
32+
"""Executed after each test"""
33+
with self.app.app_context():
34+
db.session.remove()
35+
db.drop_all()
2836

2937
"""
3038
TODO
@@ -34,4 +42,4 @@ def tearDown(self):
3442

3543
# Make the tests conveniently executable
3644
if __name__ == "__main__":
37-
unittest.main()
45+
unittest.main()

0 commit comments

Comments
 (0)