update tests for Flask

This commit is contained in:
dandds
2018-08-02 13:49:39 -04:00
parent 5987748898
commit 45b47c41bf
32 changed files with 468 additions and 482 deletions

View File

@@ -0,0 +1,76 @@
import re
import pytest
import tornado
import urllib
from tests.mocks import MOCK_REQUEST, MOCK_USER
from tests.factories import PENumberFactory
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.forms.financial.FinancialForm.validate", lambda s: True)
monkeypatch.setattr("atst.domain.requests.Requests.get", lambda i: MOCK_REQUEST)
def submit_data(self, client, data):
response = client.post(
"/requests/verify/{}".format(MOCK_REQUEST.id),
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=urllib.parse.urlencode(data),
follow_redirects=False,
)
return response
def test_submit_request_form_with_invalid_pe_id(self, monkeypatch, client):
self._set_monkeypatches(monkeypatch)
response = self.submit_data(client, self.required_data)
assert "We couldn\'t find that PE number" in response.data.decode()
assert response.status_code == 200
def test_submit_request_form_with_unchanged_pe_id(self, monkeypatch, client):
self._set_monkeypatches(monkeypatch)
data = dict(self.required_data)
data['pe_id'] = MOCK_REQUEST.body['financial_verification']['pe_id']
response = self.submit_data(client, data)
assert response.status_code == 302
assert "/requests/financial_verification_submitted" in response.headers.get("Location")
def test_submit_request_form_with_new_valid_pe_id(self, session, monkeypatch, client):
self._set_monkeypatches(monkeypatch)
pe = PENumberFactory.create(number="8675309U", description="sample PE number")
session.add(pe)
session.commit()
data = dict(self.required_data)
data['pe_id'] = pe.number
response = self.submit_data(client, data)
assert response.status_code == 302
assert "/requests/financial_verification_submitted" in response.headers.get("Location")

View File

@@ -0,0 +1,35 @@
import re
import pytest
import urllib
from tests.mocks import MOCK_USER
from tests.factories import RequestFactory
ERROR_CLASS = "alert--error"
MOCK_REQUEST = RequestFactory.create(
creator=MOCK_USER["id"],
body={
"financial_verification": {
"pe_id": "0203752A",
},
}
)
def test_submit_invalid_request_form(monkeypatch, client):
response = client.post(
"/requests/new/1",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data="total_ram=5",
)
assert re.search(ERROR_CLASS, response.data.decode())
def test_submit_valid_request_form(monkeypatch, client):
monkeypatch.setattr("atst.forms.request.RequestForm.validate", lambda s: True)
response = client.post(
"/requests/new/1",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data="meaning=42",
)
assert "/requests/new/2" in response.headers.get("Location")

View File

@@ -0,0 +1,37 @@
import pytest
import tornado
from tests.mocks import MOCK_USER
from tests.factories import RequestFactory
def _mock_func(*args, **kwargs):
return RequestFactory.create()
def test_submit_reviewed_request(monkeypatch, client):
monkeypatch.setattr("atst.domain.requests.Requests.get", _mock_func)
monkeypatch.setattr("atst.domain.requests.Requests.submit", _mock_func)
monkeypatch.setattr("atst.models.request.Request.status", "pending")
# this just needs to send a known invalid form value
response = client.post(
"/requests/submit/1",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data="",
follow_redirects=False,
)
assert "/requests" in response.headers["Location"]
assert "modal" not in response.headers["Location"]
def test_submit_autoapproved_reviewed_request(monkeypatch, client):
monkeypatch.setattr("atst.domain.requests.Requests.get", _mock_func)
monkeypatch.setattr("atst.domain.requests.Requests.submit", _mock_func)
monkeypatch.setattr("atst.models.request.Request.status", "approved")
# this just needs to send a known invalid form value
response = client.post(
"/requests/submit/1",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data="",
follow_redirects=False,
)
assert "/requests?modal=True" in response.headers["Location"]