def test_update_message(self): self.message1.save() message1 = Message.get(id=1) message1.update({'content': 'new_content'}) self.assertEqual('new_content', Message.get(id=1).content) self.assertTrue( isinstance(message1.update({'random': 'bad field'}), dict))
def test_add_and_remove_message_from_conversation(self): self.conversation1.save() self.message1.save() self.message2.save() conversation1 = Conversation.get(id=1) self.assertEqual(0, len(conversation1.messages)) conversation1.insert( 'messages', [Message.get(id=1), Message.get(id=2)]) self.assertEqual(True, isinstance(conversation1.messages[0], Message)) self.assertEqual(True, isinstance(conversation1.messages[1], Message)) self.assertEqual(2, len(conversation1.messages)) conversation1.remove('messages', id=1) self.assertEqual(1, len(conversation1.messages))
def test_get_all_messages(self): self.assertEqual(True, isinstance(Message.get(id=1), dict)) self.message1.save() self.message2.save() self.assertEqual(True, isinstance(Message.get_all()[0], Message)) self.assertEqual(True, isinstance(Message.get_all()[1], Message)) self.assertEqual(2, len(Message.get_all()))
def test_delete_message(self): self.message1.save() message1 = Message.get(id=1) self.assertTrue(message1.delete()) self.assertFalse(Message.check_exists(id=1))
def test_get_message(self): self.assertEqual(True, isinstance(Message.get(id=1), dict)) self.message1.save() self.assertEqual(True, isinstance(Message.get(id=1), Message))