open-law/tests/test_approve.py

135 lines
3.8 KiB
Python
Raw Normal View History

2023-05-11 15:02:14 +00:00
from flask import current_app as Response
from flask.testing import FlaskClient
from app import models as m
2023-06-12 12:18:21 +00:00
from tests.utils import (
login,
logout,
create_book,
create_collection,
create_section,
create_interpretation,
create_comment,
)
2023-05-11 15:02:14 +00:00
def test_approve_interpretation(client: FlaskClient):
2023-06-12 12:18:21 +00:00
dummy_user = m.User(username="test", password="test").save()
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)
2023-05-11 15:02:14 +00:00
2023-06-12 12:18:21 +00:00
logout(client)
login(client)
2023-05-11 15:02:14 +00:00
response: Response = client.post(
"/approve/interpretation/999",
data=dict(
positive=True,
),
follow_redirects=True,
)
assert response
assert b"You do not have permission" in response.data
2023-05-11 15:02:14 +00:00
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
user_id=dummy_user.id
).first()
response: Response = client.post(
f"/approve/interpretation/{interpretation.id}",
follow_redirects=True,
)
assert response
assert b"You do not have permission" in response.data
2023-05-11 15:02:14 +00:00
2023-06-12 12:18:21 +00:00
logout(client)
login(client, "test", "test")
2023-05-11 15:02:14 +00:00
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
2023-06-12 12:18:21 +00:00
user_id=dummy_user.id
2023-05-11 15:02:14 +00:00
).first()
response: Response = client.post(
f"/approve/interpretation/{interpretation.id}",
follow_redirects=True,
)
assert response
assert response.json["message"] == "success"
assert response.json["approve"]
assert interpretation.approved
interpretation: m.Interpretation = m.Interpretation.query.filter_by(
2023-06-12 12:18:21 +00:00
user_id=dummy_user.id
2023-05-11 15:02:14 +00:00
).first()
response: Response = client.post(
f"/approve/interpretation/{interpretation.id}",
follow_redirects=True,
)
assert response
assert response.json["message"] == "success"
assert not response.json["approve"]
assert not interpretation.approved
def test_approve_comment(client: FlaskClient):
2023-06-12 12:18:21 +00:00
dummy_user = m.User(username="test", password="test").save()
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)
2023-05-11 15:02:14 +00:00
2023-06-12 12:18:21 +00:00
logout(client)
login(client)
2023-05-11 15:02:14 +00:00
response: Response = client.post(
"/approve/comment/999",
data=dict(
positive=True,
),
follow_redirects=True,
)
assert response
assert b"You do not have permission" in response.data
2023-05-11 15:02:14 +00:00
comment: m.Comment = m.Comment.query.filter_by(user_id=dummy_user.id).first()
response: Response = client.post(
f"/approve/comment/{comment.id}",
follow_redirects=True,
)
assert response
assert b"You do not have permission" in response.data
2023-05-11 15:02:14 +00:00
2023-06-12 12:18:21 +00:00
logout(client)
login(client, "test", "test")
comment: m.Comment = m.Comment.query.filter_by(user_id=dummy_user.id).first()
2023-05-11 15:02:14 +00:00
response: Response = client.post(
f"/approve/comment/{comment.id}",
follow_redirects=True,
)
assert response
assert response.json["message"] == "success"
assert response.json["approve"]
assert comment.approved
2023-06-12 12:18:21 +00:00
comment: m.Collection = m.Comment.query.filter_by(user_id=dummy_user.id).first()
2023-05-11 15:02:14 +00:00
response: Response = client.post(
f"/approve/comment/{comment.id}",
follow_redirects=True,
)
assert response
assert response.json["message"] == "success"
assert not response.json["approve"]
assert not comment.approved