Skip to content

Commit

Permalink
Add basic tests for flask routes
Browse files Browse the repository at this point in the history
  • Loading branch information
akuny committed Feb 12, 2024
1 parent 1c6a551 commit e691a57
Showing 5 changed files with 47 additions and 2 deletions.
3 changes: 3 additions & 0 deletions nad_ch/application/use_cases.py
Original file line number Diff line number Diff line change
@@ -74,6 +74,9 @@ def get_data_submission(
) -> DataSubmissionViewModel:
submission = ctx.submissions.get_by_id(submission_id)

if submission is None:
return None

return get_view_model(submission)


5 changes: 4 additions & 1 deletion nad_ch/controllers/web/templates/reports/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "_layouts/base.html" %} {% block title %}Home Page{% endblock %}
{%block content %}
<h1>Reports</h1>
{% if submissions %}
<table class="usa-table usa-table--borderless">
<thead>
<tr>
@@ -24,4 +25,6 @@ <h1>Reports</h1>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% else %}
<p>You haven't uploaded any data submissions yet.</p>
{% endif %} {% endblock %}
7 changes: 6 additions & 1 deletion nad_ch/controllers/web/templates/reports/show.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{% extends "_layouts/base.html" %} {% block title %}Report{% endblock %} {%block
content %}
<h1>Report</h1>
{% endblock %}
{% if submission %}
<p>{{ submission.filename }}</p>
<p>{{ submission.date_created}}</p>
{% else %}
<p>No such submission exists.</p>
{% endif %} {% endblock %}
Empty file added tests/controllers/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tests/controllers/test_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from nad_ch.config import create_app_context
from nad_ch.controllers.web.flask import create_flask_application


@pytest.fixture
def app():
context = create_app_context()
app = create_flask_application(context)
yield app


@pytest.fixture
def client(app):
return app.test_client()


def test_home_route(client):
response = client.get("/")
assert response.status_code == 200
assert "Welcome" in response.data.decode("utf-8")


def test_reports_route(client):
response = client.get("/reports")
assert response.status_code == 200
assert "Reports" in response.data.decode("utf-8")


def test_view_report_route(client):
submission_id = "some_valid_id"
response = client.get(f"/reports/{submission_id}")
assert response.status_code == 200
assert "Report" in response.data.decode("utf-8")

0 comments on commit e691a57

Please sign in to comment.