From f0e958477fcd72e6469006a40c402d7e255189f9 Mon Sep 17 00:00:00 2001 From: Daniel Abrao Date: Tue, 5 Nov 2024 01:28:38 -0300 Subject: [PATCH 1/2] Update test script to support Python 3.10 syntax --- backend/test_flaskr.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/backend/test_flaskr.py b/backend/test_flaskr.py index 7a9b6b783..1f1832fbf 100644 --- a/backend/test_flaskr.py +++ b/backend/test_flaskr.py @@ -1,10 +1,8 @@ import os import unittest -import json -from flask_sqlalchemy import SQLAlchemy from flaskr import create_app -from models import setup_db, Question, Category +from models import db class TriviaTestCase(unittest.TestCase): @@ -13,18 +11,28 @@ class TriviaTestCase(unittest.TestCase): def setUp(self): """Define test variables and initialize app.""" self.database_name = "trivia_test" - self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name) - + 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_DATABASE_URI": self.database_path, + "SQLALCHEMY_TRACK_MODIFICATIONS": False, + "TESTING": True }) + self.client = self.app.test_client() - 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 reach test""" - pass + """Executed after each test""" + with self.app.app_context(): + db.session.remove() + db.drop_all() """ TODO @@ -34,4 +42,4 @@ def tearDown(self): # Make the tests conveniently executable if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() From c08730bbd93e6ed5a09577d6f3778cfe0f167354 Mon Sep 17 00:00:00 2001 From: Daniel Abrao Date: Tue, 5 Nov 2024 01:29:43 -0300 Subject: [PATCH 2/2] Add data object models import statements --- backend/test_flaskr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/test_flaskr.py b/backend/test_flaskr.py index 1f1832fbf..20a355b90 100644 --- a/backend/test_flaskr.py +++ b/backend/test_flaskr.py @@ -2,7 +2,7 @@ import unittest from flaskr import create_app -from models import db +from models import db, Question, Category class TriviaTestCase(unittest.TestCase):