Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Commit

Permalink
Test whether signal works well
Browse files Browse the repository at this point in the history
  • Loading branch information
winterjung committed Nov 14, 2018
1 parent a32f89d commit 69e3e3d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/chat/tests/test_models.py
@@ -1,4 +1,7 @@
from unittest.mock import patch

import pytest
from django.db.models.signals import post_save

from api.chat.models import Message, Room, User

Expand All @@ -22,3 +25,18 @@ def test_new_msg(self, msg):
assert msg.content == 'hello'
assert msg.room.id == 1
assert msg.sender.id == 1

@patch('api.chat.signals.post_save.send')
def test_message_signal(self, mock, users, room):
Message.objects.create(content='test', room=room, sender=users[0])
assert mock.called
assert mock.call_count == 1

def test_message_receiver(self, users, room):
self.called = False
def handler(sender, **kwargs):
self.called = True
post_save.connect(handler)

Message.objects.create(content='test', room=room, sender=users[0])
assert self.called

0 comments on commit 69e3e3d

Please sign in to comment.