open-law/tests/test_book_stats_properties.py

131 lines
3.9 KiB
Python
Raw Normal View History

from flask.testing import FlaskClient
from app import models as m
2023-06-12 12:22:36 +00:00
from tests.utils import (
login,
logout,
create_book,
create_collection,
create_section,
create_interpretation,
create_comment,
)
def test_approved_interpretations(client: FlaskClient):
2023-06-12 12:22:36 +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)
logout(client)
login(client, "test", "test")
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)
book: m.Book = m.Book.query.first()
assert len(book.approved_interpretations) == 0
for interpretation in m.Interpretation.query.all():
interpretation.approved = True
interpretation.save()
assert len(book.approved_interpretations) == 1
section: m.Section = m.Section.query.first()
assert section
interpretation: m.Interpretation = m.Interpretation(
2023-05-18 12:37:55 +00:00
section_id=section.id, text="123", approved=True
).save()
assert len(book.approved_interpretations) == 2
interpretation.is_deleted = True
interpretation.save()
assert len(book.approved_interpretations) == 1
collection: m.Collection = m.Collection.query.first()
sub_collection: m.Collection = m.Collection(
parent_id=collection.id,
label="123",
).save()
section: m.Section = m.Section(
2023-06-12 12:18:21 +00:00
label="123", collection_id=sub_collection.id, version_id=book.active_version.id
).save()
interpretation: m.Interpretation = m.Interpretation(
2023-05-18 12:37:55 +00:00
section_id=section.id, text="123", approved=True
).save()
assert len(book.approved_interpretations) == 2
sub_collection.is_deleted = True
sub_collection.save()
assert len(book.approved_interpretations) == 1
sub_collection.is_deleted = False
sub_collection.save()
assert len(book.approved_interpretations) == 2
# collection.is_deleted = True
# collection.save()
# assert len(book.approved_interpretations) == 0
def test_approved_comments(client: FlaskClient):
_, user = login(client)
2023-06-12 12:22:36 +00:00
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)
logout(client)
login(client, "test", "test")
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)
book: m.Book = m.Book.query.first()
assert len(book.approved_comments) == 0
for comment in m.Comment.query.all():
comment.approved = True
comment.save()
assert len(book.approved_comments) == 1
interpretation: m.Interpretation = m.Interpretation.query.first()
assert interpretation
comment: m.Comment = m.Comment(
text="231", approved=True, interpretation_id=interpretation.id
).save()
assert len(book.approved_comments) == 2
comment.is_deleted = True
comment.save()
assert len(book.approved_comments) == 1
comment: m.Comment = m.Comment(
text="456", approved=True, interpretation_id=interpretation.id
).save()
assert len(book.approved_comments) == 2
interpretation.is_deleted = True
interpretation.save()
assert len(book.approved_comments) == 0
interpretation.is_deleted = False
interpretation.save()
assert len(book.approved_comments) == 2