Пример #1
0
def edit(id):
    topic = Topic.find(id)
    if request.method == 'POST':
        topic.update({
            'title': request.form['title'],
            'body': request.form['body']
        })
        return redirect(url_for('topic.show', id=id))
    else:
        topic = Topic.find(id)
        return render_template('topics/edit.html', topic=topic)
Пример #2
0
def test_all(client):
    topic1 = Topic.create({ 'title': 'title1', 'body': 'body1' })
    topic2 = Topic.create({ 'title': 'title2', 'body': 'body2' })
    topics = Topic.all()
    assert len(topics) == 2
    assert Topic.find(topic1.id()).title() == topic1.title()
    assert Topic.find(topic1.id()).body() == topic1.body()
    assert Topic.find(topic2.id()).title() == topic2.title()
    assert Topic.find(topic2.id()).body() == topic2.body()

    topics = Topic.all(limit=1)
    assert len(topics) == 1
Пример #3
0
def test_update(client):
    topic = Topic.create({ 'title': 'title2', 'body': 'body2' })
    assert 'title2', topic.title()
    assert 'body2', topic.body()
    topic.update({ 'title': 'title3', 'body': 'body3' })
    assert 'title3', topic.title()
    assert 'body3', topic.body()
    topic = Topic.find(topic.id())
    assert 'title3', topic.title()
    assert 'body3', topic.body()
Пример #4
0
def new_comment(id):
    topic = Topic.find(id)
    if request.method == 'POST':
        Comment.create({
            'topic_id': topic.id(),
            'body': request.form['comment_body']
        })
        return redirect(url_for('topic.show', id=id))
    else:
        return render_template('comments/new.html', topic=topic)
Пример #5
0
def test_find(client):
    topic = Topic.create({ 'title': 'title2', 'body': 'body2' })
    topic = Topic.find(topic.id())
    assert 'title2', topic.title()
    assert 'body2', topic.body()
    assert type(topic) == Topic
Пример #6
0
def delete(id):
    topic = Topic.find(id)
    topic.destroy()
    return redirect(url_for('topic.index'))
Пример #7
0
def show(id):
    topic = Topic.find(id)
    comments = topic.comments()
    return render_template('topics/show.html', topic=topic, comments=comments)