def index(self): form = SendMessageForm() if form.validate_on_submit(): send_messages(form.users_list, form.message.data) else: flash_errors(form) return self.render('admin/message.html', form=form)
def test_validate_success(self, user): form = SendMessageForm(users=[user.id], message='Test') form.users.choices = [(user.id, user.full_name)] assert form.validate() is True assert user in form.users_list
def test_validate_empty_message(self, user): form = SendMessageForm(users=[user.id]) assert form.validate() is False assert 'This field is required.' in form.message.errors
def test_validate_no_recipients_selected(self, user): pass form = SendMessageForm(message='Test Message') assert form.validate() is False assert 'This field is required.' in form.users.errors