Compare commits
3 Commits
feature-lo
...
test-cover
Author | SHA1 | Date | |
---|---|---|---|
3deaa39256 | |||
c20b302458 | |||
6f186c3a3f |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,3 +4,5 @@ __pycache__/
|
|||||||
/calsocial/translations/*/LC_MESSAGES/*.mo
|
/calsocial/translations/*/LC_MESSAGES/*.mo
|
||||||
/.pytest_cache/
|
/.pytest_cache/
|
||||||
/.env
|
/.env
|
||||||
|
/.coverage
|
||||||
|
/htmlcov/
|
||||||
|
@@ -18,11 +18,6 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from contextlib import contextmanager
|
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
|
@contextmanager
|
||||||
def force_locale(locale):
|
def force_locale(locale):
|
||||||
@@ -124,41 +119,3 @@ class RoutedMixin:
|
|||||||
return func
|
return func
|
||||||
|
|
||||||
return decorator
|
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
|
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
"""Helper functions and fixtures for testing
|
"""Helper functions and fixtures for testing
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import calsocial
|
import calsocial
|
||||||
@@ -70,3 +72,22 @@ def database():
|
|||||||
yield db
|
yield db
|
||||||
|
|
||||||
db.drop_all()
|
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]
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
import calsocial
|
import calsocial
|
||||||
from calsocial.models import db, User
|
from calsocial.models import db, User
|
||||||
|
|
||||||
from helpers import client
|
from helpers import alter_config, client
|
||||||
|
|
||||||
|
|
||||||
def test_register_page(client):
|
def test_register_page(client):
|
||||||
@@ -113,3 +113,9 @@ def test_register_existing_email(client):
|
|||||||
'password_retype': 'password',
|
'password_retype': 'password',
|
||||||
})
|
})
|
||||||
assert b'This email address can not be used' in page.data
|
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
|
||||||
|
Reference in New Issue
Block a user