def test_channel_addChat_method_fails_wrong_args(self): """ ensure that the method works as expected""" channel2 = PublicChannel(name='channel2') channel2.save() badchat = {"sender": "joe", "message": "this is message", "rando": 32} # will cause error and decorator shall handle it channel2.addChat(**badchat)
def test_channel_getChats_method(self): """ ensure that the method works as expected""" numberofchats = 5 channel2 = PublicChannel(name='channel2') channel2.save() for i in range(numberofchats): channel2.addChat(**{"sender": "joe", "message": "this is message"}) self.assertEqual(numberofchats, len(channel2.getChats()))
def test_channel_getlastchat_method(self): """ ensure that the method works as expected""" channel2 = PublicChannel(name='channel2') channel2.save() chat1 = {"sender": "joe", "message": "this is message"} chat2 = {"sender": "jim", "message": "this is other message"} channel2.addChat(**chat1) channel2.addChat(**chat2) lastchat = channel2.getlastchat() lastchat.pop("date") self.assertEqual(chat2, lastchat)
def test_channel_addChat_method(self): """ ensure that the method works as expected""" channel2 = PublicChannel(name='channel2') channel2.save() chat = {"sender": "joe", "message": "this is message"} channel2.addChat(**chat) self.assertIsNotNone(channel2.chats) recievedchat = channel2.chats[0] self.assertEqual( { "sender": recievedchat.sender, "message": recievedchat.message }, chat)