Skip to content

Commit 7d64e39

Browse files
authored
Merge pull request #38 from CurtesMalteser/feature/use_test_config
Improves setUp by using the test_config parameter
2 parents a7f6671 + ab1de7f commit 7d64e39

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

backend/flaskr/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
def create_app(test_config=None):
1212
# create and configure the app
1313
app = Flask(__name__)
14-
setup_db(app)
14+
15+
if test_config is None:
16+
setup_db(app)
17+
else:
18+
database_path = test_config.get('SQLALCHEMY_DATABASE_URI')
19+
setup_db(app, database_path=database_path)
1520

1621
"""
1722
@TODO: Set up CORS. Allow '*' for origins. Delete the sample route after completing the TODOs

backend/test_flaskr.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ class TriviaTestCase(unittest.TestCase):
1212

1313
def setUp(self):
1414
"""Define test variables and initialize app."""
15-
self.app = create_app()
16-
self.client = self.app.test_client
1715
self.database_name = "trivia_test"
1816
self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name)
19-
setup_db(self.app, self.database_path)
20-
21-
# binds the app to the current context
22-
with self.app.app_context():
23-
self.db = SQLAlchemy()
24-
self.db.init_app(self.app)
25-
# create all tables
26-
self.db.create_all()
17+
18+
self.app = create_app({
19+
"SQLALCHEMY_DATABASE_URI": self.database_path
20+
})
21+
22+
self.client = self.app.test_client
23+
2724

2825
def tearDown(self):
2926
"""Executed after reach test"""

0 commit comments

Comments
 (0)