From b032e793de4b5a0b906675c6c31b2c89b44a88e0 Mon Sep 17 00:00:00 2001 From: Matthew Welch Date: Mon, 29 Mar 2021 18:17:29 -0700 Subject: [PATCH] Add tests for the edit_question view --- QuizTheWord/admin/templates/admin/base.html | 2 +- QuizTheWord/templates/base.html | 2 +- tests/conftest.py | 2 +- tests/test_admin.py | 28 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/QuizTheWord/admin/templates/admin/base.html b/QuizTheWord/admin/templates/admin/base.html index 5e162f6..60e639f 100644 --- a/QuizTheWord/admin/templates/admin/base.html +++ b/QuizTheWord/admin/templates/admin/base.html @@ -35,8 +35,8 @@ Created By ItIsGood.com - {% block scripts %}{% endblock %} + \ No newline at end of file diff --git a/QuizTheWord/templates/base.html b/QuizTheWord/templates/base.html index 7fa98c3..926883b 100644 --- a/QuizTheWord/templates/base.html +++ b/QuizTheWord/templates/base.html @@ -20,8 +20,8 @@ Created By ItIsGood.com - {% block scripts %}{% endblock %} + \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 67d5cdb..d8a5111 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,7 +19,7 @@ def session(): @pytest.fixture(scope="module") -def init_database(client, session): +def init_database(session): init_db() user_datastore = SQLAlchemySessionUserDatastore(session, User, Role) diff --git a/tests/test_admin.py b/tests/test_admin.py index dc13d48..3c0cd54 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -1,3 +1,5 @@ +import json +from html5validate import validate from flask.testing import FlaskClient @@ -9,3 +11,29 @@ def test_admin_home_with_basic_user(client: FlaskClient, login_basic_user): 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