forked from gergely/calendar-social
Compare commits
2 Commits
test-cover
...
feature-lo
Author | SHA1 | Date | |
---|---|---|---|
b3cb42dbef | |||
f7d807370d |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,5 +4,3 @@ __pycache__/
|
|||||||
/calsocial/translations/*/LC_MESSAGES/*.mo
|
/calsocial/translations/*/LC_MESSAGES/*.mo
|
||||||
/.pytest_cache/
|
/.pytest_cache/
|
||||||
/.env
|
/.env
|
||||||
/.coverage
|
|
||||||
/htmlcov/
|
|
||||||
|
@@ -18,6 +18,11 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
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):
|
||||||
@@ -119,3 +124,41 @@ 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,8 +17,6 @@
|
|||||||
"""Helper functions and fixtures for testing
|
"""Helper functions and fixtures for testing
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from contextlib import contextmanager
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import calsocial
|
import calsocial
|
||||||
@@ -72,22 +70,3 @@ 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 alter_config, client
|
from helpers import client
|
||||||
|
|
||||||
|
|
||||||
def test_register_page(client):
|
def test_register_page(client):
|
||||||
@@ -113,9 +113,3 @@ 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