Skip to content
Snippets Groups Projects
Commit 7306f599 authored by florimondmanca's avatar florimondmanca
Browse files

fix bug preventing notification on participation creation

parent 77a36eed
No related branches found
No related tags found
No related merge requests found
...@@ -14,9 +14,8 @@ class NotifyParticipationTest(SignalTestMixin, TestCase): ...@@ -14,9 +14,8 @@ class NotifyParticipationTest(SignalTestMixin, TestCase):
"""Test the notify_participation signal handler.""" """Test the notify_participation signal handler."""
def setUp(self): def setUp(self):
VisitFactory.create() VisitFactory.create_batch(5)
user = UserFactory.create() self.obj = ParticipationFactory.create(accepted=None)
self.obj = ParticipationFactory.create(user=user, accepted=None)
def change(self, accepted=True): def change(self, accepted=True):
self.obj.accepted = accepted self.obj.accepted = accepted
...@@ -26,10 +25,14 @@ class NotifyParticipationTest(SignalTestMixin, TestCase): ...@@ -26,10 +25,14 @@ class NotifyParticipationTest(SignalTestMixin, TestCase):
with self.assertCalled(accepted_changed): with self.assertCalled(accepted_changed):
self.change() self.change()
def test_notification_sent_called_by_accepted(self): def test_accepted_changed_called_when_creating_accepted_partipant(self):
with self.assertCalled(accepted_changed):
ParticipationFactory.create(accepted=True)
def test_notification_sent_is_called_by_accepted(self):
with self.assertCalled(notification_sent, sender=Accepted): with self.assertCalled(notification_sent, sender=Accepted):
self.change(accepted=True) self.change(accepted=True)
def test_notification_sent_called_by_rejected(self): def test_notification_sent_is_called_by_rejected(self):
with self.assertCalled(notification_sent, sender=Rejected): with self.assertCalled(notification_sent, sender=Rejected):
self.change(accepted=False) self.change(accepted=False)
...@@ -10,9 +10,9 @@ accepted_changed = Signal() ...@@ -10,9 +10,9 @@ accepted_changed = Signal()
@receiver(post_save, sender=Participation) @receiver(post_save, sender=Participation)
def fire_accepted_changed(sender, instance: Participation, **kwargs): def fire_accepted_changed(sender, instance: Participation, created, **kwargs):
"""Fire an event if the participation status has changed.""" """Fire an event if the participation status has changed."""
if instance.accepted_changed(): if created or instance.accepted_changed():
accepted_changed.send(sender=sender, instance=instance) accepted_changed.send(sender=sender, instance=instance)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment