mirror of
https://github.com/wassname/flask-security.git
synced 2026-08-02 12:40:33 +08:00
Full test coverage!
This commit is contained in:
+40
-2
@@ -18,6 +18,7 @@ from flask.ext.security.datastore import SQLAlchemyUserDatastore, \
|
||||
MongoEngineUserDatastore
|
||||
from flask.ext.security.decorators import http_auth_required, \
|
||||
auth_token_required
|
||||
from flask.ext.security.exceptions import RoleNotFoundError
|
||||
|
||||
|
||||
def create_roles():
|
||||
@@ -45,12 +46,12 @@ def create_app(auth_config):
|
||||
app.debug = True
|
||||
app.config['SECRET_KEY'] = 'secret'
|
||||
|
||||
app.mail = Mail(app)
|
||||
|
||||
if auth_config:
|
||||
for key, value in auth_config.items():
|
||||
app.config[key] = value
|
||||
|
||||
app.mail = Mail(app)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html', content='Home Page')
|
||||
@@ -115,6 +116,43 @@ def create_app(auth_config):
|
||||
def unauthorized():
|
||||
return render_template('unauthorized.html')
|
||||
|
||||
@app.route('/coverage/add_role_to_user')
|
||||
def add_role_to_user():
|
||||
ds = app.security.datastore
|
||||
u = ds.find_user(email='joe@lp.com')
|
||||
r = ds.find_role('admin')
|
||||
ds.add_role_to_user(u, r)
|
||||
return 'success'
|
||||
|
||||
@app.route('/coverage/remove_role_from_user')
|
||||
def remove_role_from_user():
|
||||
ds = app.security.datastore
|
||||
u = ds.find_user(email='matt@lp.com')
|
||||
ds.remove_role_from_user(u, 'admin')
|
||||
return 'success'
|
||||
|
||||
@app.route('/coverage/deactivate_user')
|
||||
def deactivate_user():
|
||||
ds = app.security.datastore
|
||||
u = ds.find_user(email='matt@lp.com')
|
||||
ds.deactivate_user(u)
|
||||
return 'success'
|
||||
|
||||
@app.route('/coverage/activate_user')
|
||||
def activate_user():
|
||||
ds = app.security.datastore
|
||||
u = ds.find_user(email='tiya@lp.com')
|
||||
ds.activate_user(u)
|
||||
return 'success'
|
||||
|
||||
@app.route('/coverage/invalid_role')
|
||||
def invalid_role():
|
||||
ds = app.security.datastore
|
||||
try:
|
||||
ds.find_role('bogus')
|
||||
except RoleNotFoundError:
|
||||
return 'success'
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{% include "_messages.html" %}
|
||||
{% include "_nav.html" %}
|
||||
<h1>Register</h1>
|
||||
<form action="{{ url_for('flask_security.register') }}" method="POST" name="register_form">
|
||||
{{ register_user_form.hidden_tag() }}
|
||||
{{ register_user_form.email.label }} {{ register_user_form.email }}<br/>
|
||||
|
||||
Reference in New Issue
Block a user