diff --git a/flask_security/utils.py b/flask_security/utils.py index 73d625f..03becf6 100644 --- a/flask_security/utils.py +++ b/flask_security/utils.py @@ -316,14 +316,15 @@ def capture_reset_password_requests(reset_password_sent_at=None): class CaptureSignals(object): - """ Testing utility for capturing blinker signals. + """Testing utility for capturing blinker signals. Context manager which mocks out selected signals and registers which are `sent` on and what arguments were sent. Instantiate with a list of blinker `NamedSignals` to patch. Each signal has it's `send` mocked out. """ def __init__(self, signals): - """ Patch all given signals and make them available as attributes. + """Patch all given signals and make them available as attributes. + :param signals: list of signals """ self._records = {} @@ -333,7 +334,8 @@ class CaptureSignals(object): self._receivers[signal] = functools.partial(self._record, signal) def __getitem__(self, signal): - """ All captured signals are available via `ctxt[signal]`.""" + """All captured signals are available via `ctxt[signal]`. + """ if isinstance(signal, blinker.base.NamedSignal): return self._records[signal] else: @@ -352,11 +354,14 @@ class CaptureSignals(object): signal.disconnect(receiver) def signals_sent(self): + """Return a set of the signals sent. + :rtype: list of blinker `NamedSignals`. + """ return set([signal for signal, _ in self._records.iteritems() if self._records[signal]]) def capture_signals(): - """ Factory method that creates a `CaptureSignals` with all the flask_security signals.""" + """Factory method that creates a `CaptureSignals` with all the flask_security signals.""" return CaptureSignals([user_registered, user_confirmed, confirm_instructions_sent, login_instructions_sent, password_reset, reset_password_instructions_sent]) diff --git a/tests/signals_tests.py b/tests/signals_tests.py index 8ad13ee..38fcf4b 100644 --- a/tests/signals_tests.py +++ b/tests/signals_tests.py @@ -10,7 +10,7 @@ from tests import SecurityTest def compare_user(a, b): - """ Helper to compare two users.""" + """Helper to compare two users.""" return a.id == b.id and a.email == b.email and a.password == b.password