3 Commits

Author SHA1 Message Date
3deaa39256 [Test] Add test for disabled registration 2018-07-23 13:22:50 +02:00
c20b302458 Add the alter_config context manager for testing
It can temporarily change an app configuration value.
2018-07-23 13:22:50 +02:00
6f186c3a3f Add coverage related files to .gitignore 2018-07-23 13:22:50 +02:00
3 changed files with 30 additions and 1 deletions

2
.gitignore vendored
View File

@@ -4,3 +4,5 @@ __pycache__/
/calsocial/translations/*/LC_MESSAGES/*.mo
/.pytest_cache/
/.env
/.coverage
/htmlcov/

View File

@@ -17,6 +17,8 @@
"""Helper functions and fixtures for testing
"""
from contextlib import contextmanager
import pytest
import calsocial
@@ -70,3 +72,22 @@ def database():
yield db
db.drop_all()
@contextmanager
def alter_config(app, **kwargs):
saved = {}
for key, value in kwargs.items():
if key in app.config:
saved[key] = app.config[key]
app.config[key] = value
yield
for key, value in kwargs.items():
if key in saved:
app.config[key] = saved[key]
else:
del app.config[key]

View File

@@ -20,7 +20,7 @@
import calsocial
from calsocial.models import db, User
from helpers import client
from helpers import alter_config, client
def test_register_page(client):
@@ -113,3 +113,9 @@ def test_register_existing_email(client):
'password_retype': 'password',
})
assert b'This email address can not be used' in page.data
def test_registration_disabled(client):
with alter_config(calsocial.app, REGISTRATION_ENABLED=False):
page = client.get('/accounts/register')
assert b'Registration is disabled' in page.data