Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@contextmanager
def assertSignals(self, expected_events, sender=ANY):
events = []
def receiver_(signal, sender, **kwargs):
events.append((signal, sender, kwargs))
receivers = {
signal: partial(receiver_, signal) for signal in [
signals.before_create,
signals.after_create,
signals.before_update,
signals.after_update,
signals.before_delete,
signals.after_delete,
signals.before_add_to_relation,
signals.after_add_to_relation,
@contextmanager
def assertSignals(self, expected_events, sender=ANY):
events = []
def receiver_(signal, sender, **kwargs):
events.append((signal, sender, kwargs))
receivers = {
signal: partial(receiver_, signal) for signal in [
signals.before_create,
signals.after_create,
signals.before_update,
signals.after_update,
signals.before_delete,
signals.after_delete,
signals.before_add_to_relation,
signals.after_add_to_relation,
@contextmanager
def assertSignals(self, expected_events, sender=ANY):
events = []
def receiver_(signal, sender, **kwargs):
events.append((signal, sender, kwargs))
receivers = {
signal: partial(receiver_, signal) for signal in [
signals.before_create,
signals.after_create,
signals.before_update,
signals.after_update,
signals.before_delete,
signals.after_delete,
signals.before_add_to_relation,
signals.after_add_to_relation,
@contextmanager
def connected_to(self, receiver, sender=ANY):
"""Execute a block with the signal temporarily connected to *receiver*.
:param receiver: a receiver callable
:param sender: optional, a sender to filter on
This is a context manager for use in the ``with`` statement. It can
be useful in unit tests. *receiver* is connected to the signal for
the duration of the ``with`` block, and will be disconnected
automatically when exiting the block:
.. testsetup::
from __future__ import with_statement
from blinker import Signal
on_ready = Signal()
@contextmanager
def connected_to(self, receiver, sender=ANY):
"""Execute a block with the signal temporarily connected to *receiver*.
:param receiver: a receiver callable
:param sender: optional, a sender to filter on
This is a context manager for use in the ``with`` statement. It can
be useful in unit tests. *receiver* is connected to the signal for
the duration of the ``with`` block, and will be disconnected
automatically when exiting the block:
.. testsetup::
from __future__ import with_statement
from blinker import Signal
on_ready = Signal()
@contextmanager
def connected_to(self, receiver, sender=ANY):
"""Execute a block with the signal temporarily connected to *receiver*.
:param receiver: a receiver callable
:param sender: optional, a sender to filter on
This is a context manager for use in the ``with`` statement. It can
be useful in unit tests. *receiver* is connected to the signal for
the duration of the ``with`` block, and will be disconnected
automatically when exiting the block:
.. testsetup::
from __future__ import with_statement
from blinker import Signal
on_ready = Signal()
@contextmanager
def connected_to(self, receiver, sender=ANY):
"""Execute a block with the signal temporarily connected to *receiver*.
:param receiver: a receiver callable
:param sender: optional, a sender to filter on
This is a context manager for use in the ``with`` statement. It can
be useful in unit tests. *receiver* is connected to the signal for
the duration of the ``with`` block, and will be disconnected
automatically when exiting the block:
.. testsetup::
from __future__ import with_statement
from blinker import Signal
on_ready = Signal()
@contextmanager
def connected_to(self, receiver, sender=ANY):
"""Execute a block with the signal temporarily connected to *receiver*.
:param receiver: a receiver callable
:param sender: optional, a sender to filter on
This is a context manager for use in the ``with`` statement. It can
be useful in unit tests. *receiver* is connected to the signal for
the duration of the ``with`` block, and will be disconnected
automatically when exiting the block:
.. testsetup::
from __future__ import with_statement
from blinker import Signal
on_ready = Signal()