2023-11-27 19:25:33 -08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-03-29 18:17:29 -07:00
|
|
|
import json
|
2023-11-27 19:25:33 -08:00
|
|
|
|
2021-03-28 17:33:59 -07:00
|
|
|
from flask.testing import FlaskClient
|
2023-11-27 19:25:33 -08:00
|
|
|
from html5validate import validate
|
2021-03-28 17:33:59 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_admin_home_with_basic_user(client: FlaskClient, login_basic_user):
|
|
|
|
response = client.get("/admin/")
|
|
|
|
assert response.status_code == 403
|
|
|
|
|
|
|
|
|
|
|
|
def test_admin_home_with_admin_user(client: FlaskClient, login_admin_user):
|
|
|
|
response = client.get("/admin/")
|
|
|
|
assert response.status_code == 200
|
2021-03-29 18:17:29 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_edit_question_view_gives_json(client: FlaskClient, login_admin_user):
|
|
|
|
response = client.get("/admin/questions/edit/0", headers={"Accept": "application/json"})
|
|
|
|
assert response.headers.get("Content-Type") == "application/json"
|
|
|
|
data = json.loads(response.data)
|
|
|
|
assert "question_id" in data.keys()
|
|
|
|
assert type(data["question_id"]) is int
|
|
|
|
assert "question" in data.keys()
|
|
|
|
assert type(data["question"]) is str
|
|
|
|
assert "answer" in data.keys()
|
|
|
|
assert type(data["answer"]) is str
|
|
|
|
assert "addresses" in data.keys()
|
|
|
|
assert type(data["addresses"]) is str
|
|
|
|
|
|
|
|
|
|
|
|
def test_edit_question_view_gives_html(client: FlaskClient, login_admin_user):
|
|
|
|
response = client.get("/admin/questions/edit/0", headers={"Accept": "text/html"})
|
|
|
|
assert "text/html" in response.headers.get("Content-Type")
|
|
|
|
assert validate(response.data) is None
|
|
|
|
|
|
|
|
|
|
|
|
def test_edit_question_view(client: FlaskClient, login_admin_user):
|
|
|
|
response = client.get("/admin/questions/edit/0")
|
|
|
|
assert "text/html" in response.headers.get("Content-Type")
|
|
|
|
assert validate(response.data) is None
|