diff --git a/app/routes.py b/app/routes.py index 302160d..8bf7c1c 100644 --- a/app/routes.py +++ b/app/routes.py @@ -15,8 +15,6 @@ app = Flask(__name__) jinja_partials.register_extensions(app) -# TODO: test that every endpoint logs the request. - @app.before_request def create_data_service() -> None: @@ -49,12 +47,21 @@ def get_survey(uid: str) -> str: data_service: DataService = app.data_service # type: ignore[attr-defined] survey_uid = UUID(uid) survey = data_service.get_survey_if_open(survey_uid=survey_uid) - questions = data_service.get_text_questions_from_survey(survey_uid=survey_uid) if survey is None: abort(404, "Could not find a survey with that UUID.") - return render_template("survey.html", survey=survey, questions=questions) + text_questions = data_service.get_text_questions_from_survey(survey_uid=survey_uid) + dimensional_questions = data_service.get_dimensional_questions_from_survey( + survey_uid=survey_uid + ) + + return render_template( + "survey.html", + survey=survey, + text_questions=text_questions, + dimensional_questions=dimensional_questions, + ) @app.route("/surveys/new") diff --git a/app/templates/survey.html b/app/templates/survey.html index 4e0573b..0400a05 100644 --- a/app/templates/survey.html +++ b/app/templates/survey.html @@ -3,12 +3,25 @@ {% block content %}

{{survey.name}}

+

Note: Answering Questions is not yet implemented & this page is for testing purposes only.

+ +
+{% for question in text_questions %} +

{{question.question}}

+{% endfor %}
-{% for question in questions %} -

{{question.question}}

+ +
+{% for question in dimensional_questions %} +

{{question.question}}

+
    +
  • question.dimension_one
  • +
  • question.dimension_two
  • +
  • question.dimension_three
  • +
{% endfor %}
-Answering Questions is not yet implemented. + {% endblock %} diff --git a/data/initial_data.sql b/data/initial_data.sql index 220a10a..7529d29 100644 --- a/data/initial_data.sql +++ b/data/initial_data.sql @@ -15,9 +15,29 @@ INSERT INTO text_question ( ) VALUES ( '9c9facb5-f360-4155-852a-8e2ac04607ea' , '4b5bfb06-2060-4abf-b5fd-3bae5dcf72b9' - , 'What is your name?' -), ( - 'ee947616-3d16-4095-bc8f-603be72022d3' - , '4b5bfb06-2060-4abf-b5fd-3bae5dcf72b9' - , 'Are you sure?' + , 'What story would you tell your best friend about this company?' +); + +INSERT INTO dimensional_question ( + uid + , survey_uid + , question + , dimension_one + , dimension_two + , dimension_three +) VALUES ( + "4ccfc2b3-c18a-4c86-b918-1f30efdfeea2" + , "4b5bfb06-2060-4abf-b5fd-3bae5dcf72b9" + , "How strongly does this story demonstrate the following values?" + , "Empathy to Colleagues" + , "Service to Others" + , "Individual Growth" +), +( + "a6938e91-e7cc-4048-9b77-8cbba8d735cd" + , "4b5bfb06-2060-4abf-b5fd-3bae5dcf72b9" + , "How strongly does this story demonstrate the following values?" + , "Accountability" + , "Efficiency" + , "Individual Growth" ); diff --git a/tests/integration/test_application.py b/tests/integration/test_application.py index cb34017..c18bd6f 100644 --- a/tests/integration/test_application.py +++ b/tests/integration/test_application.py @@ -5,6 +5,7 @@ from app.data_service import DataService, Sqlite3Driver from app.models import Survey +from tests.unit.test_routes_helpers import assert_response_is_valid_html @pytest.fixture @@ -19,6 +20,24 @@ def patched_init(self, driver): monkeypatch.undo() +class TestReadEndpoints: + test_cases = ( + "/", + "/admin", + "/surveys/new", + "/surveys/00000000-1f7c-43e9-ab61-3c34fd59a333", + ) + + @pytest.mark.parametrize("slug", test_cases) + def test_endpoint_returns_html( + self, app_client, setup_data_service, slug: str + ) -> None: + response = app_client.get(slug) + + assert response.status_code == 200 + assert_response_is_valid_html(response) + + class TestMutationEndpoints: test_cases = [ ( @@ -38,7 +57,7 @@ class TestMutationEndpoints: "name": "test mutable endpoints 2", "is_open": "on", "question-0": "What's my name again?", - "question-1": "What's you name again?", + "question-1": "What's your name again?", "question-2": "Why are we here again?", }, "/surveys", diff --git a/tests/test_assets/test_db_data.sql b/tests/test_assets/test_db_data.sql index 52744ec..7eb5b3b 100644 --- a/tests/test_assets/test_db_data.sql +++ b/tests/test_assets/test_db_data.sql @@ -28,6 +28,11 @@ INSERT INTO survey ( "00000000-e253-4c39-b32b-eeb4f8e8711d" , true , "Open Test Survey - 2DQ" +), +( + "00000000-1f7c-43e9-ab61-3c34fd59a333" + , true + , "Open Test Survey - Mixed Questions" ); INSERT INTO text_question ( @@ -53,6 +58,11 @@ INSERT INTO text_question ( "11111111-b37a-44a1-19d9-72ec921021e3" , "00000000-b37a-32b3-19d9-72ec921021e3" , "What story?" +), +( + "11111111-8713-4275-9f43-4d127671f0ff" + , "00000000-1f7c-43e9-ab61-3c34fd59a333" + , "What story would you tell your grandchild about working in the military?" ); INSERT INTO dimensional_question ( @@ -93,6 +103,22 @@ INSERT INTO dimensional_question ( , "Purpose" , "Audacity" , "Clarity of Direction" -); +), +( + "11111111-0fcc-484b-bab4-c33309cebd3c" + , "00000000-1f7c-43e9-ab61-3c34fd59a333" + , "How strongly does this story demonstrate the following values?" + , "Empathy to Colleagues" + , "Service to Others" + , "Individual Growth" +), +( + "11111111-b54a-45ee-86af-05f625f3d239" + , "00000000-1f7c-43e9-ab61-3c34fd59a333" + , "How strongly does this story demonstrate the following values?" + , "Accountability" + , "Efficiency" + , "Individual Growth" +);; COMMIT; diff --git a/tests/unit/data_service/sqlite3/test_driver.py b/tests/unit/data_service/sqlite3/test_driver.py index 37d553f..add74a9 100644 --- a/tests/unit/data_service/sqlite3/test_driver.py +++ b/tests/unit/data_service/sqlite3/test_driver.py @@ -23,7 +23,7 @@ class TestDriverSurveyMethods: def test_sqlite3_driver_can_get_list_open_surveys(self, populated_db_driver): surveys = populated_db_driver.get_open_surveys() - assert len(surveys) == 4 + assert len(surveys) == 5 for survey in surveys: assert isinstance(survey, Survey) diff --git a/tests/unit/test_routes.py b/tests/unit/test_routes.py index 57d8112..27a60a4 100644 --- a/tests/unit/test_routes.py +++ b/tests/unit/test_routes.py @@ -72,7 +72,11 @@ def test_get_request_returns_404( ( ( "/surveys/00000000-a087-4fb6-a123-24ff30263530", - ("get_survey_if_open", "get_text_questions_from_survey"), + ( + "get_survey_if_open", + "get_text_questions_from_survey", + "get_dimensional_questions_from_survey", + ), ), ), )