2023-05-16 08:31:17 +00:00
|
|
|
from flask import current_app as Response
|
2023-05-16 10:27:19 +00:00
|
|
|
from flask.testing import FlaskClient
|
2023-05-16 08:31:17 +00:00
|
|
|
|
2023-06-14 11:14:39 +00:00
|
|
|
from app import models as m
|
2023-06-12 13:23:17 +00:00
|
|
|
from tests.utils import (
|
|
|
|
create_book,
|
|
|
|
create_collection,
|
|
|
|
create_comment,
|
|
|
|
create_interpretation,
|
|
|
|
create_section,
|
|
|
|
login,
|
|
|
|
)
|
2023-05-16 10:27:19 +00:00
|
|
|
|
|
|
|
|
2023-05-17 15:39:37 +00:00
|
|
|
def test_create_tags_on_book_create_and_edit(client: FlaskClient):
|
2023-05-16 10:27:19 +00:00
|
|
|
login(client)
|
|
|
|
|
|
|
|
BOOK_NAME = "Test Book"
|
|
|
|
tags = "tag1,tag2,tag3"
|
|
|
|
|
|
|
|
response: Response = client.post(
|
|
|
|
"/book/create",
|
|
|
|
data=dict(label=BOOK_NAME, tags=tags),
|
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert b"Book added!" in response.data
|
|
|
|
|
|
|
|
book = m.Book.query.filter_by(label=BOOK_NAME).first()
|
|
|
|
assert book.tags
|
|
|
|
|
2023-05-26 11:10:14 +00:00
|
|
|
splitted_tags = [tag.lower() for tag in tags.split(",")]
|
2023-05-16 10:27:19 +00:00
|
|
|
assert len(book.tags) == 3
|
|
|
|
for tag in book.tags:
|
|
|
|
tag: m.Tag
|
|
|
|
assert tag.name in splitted_tags
|
|
|
|
|
|
|
|
tags_from_db: m.Tag = m.Tag.query.all()
|
|
|
|
assert len(tags_from_db) == 3
|
2023-05-16 08:31:17 +00:00
|
|
|
|
|
|
|
tags = "tag1,tag2,tag3"
|
|
|
|
|
|
|
|
client.post(
|
|
|
|
f"/book/{book.id}/edit",
|
|
|
|
data=dict(book_id=book.id, label=book.label, tags=tags),
|
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
book: m.Book = m.Book.query.first()
|
|
|
|
|
2023-05-26 11:10:14 +00:00
|
|
|
splitted_tags = [tag.lower() for tag in tags.split(",")]
|
2023-05-16 08:31:17 +00:00
|
|
|
assert len(book.tags) == 3
|
|
|
|
for tag in book.tags:
|
|
|
|
tag: m.Tag
|
|
|
|
assert tag.name in splitted_tags
|
|
|
|
|
|
|
|
tags_from_db: m.Tag = m.Tag.query.all()
|
|
|
|
assert len(tags_from_db) == 3
|
|
|
|
|
|
|
|
tags = "tag1,tag2,tag4"
|
|
|
|
|
|
|
|
client.post(
|
|
|
|
f"/book/{book.id}/edit",
|
|
|
|
data=dict(book_id=book.id, label=book.label, tags=tags),
|
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
tags_from_db: m.Tag = m.Tag.query.all()
|
|
|
|
assert len(tags_from_db) == 4
|
|
|
|
book: m.Book = m.Book.query.first()
|
|
|
|
assert len(book.tags) == 3
|
|
|
|
|
|
|
|
tags = "1" * 33
|
|
|
|
|
|
|
|
client.post(
|
|
|
|
f"/book/{book.id}/edit",
|
|
|
|
data=dict(book_id=book.id, label=book.label, tags=tags),
|
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
tags_from_db: m.Tag = m.Tag.query.all()
|
|
|
|
assert len(tags_from_db) == 4
|
|
|
|
book: m.Book = m.Book.query.first()
|
|
|
|
assert len(book.tags) == 0
|
2023-05-16 10:38:51 +00:00
|
|
|
|
|
|
|
|
2023-05-17 15:01:39 +00:00
|
|
|
def test_create_tags_on_comment_create_and_edit(client: FlaskClient):
|
2023-06-12 13:23:17 +00:00
|
|
|
login(client)
|
|
|
|
book = create_book(client)
|
|
|
|
collection, _ = create_collection(client, book.id)
|
|
|
|
section, _ = create_section(client, book.id, collection.id)
|
|
|
|
interpretation, _ = create_interpretation(client, book.id, section.id)
|
|
|
|
comment, _ = create_comment(client, book.id, interpretation.id)
|
2023-05-16 10:38:51 +00:00
|
|
|
|
2023-06-01 11:39:42 +00:00
|
|
|
tags = "#tag1 #tag2 #tag3"
|
2023-05-16 10:38:51 +00:00
|
|
|
response: Response = client.post(
|
2023-05-30 07:24:25 +00:00
|
|
|
f"/book/{book.id}/{interpretation.id}/create_comment",
|
2023-05-16 10:38:51 +00:00
|
|
|
data=dict(
|
|
|
|
section_id=section.id,
|
2023-05-22 11:44:12 +00:00
|
|
|
text="some text" + tags,
|
2023-05-16 10:38:51 +00:00
|
|
|
interpretation_id=interpretation.id,
|
|
|
|
),
|
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
2023-05-22 11:44:12 +00:00
|
|
|
comment: m.Comment = m.Comment.query.filter_by(text="some text" + tags).first()
|
2023-05-16 10:38:51 +00:00
|
|
|
assert comment
|
|
|
|
assert comment.tags
|
|
|
|
|
2023-06-01 11:39:42 +00:00
|
|
|
splitted_tags = [tag.lower().replace("#", "") for tag in tags.split()]
|
2023-05-16 10:38:51 +00:00
|
|
|
assert len(comment.tags) == 3
|
|
|
|
for tag in comment.tags:
|
|
|
|
tag: m.Tag
|
|
|
|
assert tag.name in splitted_tags
|
|
|
|
|
|
|
|
tags_from_db: m.Tag = m.Tag.query.all()
|
|
|
|
assert len(tags_from_db) == 3
|
2023-05-17 09:32:25 +00:00
|
|
|
|
2023-06-01 11:39:42 +00:00
|
|
|
tags = "#tag1 #tag5 #tag7"
|
2023-05-17 15:01:39 +00:00
|
|
|
response: Response = client.post(
|
2023-05-30 07:24:25 +00:00
|
|
|
f"/book/{book.id}/{interpretation.id}/comment_edit",
|
2023-05-22 11:44:12 +00:00
|
|
|
data=dict(text="some text" + tags, comment_id=comment.id),
|
2023-05-17 15:01:39 +00:00
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
2023-05-22 11:44:12 +00:00
|
|
|
comment: m.Comment = m.Comment.query.filter_by(text="some text" + tags).first()
|
2023-05-17 15:01:39 +00:00
|
|
|
assert comment
|
|
|
|
assert comment.tags
|
|
|
|
|
2023-06-01 11:39:42 +00:00
|
|
|
splitted_tags = [tag.lower().replace("#", "") for tag in tags.split()]
|
2023-05-17 15:01:39 +00:00
|
|
|
assert len(comment.tags) == 3
|
|
|
|
for tag in comment.tags:
|
|
|
|
tag: m.Tag
|
|
|
|
assert tag.name in splitted_tags
|
|
|
|
|
|
|
|
tags_from_db: m.Tag = m.Tag.query.all()
|
|
|
|
assert len(tags_from_db) == 5
|
|
|
|
|
2023-05-17 09:32:25 +00:00
|
|
|
|
|
|
|
def test_create_tags_on_interpretation_create_and_edit(client: FlaskClient):
|
2023-06-12 13:23:17 +00:00
|
|
|
login(client)
|
|
|
|
book = create_book(client)
|
|
|
|
collection, _ = create_collection(client, book.id)
|
|
|
|
section, _ = create_section(client, book.id, collection.id)
|
|
|
|
interpretation, _ = create_interpretation(client, book.id, section.id)
|
2023-05-17 09:32:25 +00:00
|
|
|
|
2023-06-01 11:39:42 +00:00
|
|
|
tags = "#tag1 #tag2 #tag3"
|
|
|
|
text_1 = "Test Interpretation no1 Text"
|
2023-05-17 09:32:25 +00:00
|
|
|
|
|
|
|
response: Response = client.post(
|
2023-05-30 07:24:25 +00:00
|
|
|
f"/book/{book.id}/{section.id}/create_interpretation",
|
2023-05-22 11:44:12 +00:00
|
|
|
data=dict(section_id=section.id, text=text_1 + tags),
|
2023-05-17 09:32:25 +00:00
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
|
2023-05-22 11:44:12 +00:00
|
|
|
text=text_1 + tags, section_id=section.id
|
2023-05-17 09:32:25 +00:00
|
|
|
).first()
|
|
|
|
assert interpretation
|
|
|
|
assert interpretation.tags
|
|
|
|
|
2023-06-01 11:39:42 +00:00
|
|
|
splitted_tags = [tag.lower().replace("#", "") for tag in tags.split()]
|
2023-05-17 09:32:25 +00:00
|
|
|
assert len(interpretation.tags) == 3
|
|
|
|
for tag in interpretation.tags:
|
|
|
|
tag: m.Tag
|
|
|
|
assert tag.name in splitted_tags
|
|
|
|
|
|
|
|
tags_from_db: m.Tag = m.Tag.query.all()
|
|
|
|
assert len(tags_from_db) == 3
|
|
|
|
|
2023-06-01 11:39:42 +00:00
|
|
|
tags = "#tag4 #tag3 #tag5"
|
2023-05-17 09:32:25 +00:00
|
|
|
response: Response = client.post(
|
2023-05-30 07:12:43 +00:00
|
|
|
f"/book/{book.id}/{interpretation.id}/edit_interpretation",
|
2023-05-22 11:44:12 +00:00
|
|
|
data=dict(interpretation_id=interpretation.id, text=text_1 + tags),
|
2023-05-17 09:32:25 +00:00
|
|
|
follow_redirects=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
|
2023-05-22 11:44:12 +00:00
|
|
|
text=text_1 + tags, section_id=section.id
|
2023-05-17 09:32:25 +00:00
|
|
|
).first()
|
|
|
|
assert interpretation
|
|
|
|
|
2023-06-01 11:39:42 +00:00
|
|
|
splitted_tags = [tag.lower().replace("#", "") for tag in tags.split()]
|
2023-05-17 09:32:25 +00:00
|
|
|
assert len(interpretation.tags) == 3
|
|
|
|
for tag in interpretation.tags:
|
|
|
|
tag: m.Tag
|
|
|
|
assert tag.name in splitted_tags
|
|
|
|
|
|
|
|
tags_from_db: m.Tag = m.Tag.query.all()
|
|
|
|
assert len(tags_from_db) == 5
|