def conversation_msgs(conversation, user, admin_user): message = Message(user_id=user.id, conversation_id=conversation.id, message="First message") conversation.save(message=message) message = Message(user_id=admin_user.id, conversation_id=conversation.id, message="Second message") conversation.save(message=message) return conversation
def save(self, conversation, user_id, unread=False): """Saves the form data to the model. :param conversation: The Conversation object. :param user_id: The id from the user who sent the message. :param reciever: If the message should also be stored in the recievers inbox. """ message = Message(message=self.message.data, user_id=user_id) if unread: conversation.unread = True conversation.save() return message.save(conversation)
def test_conversation_save(conversation): """ also tests message.save() since we must create a message to save """ message = Message( user_id=conversation.user_id, conversation_id=conversation.id, message="Hello World" ) conversation.save(message=message) assert conversation.shared_id is not None
def test_last_message(conversation_msgs, user): conversation = conversation_msgs assert conversation.last_message.message == "Second message" message = Message( user_id=user.id, message="Third message" ) conversation.save(message=message) assert conversation.last_message.message != "Second message"
def save(self, from_user, to_user, user_id, unread, as_draft=False, shared_id=None): conversation = Conversation( subject=self.subject.data, draft=as_draft, shared_id=shared_id, from_user_id=from_user, to_user_id=to_user, user_id=user_id, unread=unread ) message = Message(message=self.message.data, user_id=from_user) return conversation.save(message=message)