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
4 changed files with 30 additions and 44 deletions

2
.gitignore vendored
View File

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

View File

@@ -18,11 +18,6 @@
"""
from contextlib import contextmanager
from functools import wraps
from flask import flash, redirect, url_for
from flask_babelex import gettext as _
from flask_security import current_user
@contextmanager
def force_locale(locale):
@@ -124,41 +119,3 @@ class RoutedMixin:
return func
return decorator
def beta(func):
"""Decorator to hide beta features from non-beta testers
"""
@wraps(func)
def decorated(*args, **kwargs): # pylint: disable=missing-docstring
if current_user.settings['beta'] != 'True':
flash(_('Join the beta testers to enable this functionality!'))
return redirect(url_for('account.settings'))
return func(*args, **kwargs)
return decorated
def feature_lock(feature): # pylint: disable=missing-return-doc,missing-return-type-doc
"""Decorator to lock a feature
:param feature: the name of a feature
:type feature: str
"""
def decorator(func): # pylint: disable=missing-docstring
@wraps(func)
def decorated(*args, **kwargs): # pylint: disable=missing-docstring
from calsocial.models import AppState
if AppState[f'feature:{feature}'] == 'true':
return func(*args, **kwargs)
return 'Feature locked'
return decorated
return decorator

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