Skip to content

Commit

Permalink
Improves setUp by using the test_config parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
CurtesMalteser committed Feb 23, 2024
1 parent a7f6671 commit ab1de7f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
7 changes: 6 additions & 1 deletion backend/flaskr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__)
setup_db(app)

if test_config is None:
setup_db(app)
else:
database_path = test_config.get('SQLALCHEMY_DATABASE_URI')
setup_db(app, database_path=database_path)

"""
@TODO: Set up CORS. Allow '*' for origins. Delete the sample route after completing the TODOs
Expand Down
17 changes: 7 additions & 10 deletions backend/test_flaskr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ class TriviaTestCase(unittest.TestCase):

def setUp(self):
"""Define test variables and initialize app."""
self.app = create_app()
self.client = self.app.test_client
self.database_name = "trivia_test"
self.database_path = "postgres://{}/{}".format('localhost:5432', self.database_name)
setup_db(self.app, self.database_path)

# binds the app to the current context
with self.app.app_context():
self.db = SQLAlchemy()
self.db.init_app(self.app)
# create all tables
self.db.create_all()

self.app = create_app({
"SQLALCHEMY_DATABASE_URI": self.database_path
})

self.client = self.app.test_client


def tearDown(self):
"""Executed after reach test"""
Expand Down

0 comments on commit ab1de7f

Please sign in to comment.