diff --git a/atst/handlers/request_financial_verification.py b/atst/handlers/request_financial_verification.py
index 51445d66..a3bf8fc8 100644
--- a/atst/handlers/request_financial_verification.py
+++ b/atst/handlers/request_financial_verification.py
@@ -1,11 +1,6 @@
import tornado
-from collections import defaultdict
from atst.handler import BaseHandler
-from atst.forms.request import RequestForm
-from atst.forms.org import OrgForm
-from atst.forms.poc import POCForm
-from atst.forms.review import ReviewForm
from atst.forms.financial import FinancialForm
@@ -25,12 +20,54 @@ class RequestFinancialVerification(BaseHandler):
@tornado.web.authenticated
@tornado.gen.coroutine
def get(self, request_id=None):
- # self.check_xsrf_cookie()
- # post_data = self.request.arguments
- current_user = self.get_current_user()
existing_request = yield self.get_existing_request(request_id)
+ form = FinancialForm(data=existing_request['body'].get('financial_verification'))
self.render(
"requests/financial_verification.html.to",
page=self.page,
+ f=form,
+ request_id=request_id,
)
+ @tornado.gen.coroutine
+ def update_request(self, request_id, form_data):
+ request_data = {
+ "creator_id": self.current_user["id"],
+ "request": {"financial_verification": form_data},
+ }
+ response = yield self.requests_client.patch(
+ "/requests/{}".format(request_id), json=request_data
+ )
+ return response
+
+ @tornado.web.authenticated
+ @tornado.gen.coroutine
+ def post(self, request_id=None):
+ self.check_xsrf_cookie()
+ post_data = self.request.arguments
+ existing_request = yield self.get_existing_request(request_id)
+ form = FinancialForm(post_data)
+
+ rerender_args = dict(request_id=request_id, f=form)
+
+ if form.validate():
+ response = yield self.update_request(request_id, form.data)
+ if response.ok:
+ valid = yield form.perform_extra_validation(
+ existing_request.get('body', {}).get('financial_verification'),
+ self.fundz_client
+ )
+ if valid:
+ self.redirect('/requests')
+ else:
+ self.render(
+ "requests/financial_verification.html.to",
+ **rerender_args
+ )
+ else:
+ self.set_status(response.code)
+ else:
+ self.render(
+ "requests/financial_verification.html.to",
+ **rerender_args
+ )
diff --git a/atst/handlers/request_new.py b/atst/handlers/request_new.py
index 096572d3..de3c2713 100644
--- a/atst/handlers/request_new.py
+++ b/atst/handlers/request_new.py
@@ -6,7 +6,6 @@ from atst.forms.request import RequestForm
from atst.forms.org import OrgForm
from atst.forms.poc import POCForm
from atst.forms.review import ReviewForm
-from atst.forms.financial import FinancialForm
class RequestNew(BaseHandler):
@@ -221,12 +220,6 @@ class JEDIRequestFlow(object):
"form": ReviewForm,
"show":True,
},
- {
- "title": "Financial Verification",
- "section": "financial_verification",
- "form": FinancialForm,
- "show": self.request and self.request["status"] == "approved",
- },
]
@tornado.gen.coroutine
diff --git a/templates/requests/financial_verification.html.to b/templates/requests/financial_verification.html.to
index 06abd2ea..dc1c4d71 100644
--- a/templates/requests/financial_verification.html.to
+++ b/templates/requests/financial_verification.html.to
@@ -9,13 +9,211 @@
-
Order #36552512
- Financial Verification
+ Order #{{ request_id }}
+ Financial Verification
+ {% block form_action %}
+
+
{% end %}
-
diff --git a/tests/handlers/test_financial_verification.py b/tests/handlers/test_financial_verification.py
new file mode 100644
index 00000000..4ca2ce2e
--- /dev/null
+++ b/tests/handlers/test_financial_verification.py
@@ -0,0 +1,84 @@
+import re
+import pytest
+import tornado
+import urllib
+from tests.mocks import MOCK_REQUEST, MOCK_USER, MOCK_VALID_PE_ID
+
+
+class TestPENumberInForm:
+
+ required_data = {
+ "pe_id": "123",
+ "task_order_id": "1234567899C0001",
+ "fname_co": "Contracting",
+ "lname_co": "Officer",
+ "email_co": "jane@mail.mil",
+ "office_co": "WHS",
+ "fname_cor": "Officer",
+ "lname_cor": "Representative",
+ "email_cor": "jane@mail.mil",
+ "office_cor": "WHS",
+ "funding_type": "RDTE",
+ "funding_type_other": "other",
+ "clin_0001": "50,000",
+ "clin_0003": "13,000",
+ "clin_1001": "30,000",
+ "clin_1003": "7,000",
+ "clin_2001": "30,000",
+ "clin_2003": "7,000",
+ }
+
+ def _set_monkeypatches(self, monkeypatch):
+ monkeypatch.setattr(
+ "atst.handlers.request_financial_verification.RequestFinancialVerification.get_current_user", lambda s: MOCK_USER
+ )
+ monkeypatch.setattr(
+ "atst.handlers.request_financial_verification.RequestFinancialVerification.check_xsrf_cookie", lambda s: True
+ )
+ monkeypatch.setattr("atst.forms.request.RequestForm.validate", lambda s: True)
+
+ @tornado.gen.coroutine
+ def submit_data(self, http_client, base_url, data):
+ response = yield http_client.fetch(
+ base_url + "/requests/verify/{}".format(MOCK_REQUEST["id"]),
+ method="POST",
+ headers={"Content-Type": "application/x-www-form-urlencoded"},
+ body=urllib.parse.urlencode(data),
+ follow_redirects=False,
+ raise_error=False,
+ )
+ return response
+
+ @pytest.mark.gen_test
+ def test_submit_request_form_with_invalid_pe_id(self, monkeypatch, http_client, base_url):
+ self._set_monkeypatches(monkeypatch)
+
+ response = yield self.submit_data(http_client, base_url, self.required_data)
+
+ assert "We couldn\'t find that PE number" in response.body.decode()
+ assert response.code == 200
+ assert "/requests/verify" in response.effective_url
+
+ @pytest.mark.gen_test
+ def test_submit_request_form_with_unchanged_pe_id(self, monkeypatch, http_client, base_url):
+ self._set_monkeypatches(monkeypatch)
+
+ data = dict(self.required_data)
+ data['pe_id'] = MOCK_REQUEST['body']['financial_verification']['pe_id']
+
+ response = yield self.submit_data(http_client, base_url, data)
+
+ assert response.code == 302
+ assert response.headers.get("Location") == "/requests"
+
+ @pytest.mark.gen_test
+ def test_submit_request_form_with_new_valid_pe_id(self, monkeypatch, http_client, base_url):
+ self._set_monkeypatches(monkeypatch)
+
+ data = dict(self.required_data)
+ data['pe_id'] = MOCK_VALID_PE_ID
+
+ response = yield self.submit_data(http_client, base_url, data)
+
+ assert response.code == 302
+ assert response.headers.get("Location") == "/requests"
diff --git a/tests/handlers/test_request_new.py b/tests/handlers/test_request_new.py
index 6a8a37f6..fc09cb3e 100644
--- a/tests/handlers/test_request_new.py
+++ b/tests/handlers/test_request_new.py
@@ -2,16 +2,9 @@ import re
import pytest
import tornado
import urllib
-from tests.mocks import MOCK_REQUEST, MOCK_VALID_PE_ID
+from tests.mocks import MOCK_USER
ERROR_CLASS = "usa-input-error-message"
-MOCK_USER = {
- "id": "9cb348f0-8102-4962-88c4-dac8180c904c",
- "email": "fake.user@mail.com",
- "first_name": "Fake",
- "last_name": "User",
-}
-
@pytest.mark.gen_test
def test_submit_invalid_request_form(monkeypatch, http_client, base_url):
@@ -50,82 +43,3 @@ def test_submit_valid_request_form(monkeypatch, http_client, base_url):
body="meaning=42",
)
assert "/requests/new/2" in response.effective_url
-
-
-class TestPENumberInForm:
-
- required_data = {
- "pe_id": "123",
- "task_order_id": "1234567899C0001",
- "fname_co": "Contracting",
- "lname_co": "Officer",
- "email_co": "jane@mail.mil",
- "office_co": "WHS",
- "fname_cor": "Officer",
- "lname_cor": "Representative",
- "email_cor": "jane@mail.mil",
- "office_cor": "WHS",
- "funding_type": "RDTE",
- "funding_type_other": "other",
- "clin_0001": "50,000",
- "clin_0003": "13,000",
- "clin_1001": "30,000",
- "clin_1003": "7,000",
- "clin_2001": "30,000",
- "clin_2003": "7,000",
- }
-
- def _set_monkeypatches(self, monkeypatch):
- monkeypatch.setattr(
- "atst.handlers.request_new.RequestNew.get_current_user", lambda s: MOCK_USER
- )
- monkeypatch.setattr(
- "atst.handlers.request_new.RequestNew.check_xsrf_cookie", lambda s: True
- )
- monkeypatch.setattr("atst.forms.request.RequestForm.validate", lambda s: True)
-
- @tornado.gen.coroutine
- def submit_data(self, http_client, base_url, data):
- response = yield http_client.fetch(
- base_url + "/requests/new/5/{}".format(MOCK_REQUEST["id"]),
- method="POST",
- headers={"Content-Type": "application/x-www-form-urlencoded"},
- body=urllib.parse.urlencode(data),
- follow_redirects=False,
- raise_error=False,
- )
- return response
-
- @pytest.mark.gen_test
- def test_submit_request_form_with_invalid_pe_id(self, monkeypatch, http_client, base_url):
- self._set_monkeypatches(monkeypatch)
-
- response = yield self.submit_data(http_client, base_url, self.required_data)
-
- assert "We couldn\'t find that PE number" in response.body.decode()
- assert response.code == 200
- assert "/requests/new/5" in response.effective_url
-
- @pytest.mark.gen_test
- def test_submit_request_form_with_unchanged_pe_id(self, monkeypatch, http_client, base_url):
- self._set_monkeypatches(monkeypatch)
-
- data = dict(self.required_data)
- data['pe_id'] = MOCK_REQUEST['body']['financial_verification']['pe_id']
-
- response = yield self.submit_data(http_client, base_url, data)
-
- assert response.code == 302
- assert response.headers.get("Location") == "/requests"
-
- @pytest.mark.gen_test
- def test_submit_request_form_with_new_valid_pe_id(self, monkeypatch, http_client, base_url):
- self._set_monkeypatches(monkeypatch)
-
- data = dict(self.required_data)
- data['pe_id'] = MOCK_VALID_PE_ID
-
- response = yield self.submit_data(http_client, base_url, data)
-
- assert response.code == 302
- assert response.headers.get("Location") == "/requests"
diff --git a/tests/mocks.py b/tests/mocks.py
index 6cd3540c..a7290a03 100644
--- a/tests/mocks.py
+++ b/tests/mocks.py
@@ -4,6 +4,14 @@ from tornado.httpclient import HTTPRequest, HTTPResponse
from atst.api_client import ApiClient
+MOCK_USER = {
+ "id": "9cb348f0-8102-4962-88c4-dac8180c904c",
+ "email": "fake.user@mail.com",
+ "first_name": "Fake",
+ "last_name": "User",
+}
+
+
class MockApiClient(ApiClient):
def __init__(self, service):