def test_leave(self): user = UserFactory() conversation = ConversationFactory() conversation.join(user) self.assertIn(user, conversation.participants.all()) conversation.leave(user) self.assertNotIn(user, conversation.participants.all())
def tests_receive_message_on_leave(self): user = UserFactory() # join a conversation conversation = ConversationFactory(participants=[ user, ]) # login and connect client = self.connect_as(user) conversation.leave(user) self.assertEqual(client.messages[0], {'topic': 'conversations:leave', 'payload': {'id': conversation.id}})
def test_other_participants_receive_update_on_leave(self): user = UserFactory() leaving_user = UserFactory() # join a conversation conversation = ConversationFactory(participants=[user, leaving_user]) # login and connect client = self.connect_as(user) conversation.leave(leaving_user) response = client.messages[0] self.assertEqual(response['topic'], 'conversations:conversation') self.assertEqual(response['payload']['participants'], [user.id])
def tests_receive_message_on_leave(self): client = WSClient() user = UserFactory() # join a conversation conversation = ConversationFactory() conversation.join(user) # login and connect client.force_login(user) client.send_and_consume('websocket.connect', path='/') conversation.leave(user) self.assertEqual(client.receive(json=True), { 'topic': 'conversations:leave', 'payload': { 'id': conversation.id } })
def test_other_participants_receive_update_on_leave(self): client = WSClient() user = UserFactory() leaving_user = UserFactory() # join a conversation conversation = ConversationFactory() conversation.join(user) conversation.join(leaving_user) # login and connect client.force_login(user) client.send_and_consume('websocket.connect', path='/') conversation.leave(leaving_user) response = client.receive(json=True) self.assertEqual(response['topic'], 'conversations:conversation') self.assertEqual(response['payload']['participants'], [user.id])