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:
0
capsulflask/tests/__init__.py
Normal file
0
capsulflask/tests/__init__.py
Normal file
23
capsulflask/tests/test_auth.py
Normal file
23
capsulflask/tests/test_auth.py
Normal file
@ -0,0 +1,23 @@
|
||||
from flask import url_for, session
|
||||
|
||||
from capsulflask.db import get_model
|
||||
from capsulflask.tests_base import BaseTestCase
|
||||
|
||||
|
||||
class LoginTests(BaseTestCase):
|
||||
render_templates = False
|
||||
|
||||
def test_login_request(self):
|
||||
with self.client as client:
|
||||
response = client.get(url_for("auth.login"))
|
||||
self.assert_200(response)
|
||||
|
||||
# FIXME test generated login link
|
||||
|
||||
def test_login_magiclink(self):
|
||||
token, ignoreCaseMatches = get_model().login('test@example.com')
|
||||
|
||||
with self.client as client:
|
||||
response = client.get(url_for("auth.magiclink", token=token))
|
||||
self.assertRedirects(response, url_for("console.index"))
|
||||
self.assertEqual(session['account'], 'test@example.com')
|
14
capsulflask/tests/test_landing.py
Normal file
14
capsulflask/tests/test_landing.py
Normal file
@ -0,0 +1,14 @@
|
||||
from capsulflask.tests_base import BaseTestCase
|
||||
|
||||
|
||||
class LandingTests(BaseTestCase):
|
||||
#: Do not render templates, we're only testing logic here.
|
||||
render_templates = False
|
||||
|
||||
def test_landing(self):
|
||||
pages = ['/', 'pricing', 'faq', 'about-ssh', 'changelog', 'support']
|
||||
|
||||
with self.client as client:
|
||||
for page in pages:
|
||||
response = client.get(page)
|
||||
self.assert_200(response)
|
Reference in New Issue
Block a user