Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions backend/test_flaskr.py
Original file line number Diff line number Diff line change
@@ -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, Question, Category


class TriviaTestCase(unittest.TestCase):
Expand All @@ -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
Expand All @@ -34,4 +42,4 @@ def tearDown(self):

# Make the tests conveniently executable
if __name__ == "__main__":
unittest.main()
unittest.main()
Loading