From be080ed205cce7146fa40036bd5641be6c391975 Mon Sep 17 00:00:00 2001 From: Montana Date: Mon, 27 Aug 2018 14:22:44 -0400 Subject: [PATCH] Add new filter for rendering FileStorage name in case of invalid financial form submission --- atst/filters.py | 13 +++++++++++++ templates/requests/financial_verification.html | 2 +- tests/domain/test_task_orders.py | 1 + tests/routes/test_financial_verification.py | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/atst/filters.py b/atst/filters.py index 795f2222..c56cb739 100644 --- a/atst/filters.py +++ b/atst/filters.py @@ -1,4 +1,6 @@ import re +from flask import current_app as app +from werkzeug.datastructures import FileStorage def iconSvg(name): @@ -31,9 +33,20 @@ def getOptionLabel(value, options): return next(tup[1] for tup in options if tup[0] == value) +def enhancedToJson(value): + if ( + isinstance(value, dict) + and "task_order" in value + and isinstance(value["task_order"], FileStorage) + ): + value["task_order"] = value["task_order"].filename + return app.jinja_env.filters["tojson"](value) + + def register_filters(app): app.jinja_env.filters["iconSvg"] = iconSvg app.jinja_env.filters["dollars"] = dollars app.jinja_env.filters["usPhone"] = usPhone app.jinja_env.filters["readableInteger"] = readableInteger app.jinja_env.filters["getOptionLabel"] = getOptionLabel + app.jinja_env.filters["enhancedToJson"] = enhancedToJson diff --git a/templates/requests/financial_verification.html b/templates/requests/financial_verification.html index 0808eaa0..0f4f4903 100644 --- a/templates/requests/financial_verification.html +++ b/templates/requests/financial_verification.html @@ -6,7 +6,7 @@ {% block content %} - +
{% if extended %} diff --git a/tests/domain/test_task_orders.py b/tests/domain/test_task_orders.py index 2e86a2c0..cc83d284 100644 --- a/tests/domain/test_task_orders.py +++ b/tests/domain/test_task_orders.py @@ -37,6 +37,7 @@ def test_nonexistent_task_order_raises_with_client(monkeypatch): with pytest.raises(NotFoundError): TaskOrders.get("some other fake numer") + def test_create_attachment(extended_financial_verification_data): task_order_data = extended_financial_verification_data.copy() task_order_data["pdf"] = task_order_data.pop("task_order") diff --git a/tests/routes/test_financial_verification.py b/tests/routes/test_financial_verification.py index 631b6743..ef8314f3 100644 --- a/tests/routes/test_financial_verification.py +++ b/tests/routes/test_financial_verification.py @@ -130,3 +130,18 @@ class TestPENumberInForm: assert response.status_code == 302 assert "/projects/new" in response.headers.get("Location") + + def test_submit_invalid_extended_financial_form( + self, monkeypatch, user_session, client, extended_financial_verification_data + ): + request = RequestFactory.create() + monkeypatch.setattr("atst.domain.requests.Requests.get", lambda i: request) + monkeypatch.setattr("atst.forms.financial.validate_pe_id", lambda *args: True) + user_session() + data = {**self.required_data, **extended_financial_verification_data} + data["task_order_number"] = "1234567" + del (data["clin_0001"]) + + response = self.submit_data(client, data, extended=True) + + assert response.status_code == 200