Skip to content

Commit

Permalink
Fix #283
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroLQueiroz committed May 9, 2024
1 parent d1b9187 commit 825b0d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion notifications/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def notify_handler(sender, **kwargs):
setattr(newnotify, key, kwargs.pop(key))
newnotify.data = kwargs

newnotify.save()
new_notifications.append(newnotify)
Notification.objects.bulk_create(new_notifications)

return new_notifications

Expand Down
11 changes: 8 additions & 3 deletions notifications/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_send():
target = TargetFactory()
action_object = TargetFactory()
timestamp = now()
notify.send(
notifications = notify.send(
sender=actor,
recipient=recipient,
verb="poked",
Expand All @@ -34,10 +34,11 @@ def test_send():
level=NotificationLevel.ERROR,
target=target,
action_object=action_object,
)
)[0]

assert Notification.objects.count() == 1
notification = Notification.objects.first()
assert notifications[1][0] == notification
assert notification.actor == actor
assert notification.recipient == recipient
assert notification.verb == "poked"
Expand All @@ -57,9 +58,13 @@ def test_send_to_multiple_recipients():
recipient2 = RecipientFactory()
recipient1.groups.add(group)

notify.send(sender=actor, recipient=[recipient1, recipient2], verb="poked you")
notifications = notify.send(sender=actor, recipient=[recipient1, recipient2], verb="poked you")
assert Notification.objects.filter(actor_object_id=actor.id, recipient=recipient1, verb="poked you").count() == 1
assert Notification.objects.filter(actor_object_id=actor.id, recipient=recipient2, verb="poked you").count() == 1
assert notifications[0][1][0] == Notification.objects.filter(recipient=recipient1)[0]
assert notifications[0][1][1] == Notification.objects.filter(recipient=recipient2)[0]
assert notifications[0][1][0].id == 1
assert notifications[0][1][1].id == 2

recipients = User.objects.filter(username__startswith="recipient")
notify.send(sender=actor, recipient=recipients, verb="poked you")
Expand Down

0 comments on commit 825b0d5

Please sign in to comment.