Fixed dict iterations
Added simple test script
This commit is contained in:
parent
a94263ef6a
commit
142b809c63
3 changed files with 30 additions and 3 deletions
|
@ -140,7 +140,7 @@ class FilterSignal(Signal):
|
|||
|
||||
for receiver, _ in receivers:
|
||||
response = receiver(signal=self, sender=sender, **responses)
|
||||
for key, value in response:
|
||||
for key, value in response.items():
|
||||
responses[key] = value
|
||||
|
||||
return responses
|
||||
|
@ -183,7 +183,7 @@ class FilterSignal(Signal):
|
|||
for receiver, _ in receivers:
|
||||
try:
|
||||
response = receiver(signal=self, sender=sender, **responses)
|
||||
for key, value in response:
|
||||
for key, value in response.items():
|
||||
responses[key] = value
|
||||
except Exception as err:
|
||||
responses["_errors"].append((receiver, err))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[metadata]
|
||||
name = django-filtersignals
|
||||
version = 0.1
|
||||
version = 0.1.1
|
||||
description = Prioritized signals for Django projects
|
||||
long_description = file: README.md
|
||||
url = https://kumig.it/kumisystems/django-filtersignals
|
||||
|
|
27
test.py
Normal file
27
test.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import filtersignals
|
||||
|
||||
signal = filtersignals.FilterSignal()
|
||||
|
||||
class TestFilter:
|
||||
def __init__(self):
|
||||
processed = signal.send(self.__class__, this="great")
|
||||
if processed["this"] == "amazing":
|
||||
print("Test passed.")
|
||||
|
||||
@filtersignals.receiver(signal, priority=1, sender=TestFilter)
|
||||
def second_receiver(sender, **kwargs):
|
||||
return
|
||||
|
||||
@filtersignals.receiver(signal, priority=2, sender=TestFilter)
|
||||
def third_receiver(sender, **kwargs):
|
||||
if kwargs["this"] == "better":
|
||||
return {"this": "amazing"}
|
||||
return {"this": "sucks a lot"}
|
||||
|
||||
@filtersignals.receiver(signal, priority=0, sender=TestFilter)
|
||||
def first_receiver(sender, **kwargs):
|
||||
if kwargs["this"] == "great":
|
||||
return {"this": "better"}
|
||||
return {"this": "sucks"}
|
||||
|
||||
TestFilter()
|
Loading…
Reference in a new issue