forked from 3wordchant/capsul-flask
Basic testing using flask-testing
This commit makes it possible to override settings during tests, by switching capsulflask/__init__.py to a "create_app" pattern, and using `dotenv_values` instead of `load_dotenv`. The create_app() method returns a Flask app instance, to give more control over when to initialise the app. This allows setting environment variables in test files. Then, use dotenv_values to override loaded .env variables with ones from the environment, so that tests can set `POSTGRES_CONNECTION_PARAMETERS` and `SPOKE_MODEL` (possibly others in future..). Inital tests for the "landing" pages, and login / activation, are included.
This commit is contained in:
25
capsulflask/tests_base.py
Normal file
25
capsulflask/tests_base.py
Normal file
@ -0,0 +1,25 @@
|
||||
import os
|
||||
from nanoid import generate
|
||||
|
||||
from flask_testing import TestCase
|
||||
|
||||
from capsulflask import create_app
|
||||
|
||||
class BaseTestCase(TestCase):
|
||||
def create_app(self):
|
||||
# Use default connection paramaters
|
||||
os.environ['POSTGRES_CONNECTION_PARAMETERS'] = "host=localhost port=5432 user=postgres password=dev dbname=capsulflask_test"
|
||||
os.environ['TESTING'] = '1'
|
||||
os.environ['SPOKE_MODEL'] = 'mock'
|
||||
return create_app()
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def _login(self, user_email):
|
||||
with self.client.session_transaction() as session:
|
||||
session['account'] = user_email
|
||||
session['csrf-token'] = generate()
|
Reference in New Issue
Block a user