def test_create_message(self): msg = self.d.new_message(sender=self.u1, body='text_body') self.assertTrue(Message.query.filter_by(id=1).first_or_404()) self.assertIs(msg, Message.query.filter_by(id=1).first_or_404()) self.assertEqual( Message.query.filter_by(id=1).first().body, 'text_body') self.assertIs(Dialog.get_by_id(1).last_message, msg) self.assertIsNot(Dialog.get_by_id(2).last_message, msg)
def dialog(id): if not current_user.dialogs.filter_by(id=id).all(): return redirect(url_for('dialogs.dialogs')) d: Dialog = Dialog.get_by_id(id) other_users = d.get_recipients(current_user) if not d: flash('You have not gor this dialog') return redirect(url_for('dialogs.dialogs')) form = MessageForm() if form.validate_on_submit(): d.new_message(sender=current_user, body=form.message.data) return redirect(url_for('dialogs.dialog', id=id)) # user_dialog = Dialog.query.filter_by(id=id).first_or_404() msg_list = [] if d: # msg_list = Message.query.filter_by(dialog_id=id).order_by(Message.timestamp_send.desc()).paginate(1, 100, False) msg_list = d.messages.order_by(Message.timestamp_send.desc()).paginate( 1, 100, False) return render_template('dialogs/dialog_window.html', messages_list=msg_list.items, form=form, width=50, recipients=other_users)
def test_create_dialog_ids(self): self.create_users() d = Dialog.create_dialog_new(ids=(1, 2, 3)) self.assertEqual(d, Dialog.get_by_id(1))
def test_get_by_id(self): self.create_users() d = self.create_dialog(self.u1, self.u2) d1 = self.create_dialog(self.u1, self.u3) self.assertIs(d, Dialog.get_by_id(1)) self.assertIsNot(d, Dialog.get_by_id(2))