from __future__ import annotations import json from flask.testing import FlaskClient from html5validate import validate 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 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