From dd72c09a24553c6b7d157e8248c6ad115cd2e82b Mon Sep 17 00:00:00 2001 From: dandds Date: Tue, 21 Aug 2018 10:06:18 -0400 Subject: [PATCH] test extended financial verification and task order validation --- tests/routes/test_financial_verification.py | 56 +++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/tests/routes/test_financial_verification.py b/tests/routes/test_financial_verification.py index fca2aa3b..778234a3 100644 --- a/tests/routes/test_financial_verification.py +++ b/tests/routes/test_financial_verification.py @@ -1,6 +1,10 @@ import re import pytest import urllib +from flask import url_for + +from atst.eda_client import MockEDAClient + from tests.mocks import MOCK_REQUEST, MOCK_USER from tests.factories import PENumberFactory @@ -9,7 +13,7 @@ class TestPENumberInForm: required_data = { "pe_id": "123", - "task_order_id": "1234567899C0001", + "task_order_id": MockEDAClient.MOCK_CONTRACT_NUMBER, "fname_co": "Contracting", "lname_co": "Officer", "email_co": "jane@mail.mil", @@ -18,6 +22,11 @@ class TestPENumberInForm: "lname_cor": "Representative", "email_cor": "jane@mail.mil", "office_cor": "WHS", + "uii_ids": "1234", + "treasury_code": "00123456", + "ba_code": "024A" + } + extended_data = { "funding_type": "RDTE", "funding_type_other": "other", "clin_0001": "50,000", @@ -33,9 +42,13 @@ class TestPENumberInForm: monkeypatch.setattr("atst.domain.requests.Requests.get", lambda i: MOCK_REQUEST) monkeypatch.setattr("atst.domain.auth.get_current_user", lambda *args: MOCK_USER) - def submit_data(self, client, data): + def submit_data(self, client, data, extended=False): + url_kwargs = {"request_id": MOCK_REQUEST.id} + if extended: + url_kwargs["extended"] = True + response = client.post( - "/requests/verify/{}".format(MOCK_REQUEST.id), + url_for("requests.financial_verification", **url_kwargs), headers={"Content-Type": "application/x-www-form-urlencoded"}, data=urllib.parse.urlencode(data), follow_redirects=False, @@ -83,3 +96,40 @@ class TestPENumberInForm: assert "There were some errors" in response.data.decode() assert response.status_code == 200 + + def test_submit_financial_form_with_invalid_task_order(self, monkeypatch, user_session, client): + monkeypatch.setattr("atst.domain.requests.Requests.get", lambda i: MOCK_REQUEST) + user_session() + + data = dict(self.required_data) + data['pe_id'] = MOCK_REQUEST.body['financial_verification']['pe_id'] + data['task_order_id'] = '1234' + + response = self.submit_data(client, data) + + assert "enter TO information manually" in response.data.decode() + + def test_submit_financial_form_with_valid_task_order(self, monkeypatch, user_session, client): + monkeypatch.setattr("atst.domain.requests.Requests.get", lambda i: MOCK_REQUEST) + user_session() + + data = dict(self.required_data) + data['pe_id'] = MOCK_REQUEST.body['financial_verification']['pe_id'] + data['task_order_id'] = MockEDAClient.MOCK_CONTRACT_NUMBER + + response = self.submit_data(client, data) + + assert "enter TO information manually" not in response.data.decode() + + def test_submit_extended_financial_form(self, monkeypatch, user_session, client): + monkeypatch.setattr("atst.domain.requests.Requests.get", lambda i: MOCK_REQUEST) + user_session() + + data = { **self.required_data, **self.extended_data } + data['pe_id'] = MOCK_REQUEST.body['financial_verification']['pe_id'] + data['task_order_id'] = "1234567" + + response = self.submit_data(client, data, extended=True) + + assert response.status_code == 302 + assert "/requests/financial_verification_submitted" in response.headers.get("Location")