def create_topic(): form = TopicForm(request.form) if not form.validate(): return render_template("forum/topic_new.html", form=form) name = form.name.data new_topic = Topic(name, g.area.id) new_topic.account_id = current_user.id db.session().add(new_topic) db.session().commit() message = form.message.data # Remove possible ghost messages because SQLAlchemy reuses ids Message.query.filter_by(topic_id=new_topic.id).delete() new_msg = Message(message, new_topic.id) new_msg.account_id = current_user.id db.session().add(new_msg) db.session().commit() return redirect(url_for("topic.topic", area_name=g.area.name, created=new_topic.created))
def test_new(client): topic = Topic({ 'title': 'fi', 'body': 'body' }) assert 'fi', topic.title assert 'body', topic.body