fix tests

This commit is contained in:
Kostiantyn Stoliarskyi 2023-05-30 10:24:25 +03:00
parent d9944a4209
commit 05b000fb58
3 changed files with 15 additions and 31 deletions

View File

@ -1,4 +1,4 @@
from flask import flash, redirect, url_for, current_app, request
from flask import flash, redirect, url_for, current_app
from flask_login import login_required, current_user
from app.controllers import (
@ -22,12 +22,6 @@ def create_comment(
book_id: int,
interpretation_id: int,
):
current_url = request.referrer
if not current_url:
current_url = url_for(
"book.collection_view",
book_id=book_id,
)
book: m.Book = db.session.get(m.Book, book_id)
if not book or book.is_deleted:
log(log.INFO, "User: [%s] is not owner of book: [%s]", current_user, book)
@ -69,7 +63,7 @@ def create_comment(
set_comment_tags(comment, tags)
flash("Success!", "success")
return redirect(current_url)
return redirect(redirect_url)
else:
log(log.ERROR, "Comment create errors: [%s]", form.errors)
for field, errors in form.errors.items():
@ -90,12 +84,9 @@ def comment_delete(
book_id: int,
interpretation_id: int,
):
current_url = request.referrer
if not current_url:
current_url = url_for(
"book.collection_view",
book_id=book_id,
)
redirect_url = url_for(
"book.qa_view", book_id=book_id, interpretation_id=interpretation_id
)
form = f.DeleteCommentForm()
comment_id = form.comment_id.data
comment: m.Comment = db.session.get(m.Comment, comment_id)
@ -107,7 +98,7 @@ def comment_delete(
comment.save()
flash("Success!", "success")
return redirect(current_url)
return redirect(redirect_url)
flash("Invalid id!", "danger")
return redirect(
url_for(
@ -127,12 +118,9 @@ def comment_edit(
book_id: int,
interpretation_id: int,
):
current_url = request.referrer
if not current_url:
current_url = url_for(
"book.collection_view",
book_id=book_id,
)
redirect_url = url_for(
"book.qa_view", book_id=book_id, interpretation_id=interpretation_id
)
form = f.EditCommentForm()
if form.validate_on_submit():
@ -149,7 +137,7 @@ def comment_edit(
comment.save()
flash("Success!", "success")
return redirect(current_url)
return redirect(redirect_url)
flash("Invalid id!", "danger")
return redirect(

View File

@ -1035,9 +1035,8 @@ def test_crud_comment(client: FlaskClient, runner: FlaskCliRunner):
# edit
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/{interpretation.id}/comment_edit",
f"/book/{book.id}/{interpretation.id}/comment_edit",
data=dict(
section_id=section_in_subcollection.id,
text=new_text,
interpretation_id=interpretation.id,
comment_id=comment.id,
@ -1053,9 +1052,8 @@ def test_crud_comment(client: FlaskClient, runner: FlaskCliRunner):
# delete
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{sub_collection.id}/{section_in_subcollection.id}/{interpretation.id}/comment_delete",
f"/book/{book.id}/{interpretation.id}/comment_delete",
data=dict(
section_id=section_in_subcollection.id,
text=comment_text,
interpretation_id=interpretation.id,
comment_id=comment.id,

View File

@ -83,13 +83,12 @@ def test_create_tags_on_comment_create_and_edit(client: FlaskClient):
create_test_book(user.id, 1)
book = db.session.get(m.Book, 1)
collection = db.session.get(m.Collection, 1)
section = db.session.get(m.Section, 1)
interpretation = db.session.get(m.Interpretation, 1)
tags = "[tag1] [tag2] [tag3]"
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{section.id}/{interpretation.id}/create_comment",
f"/book/{book.id}/{interpretation.id}/create_comment",
data=dict(
section_id=section.id,
text="some text" + tags,
@ -116,7 +115,7 @@ def test_create_tags_on_comment_create_and_edit(client: FlaskClient):
tags = "[tag1] [tag5] [tag7]"
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{section.id}/{interpretation.id}/comment_edit",
f"/book/{book.id}/{interpretation.id}/comment_edit",
data=dict(text="some text" + tags, comment_id=comment.id),
follow_redirects=True,
)
@ -143,14 +142,13 @@ def test_create_tags_on_interpretation_create_and_edit(client: FlaskClient):
create_test_book(user.id, 1)
book = db.session.get(m.Book, 1)
collection = db.session.get(m.Collection, 1)
section = db.session.get(m.Section, 1)
tags = "[tag1] [tag2] [tag3]"
text_1 = "Test Interpretation #1 Text"
response: Response = client.post(
f"/book/{book.id}/{collection.id}/{section.id}/create_interpretation",
f"/book/{book.id}/{section.id}/create_interpretation",
data=dict(section_id=section.id, text=text_1 + tags),
follow_redirects=True,
)