mirror of
https://github.com/wassname/flask-security.git
synced 2026-07-14 01:10:34 +08:00
Stricter tests for signals and a small docs update. Fixes #308
This commit is contained in:
+14
-19
@@ -87,43 +87,38 @@ sends the following signals.
|
||||
|
||||
.. data:: user_registered
|
||||
|
||||
Sent when a user registers on the site. It is passed a dict with
|
||||
the `user` and `confirm_token`, the user being logged in and the
|
||||
(if so configured) the confirmation token issued.
|
||||
Sent when a user registers on the site. In addition to the app (which is the
|
||||
sender), it is passed `user` and `confirm_token` arguments.
|
||||
|
||||
.. data:: user_confirmed
|
||||
|
||||
Sent when a user is confirmed. It is passed `user`, which is the
|
||||
user being confirmed.
|
||||
Sent when a user is confirmed. In addition to the app (which is the
|
||||
sender), it is passed a `user` argument.
|
||||
|
||||
.. data:: confirm_instructions_sent
|
||||
|
||||
Sent when a user requests confirmation instructions. It is passed
|
||||
the `user`.
|
||||
Sent when a user requests confirmation instructions. In addition to the app
|
||||
(which is the sender), it is passed a `user` argument.
|
||||
|
||||
.. data:: login_instructions_sent
|
||||
|
||||
Sent when passwordless login is used and user logs in. It is passed
|
||||
a dict with the `user` and `login_token`, the user being logged in
|
||||
and the (if so configured) the login token issued.
|
||||
Sent when passwordless login is used and user logs in. In addition to the app
|
||||
(which is the sender), it is passed `user` and `login_token` arguments.
|
||||
|
||||
.. data:: password_reset
|
||||
|
||||
Sent when a user completes a password reset. It is passed the
|
||||
`user`.
|
||||
Sent when a user completes a password reset. In addition to the app (which is
|
||||
the sender), it is passed a `user` argument.
|
||||
|
||||
.. data:: password_changed
|
||||
|
||||
Sent when a user completes a password change. It is passed the
|
||||
`user`.
|
||||
Sent when a user completes a password change. In addition to the app (which is
|
||||
the sender), it is passed a `user` argument.
|
||||
|
||||
.. data:: reset_password_instructions_sent
|
||||
|
||||
Sent when a user requests a password reset. It is passed a dict
|
||||
with the `user` and `token`, the user being logged in and
|
||||
the (if so configured) the reset token issued.
|
||||
Sent when a user requests a password reset. In addition to the app (which is
|
||||
the sender), it is passed `user` and `token` arguments.
|
||||
|
||||
All signals are also passed a `app` keyword argument, which is the
|
||||
current application.
|
||||
|
||||
.. _Flask documentation on signals: http://flask.pocoo.org/docs/signals/
|
||||
|
||||
@@ -42,4 +42,5 @@ def change_user_password(user, password):
|
||||
user.password = encrypt_password(password)
|
||||
_datastore.put(user)
|
||||
send_password_changed_notice(user)
|
||||
password_changed.send(app._get_current_object(), user=user)
|
||||
password_changed.send(app._get_current_object(),
|
||||
user=user._get_current_object())
|
||||
|
||||
@@ -35,8 +35,7 @@ def send_login_instructions(user):
|
||||
send_mail(config_value('EMAIL_SUBJECT_PASSWORDLESS'), user.email,
|
||||
'login_instructions', user=user, login_link=login_link)
|
||||
|
||||
login_instructions_sent.send(app._get_current_object(),
|
||||
user=user, login_token=token)
|
||||
login_instructions_sent.send(app._get_current_object(), user=user, login_token=token)
|
||||
|
||||
|
||||
def generate_login_token(user):
|
||||
|
||||
@@ -35,8 +35,7 @@ def send_reset_password_instructions(user):
|
||||
'reset_instructions',
|
||||
user=user, reset_link=reset_link)
|
||||
|
||||
reset_password_instructions_sent.send(app._get_current_object(),
|
||||
user=user, token=token)
|
||||
reset_password_instructions_sent.send(app._get_current_object(), user=user, token=token)
|
||||
|
||||
|
||||
def send_password_reset_notice(user):
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from flask import Flask
|
||||
from flask_security.core import UserMixin
|
||||
from flask_security.signals import password_changed
|
||||
|
||||
from utils import authenticate
|
||||
@@ -20,6 +22,8 @@ def test_recoverable_flag(app, client, get_message):
|
||||
|
||||
@password_changed.connect_via(app)
|
||||
def on_password_changed(app, user):
|
||||
assert isinstance(app, Flask)
|
||||
assert isinstance(user, UserMixin)
|
||||
recorded.append(user)
|
||||
|
||||
authenticate(client)
|
||||
|
||||
@@ -10,6 +10,8 @@ import time
|
||||
|
||||
import pytest
|
||||
|
||||
from flask import Flask
|
||||
from flask_security.core import UserMixin
|
||||
from flask_security.signals import user_confirmed, confirm_instructions_sent
|
||||
from flask_security.utils import capture_registrations
|
||||
|
||||
@@ -25,10 +27,14 @@ def test_confirmable_flag(app, client, sqlalchemy_datastore, get_message):
|
||||
|
||||
@user_confirmed.connect_via(app)
|
||||
def on_confirmed(app, user):
|
||||
assert isinstance(app, Flask)
|
||||
assert isinstance(user, UserMixin)
|
||||
recorded_confirms.append(user)
|
||||
|
||||
@confirm_instructions_sent.connect_via(app)
|
||||
def on_instructions_sent(app, user):
|
||||
assert isinstance(app, Flask)
|
||||
assert isinstance(user, UserMixin)
|
||||
recorded_instructions_sent.append(user)
|
||||
|
||||
# Test login before confirmation
|
||||
|
||||
@@ -10,8 +10,10 @@ import time
|
||||
|
||||
import pytest
|
||||
|
||||
from flask import Flask
|
||||
from flask_security.core import UserMixin
|
||||
from flask_security.signals import login_instructions_sent
|
||||
from flask_security.utils import capture_passwordless_login_requests
|
||||
from flask_security.utils import capture_passwordless_login_requests, string_types
|
||||
|
||||
from utils import logout
|
||||
|
||||
@@ -23,6 +25,9 @@ def test_trackable_flag(app, client, get_message):
|
||||
|
||||
@login_instructions_sent.connect_via(app)
|
||||
def on_instructions_sent(app, user, login_token):
|
||||
assert isinstance(app, Flask)
|
||||
assert isinstance(user, UserMixin)
|
||||
assert isinstance(login_token, string_types)
|
||||
recorded.append(user)
|
||||
|
||||
# Test disabled account
|
||||
|
||||
@@ -10,8 +10,10 @@ import time
|
||||
|
||||
import pytest
|
||||
|
||||
from flask import Flask
|
||||
from flask_security.core import UserMixin
|
||||
from flask_security.signals import reset_password_instructions_sent, password_reset
|
||||
from flask_security.utils import capture_reset_password_requests
|
||||
from flask_security.utils import capture_reset_password_requests, string_types
|
||||
|
||||
from utils import authenticate, logout
|
||||
|
||||
@@ -28,6 +30,9 @@ def test_recoverable_flag(app, client, get_message):
|
||||
|
||||
@reset_password_instructions_sent.connect_via(app)
|
||||
def on_instructions_sent(app, user, token):
|
||||
assert isinstance(app, Flask)
|
||||
assert isinstance(user, UserMixin)
|
||||
assert isinstance(token, string_types)
|
||||
recorded_instructions_sent.append(user)
|
||||
|
||||
# Test the reset view
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from flask import Flask
|
||||
from flask_security.core import UserMixin
|
||||
from flask_security.signals import user_registered
|
||||
|
||||
from utils import authenticate, logout
|
||||
@@ -26,6 +28,9 @@ def test_registerable_flag(client, app, get_message):
|
||||
# Test registering is successful, sends email, and fires signal
|
||||
@user_registered.connect_via(app)
|
||||
def on_user_registerd(app, user, confirm_token):
|
||||
assert isinstance(app, Flask)
|
||||
assert isinstance(user, UserMixin)
|
||||
assert confirm_token is None
|
||||
recorded.append(user)
|
||||
|
||||
data = dict(
|
||||
|
||||
Reference in New Issue
Block a user