Skip to content

Commit

Permalink
DimensionalQuestions now appear on /surveys/<uid> pages. Answering / …
Browse files Browse the repository at this point in the history
…proper displaying of question not implemented.
  • Loading branch information
epwr committed Feb 25, 2024
1 parent 3555df4 commit 1562f2b
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 16 deletions.
15 changes: 11 additions & 4 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
19 changes: 16 additions & 3 deletions app/templates/survey.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
{% block content %}
<h1>{{survey.name}}</h3>

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

<div>
{% for question in text_questions %}
<h4>{{question.question}}</h4>
{% endfor %}
<div>
{% for question in questions %}
<h2>{{question.question}}</h2>

<div>
{% for question in dimensional_questions %}
<h4>{{question.question}}</h4>
<ul>
<li>question.dimension_one</li>
<li>question.dimension_two</li>
<li>question.dimension_three</li>
</ul>
{% endfor %}
<div>

Answering Questions is not yet implemented.


{% endblock %}
30 changes: 25 additions & 5 deletions data/initial_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
21 changes: 20 additions & 1 deletion tests/integration/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
(
Expand All @@ -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",
Expand Down
28 changes: 27 additions & 1 deletion tests/test_assets/test_db_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 (
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion tests/unit/data_service/sqlite3/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
),
),
)
Expand Down

0 comments on commit 1562f2b

Please sign in to comment.