Format project

This commit is contained in:
richard-dds
2018-08-23 16:25:36 -04:00
parent e9fa4d9ecb
commit daa8634cb4
48 changed files with 415 additions and 282 deletions

View File

@@ -8,12 +8,7 @@ from atst.app import make_app, make_config
from atst.database import db as _db
import tests.factories as factories
dictConfig({
'version': 1,
'handlers': {'wsgi': {
'class': 'logging.NullHandler',
}}
})
dictConfig({"version": 1, "handlers": {"wsgi": {"class": "logging.NullHandler"}}})
@pytest.fixture(scope="session")

View File

@@ -11,7 +11,7 @@ from tests.factories import UserFactory
CERT = open("tests/fixtures/{}.crt".format(FIXTURE_EMAIL_ADDRESS)).read()
class MockCRLCache():
class MockCRLCache:
def __init__(self, valid=True):
self.valid = valid
@@ -23,16 +23,12 @@ class MockCRLCache():
def test_can_authenticate():
auth_context = AuthenticationContext(
MockCRLCache(), "SUCCESS", DOD_SDN, CERT
)
auth_context = AuthenticationContext(MockCRLCache(), "SUCCESS", DOD_SDN, CERT)
assert auth_context.authenticate()
def test_unsuccessful_status():
auth_context = AuthenticationContext(
MockCRLCache(), "FAILURE", DOD_SDN, CERT
)
auth_context = AuthenticationContext(MockCRLCache(), "FAILURE", DOD_SDN, CERT)
with pytest.raises(UnauthenticatedError) as excinfo:
assert auth_context.authenticate()
@@ -41,9 +37,7 @@ def test_unsuccessful_status():
def test_crl_check_fails():
auth_context = AuthenticationContext(
MockCRLCache(False), "SUCCESS", DOD_SDN, CERT
)
auth_context = AuthenticationContext(MockCRLCache(False), "SUCCESS", DOD_SDN, CERT)
with pytest.raises(UnauthenticatedError) as excinfo:
assert auth_context.authenticate()
@@ -52,9 +46,7 @@ def test_crl_check_fails():
def test_bad_sdn():
auth_context = AuthenticationContext(
MockCRLCache(), "SUCCESS", "abc123", CERT
)
auth_context = AuthenticationContext(MockCRLCache(), "SUCCESS", "abc123", CERT)
with pytest.raises(UnauthenticatedError) as excinfo:
auth_context.get_user()
@@ -64,9 +56,7 @@ def test_bad_sdn():
def test_user_exists():
user = UserFactory.create(**DOD_SDN_INFO)
auth_context = AuthenticationContext(
MockCRLCache(), "SUCCESS", DOD_SDN, CERT
)
auth_context = AuthenticationContext(MockCRLCache(), "SUCCESS", DOD_SDN, CERT)
auth_user = auth_context.get_user()
assert auth_user == user
@@ -77,9 +67,7 @@ def test_creates_user():
with pytest.raises(NotFoundError):
Users.get_by_dod_id(DOD_SDN_INFO["dod_id"])
auth_context = AuthenticationContext(
MockCRLCache(), "SUCCESS", DOD_SDN, CERT
)
auth_context = AuthenticationContext(MockCRLCache(), "SUCCESS", DOD_SDN, CERT)
user = auth_context.get_user()
assert user.dod_id == DOD_SDN_INFO["dod_id"]
assert user.email == FIXTURE_EMAIL_ADDRESS
@@ -87,9 +75,7 @@ def test_creates_user():
def test_user_cert_has_no_email():
cert = open("ssl/client-certs/atat.mil.crt").read()
auth_context = AuthenticationContext(
MockCRLCache(), "SUCCESS", DOD_SDN, cert
)
auth_context = AuthenticationContext(MockCRLCache(), "SUCCESS", DOD_SDN, cert)
user = auth_context.get_user()
assert user.email == None

View File

@@ -11,8 +11,7 @@ import atst.domain.authnid.crl.util as util
from tests.mocks import FIXTURE_EMAIL_ADDRESS
class MockX509Store():
class MockX509Store:
def __init__(self):
self.crls = []
self.certs = []
@@ -98,8 +97,7 @@ def test_parse_disa_pki_list():
assert len(crl_list) == len(href_matches)
class MockStreamingResponse():
class MockStreamingResponse:
def __init__(self, content_chunks, code=200):
self.content_chunks = content_chunks
self.status_code = code

View File

@@ -18,4 +18,3 @@ def test_invalid_date():
date_str = "This is not a valid data"
with pytest.raises(ValueError):
parse_date(date_str)

View File

@@ -7,7 +7,9 @@ from tests.factories import PENumberFactory
def test_can_get_pe_number():
new_pen = PENumberFactory.create(number="0701367F", description="Combat Support - Offensive")
new_pen = PENumberFactory.create(
number="0701367F", description="Combat Support - Offensive"
)
pen = PENumbers.get(new_pen.number)
assert pen.number == new_pen.number
@@ -17,8 +19,9 @@ def test_nonexistent_pe_number_raises():
with pytest.raises(NotFoundError):
PENumbers.get("some fake number")
def test_create_many():
pen_list = [['123456', 'Land Speeder'], ['7891011', 'Lightsaber']]
pen_list = [["123456", "Land Speeder"], ["7891011", "Lightsaber"]]
PENumbers.create_many(pen_list)
assert PENumbers.get(pen_list[0][0])

View File

@@ -7,7 +7,12 @@ from atst.models.request import Request
from atst.models.request_status_event import RequestStatus
from atst.models.task_order import Source as TaskOrderSource
from tests.factories import RequestFactory, UserFactory, RequestStatusEventFactory, TaskOrderFactory
from tests.factories import (
RequestFactory,
UserFactory,
RequestStatusEventFactory,
TaskOrderFactory,
)
@pytest.fixture(scope="function")
@@ -55,10 +60,12 @@ def test_dont_auto_approve_if_no_dollar_value_specified(new_request):
def test_should_allow_submission(new_request):
assert Requests.should_allow_submission(new_request)
RequestStatusEventFactory.create(request=new_request, new_status=RequestStatus.CHANGES_REQUESTED)
RequestStatusEventFactory.create(
request=new_request, new_status=RequestStatus.CHANGES_REQUESTED
)
assert Requests.should_allow_submission(new_request)
del new_request.body['details_of_use']
del new_request.body["details_of_use"]
assert not Requests.should_allow_submission(new_request)
@@ -76,12 +83,17 @@ def test_status_count(session):
request1 = RequestFactory.create()
request2 = RequestFactory.create()
RequestStatusEventFactory.create(sequence=2, request_id=request2.id, new_status=RequestStatus.PENDING_FINANCIAL_VERIFICATION)
RequestStatusEventFactory.create(
sequence=2,
request_id=request2.id,
new_status=RequestStatus.PENDING_FINANCIAL_VERIFICATION,
)
assert Requests.status_count(RequestStatus.PENDING_FINANCIAL_VERIFICATION) == 1
assert Requests.status_count(RequestStatus.STARTED) == 1
assert Requests.in_progress_count() == 2
def test_status_count_scoped_to_creator(session):
# make sure table is empty
session.query(Request).delete()
@@ -123,7 +135,7 @@ task_order_financial_data = {
def test_update_financial_verification_without_task_order():
request = RequestFactory.create()
financial_data = { **request_financial_data, **task_order_financial_data }
financial_data = {**request_financial_data, **task_order_financial_data}
Requests.update_financial_verification(request.id, financial_data)
assert request.task_order
assert request.task_order.clin_0001 == task_order_financial_data["clin_0001"]
@@ -132,7 +144,7 @@ def test_update_financial_verification_without_task_order():
def test_update_financial_verification_with_task_order():
task_order = TaskOrderFactory.create(source=TaskOrderSource.EDA)
financial_data = { **request_financial_data, "task_order_number": task_order.number }
financial_data = {**request_financial_data, "task_order_number": task_order.number}
request = RequestFactory.create()
Requests.update_financial_verification(request.id, financial_data)
assert request.task_order == task_order
@@ -142,4 +154,3 @@ def test_update_financial_verification_with_invalid_task_order():
request = RequestFactory.create()
Requests.update_financial_verification(request.id, request_financial_data)
assert not request.task_order

View File

@@ -16,7 +16,9 @@ def test_can_get_task_order():
def test_can_get_task_order_from_eda(monkeypatch):
monkeypatch.setattr("atst.domain.task_orders.TaskOrders._client", lambda: MockEDAClient())
monkeypatch.setattr(
"atst.domain.task_orders.TaskOrders._client", lambda: MockEDAClient()
)
to = TaskOrders.get(MockEDAClient.MOCK_CONTRACT_NUMBER)
assert to.number == MockEDAClient.MOCK_CONTRACT_NUMBER
@@ -29,6 +31,8 @@ def test_nonexistent_task_order_raises_without_client():
def test_nonexistent_task_order_raises_with_client(monkeypatch):
monkeypatch.setattr("atst.domain.task_orders.TaskOrders._client", lambda: MockEDAClient())
monkeypatch.setattr(
"atst.domain.task_orders.TaskOrders._client", lambda: MockEDAClient()
)
with pytest.raises(NotFoundError):
TaskOrders.get("some other fake numer")

View File

@@ -30,13 +30,16 @@ def test_date_insane_format():
form.date._value()
@pytest.mark.parametrize("input_,expected", [
("", []),
("hello", ["hello"]),
("hello\n", ["hello"]),
("hello\nworld", ["hello", "world"]),
("hello\nworld\n", ["hello", "world"])
])
@pytest.mark.parametrize(
"input_,expected",
[
("", []),
("hello", ["hello"]),
("hello\n", ["hello"]),
("hello\nworld", ["hello", "world"]),
("hello\nworld\n", ["hello", "world"]),
],
)
def test_newline_list_process(input_, expected):
form_data = ImmutableMultiDict({"newline_list": input_})
form = NewlineListForm(form_data)
@@ -45,11 +48,10 @@ def test_newline_list_process(input_, expected):
assert form.data == {"newline_list": expected}
@pytest.mark.parametrize("input_,expected", [
([], ""),
(["hello"], "hello"),
(["hello", "world"], "hello\nworld")
])
@pytest.mark.parametrize(
"input_,expected",
[([], ""), (["hello"], "hello"), (["hello", "world"], "hello\nworld")],
)
def test_newline_list_value(input_, expected):
form_data = {"newline_list": input_}
form = NewlineListForm(data=form_data)

View File

@@ -4,45 +4,47 @@ from atst.forms.financial import suggest_pe_id, FinancialForm, ExtendedFinancial
from atst.eda_client import MockEDAClient
@pytest.mark.parametrize("input_,expected", [
('0603502N', None),
('0603502NZ', None),
('603502N', '0603502N'),
('063502N', '0603502N'),
('63502N', '0603502N'),
])
@pytest.mark.parametrize(
"input_,expected",
[
("0603502N", None),
("0603502NZ", None),
("603502N", "0603502N"),
("063502N", "0603502N"),
("63502N", "0603502N"),
],
)
def test_suggest_pe_id(input_, expected):
assert suggest_pe_id(input_) == expected
def test_funding_type_other_not_required_if_funding_type_is_not_other():
form_data = {
"funding_type": "PROC"
}
form_data = {"funding_type": "PROC"}
form = ExtendedFinancialForm(data=form_data)
form.validate()
assert "funding_type_other" not in form.errors
def test_funding_type_other_required_if_funding_type_is_other():
form_data = {
"funding_type": "OTHER"
}
form_data = {"funding_type": "OTHER"}
form = ExtendedFinancialForm(data=form_data)
form.validate()
assert "funding_type_other" in form.errors
@pytest.mark.parametrize("input_,expected", [
("1234", True),
("123456", True),
("0001234", True),
("000123456", True),
("12345", False),
("00012345", False),
("0001234567", False),
("000000", False),
])
@pytest.mark.parametrize(
"input_,expected",
[
("1234", True),
("123456", True),
("0001234", True),
("000123456", True),
("12345", False),
("00012345", False),
("0001234567", False),
("000000", False),
],
)
def test_treasury_code_validation(input_, expected):
form_data = {"treasury_code": input_}
form = FinancialForm(data=form_data)
@@ -52,15 +54,18 @@ def test_treasury_code_validation(input_, expected):
assert is_valid == expected
@pytest.mark.parametrize("input_,expected", [
("12", True),
("00012", True),
("12A", True),
("000123", True),
("00012A", True),
("0001", False),
("00012AB", False),
])
@pytest.mark.parametrize(
"input_,expected",
[
("12", True),
("00012", True),
("12A", True),
("000123", True),
("00012A", True),
("0001", False),
("00012AB", False),
],
)
def test_ba_code_validation(input_, expected):
form_data = {"ba_code": input_}
form = FinancialForm(data=form_data)
@@ -69,16 +74,21 @@ def test_ba_code_validation(input_, expected):
assert is_valid == expected
def test_task_order_number_validation(monkeypatch):
monkeypatch.setattr("atst.domain.task_orders.TaskOrders._client", lambda: MockEDAClient())
monkeypatch.setattr(
"atst.domain.task_orders.TaskOrders._client", lambda: MockEDAClient()
)
monkeypatch.setattr("atst.forms.financial.validate_pe_id", lambda *args: True)
form_invalid = FinancialForm(data={"task_order_number": "1234"})
form_invalid.perform_extra_validation({})
assert "task_order_number" in form_invalid.errors
form_valid = FinancialForm(data={"task_order_number": MockEDAClient.MOCK_CONTRACT_NUMBER}, eda_client=MockEDAClient())
form_valid = FinancialForm(
data={"task_order_number": MockEDAClient.MOCK_CONTRACT_NUMBER},
eda_client=MockEDAClient(),
)
form_valid.perform_extra_validation({})
assert "task_order_number" not in form_valid.errors

View File

@@ -5,7 +5,6 @@ from atst.forms.validators import Alphabet, IsNumber, PhoneNumber
class TestIsNumber:
@pytest.mark.parametrize("valid", ["0", "12", "-12"])
def test_IsNumber_accepts_integers(self, valid, dummy_form, dummy_field):
validator = IsNumber()
@@ -21,24 +20,18 @@ class TestIsNumber:
class TestPhoneNumber:
@pytest.mark.parametrize("valid", [
"12345",
"1234567890",
"(123) 456-7890",
])
@pytest.mark.parametrize("valid", ["12345", "1234567890", "(123) 456-7890"])
def test_PhoneNumber_accepts_valid_numbers(self, valid, dummy_form, dummy_field):
validator = PhoneNumber()
dummy_field.data = valid
validator(dummy_form, dummy_field)
@pytest.mark.parametrize("invalid", [
"1234",
"123456",
"1234567abc",
"(123) 456-789012",
])
def test_PhoneNumber_rejects_invalid_numbers(self, invalid, dummy_form, dummy_field):
@pytest.mark.parametrize(
"invalid", ["1234", "123456", "1234567abc", "(123) 456-789012"]
)
def test_PhoneNumber_rejects_invalid_numbers(
self, invalid, dummy_form, dummy_field
):
validator = PhoneNumber()
dummy_field.data = invalid
with pytest.raises(ValidationError):
@@ -46,7 +39,6 @@ class TestPhoneNumber:
class TestAlphabet:
@pytest.mark.parametrize("valid", ["a", "abcde"])
def test_Alphabet_accepts_letters(self, valid, dummy_form, dummy_field):
validator = Alphabet()

View File

@@ -69,6 +69,7 @@ def test_request_status_pending_deleted_displayname():
assert request.status_displayname == "Canceled"
def test_annual_spend():
request = RequestFactory.create()
monthly = request.body.get("details_of_use").get("estimated_monthly_spend")

View File

@@ -22,7 +22,7 @@ class TestPENumberInForm:
"office_cor": "WHS",
"uii_ids": "1234",
"treasury_code": "00123456",
"ba_code": "024A"
"ba_code": "024A",
}
extended_data = {
"funding_type": "RDTE",
@@ -36,8 +36,12 @@ class TestPENumberInForm:
}
def _set_monkeypatches(self, monkeypatch):
monkeypatch.setattr("atst.forms.financial.FinancialForm.validate", lambda s: True)
monkeypatch.setattr("atst.domain.auth.get_current_user", lambda *args: MOCK_USER)
monkeypatch.setattr(
"atst.forms.financial.FinancialForm.validate", lambda s: True
)
monkeypatch.setattr(
"atst.domain.auth.get_current_user", lambda *args: MOCK_USER
)
def submit_data(self, client, data, extended=False):
request = RequestFactory.create(body=MOCK_REQUEST.body)
@@ -64,7 +68,7 @@ class TestPENumberInForm:
self._set_monkeypatches(monkeypatch)
data = dict(self.required_data)
data['pe_id'] = MOCK_REQUEST.body['financial_verification']['pe_id']
data["pe_id"] = MOCK_REQUEST.body["financial_verification"]["pe_id"]
response = self.submit_data(client, data)
@@ -76,7 +80,7 @@ class TestPENumberInForm:
pe = PENumberFactory.create(number="8675309U", description="sample PE number")
data = dict(self.required_data)
data['pe_id'] = pe.number
data["pe_id"] = pe.number
response = self.submit_data(client, data)
@@ -87,32 +91,36 @@ class TestPENumberInForm:
self._set_monkeypatches(monkeypatch)
data = dict(self.required_data)
data['pe_id'] = ''
data["pe_id"] = ""
response = self.submit_data(client, data)
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):
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_number'] = '1234'
data["pe_id"] = MOCK_REQUEST.body["financial_verification"]["pe_id"]
data["task_order_number"] = "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):
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_number'] = MockEDAClient.MOCK_CONTRACT_NUMBER
data["pe_id"] = MOCK_REQUEST.body["financial_verification"]["pe_id"]
data["task_order_number"] = MockEDAClient.MOCK_CONTRACT_NUMBER
response = self.submit_data(client, data)
@@ -122,9 +130,9 @@ class TestPENumberInForm:
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_number'] = "1234567"
data = {**self.required_data, **self.extended_data}
data["pe_id"] = MOCK_REQUEST.body["financial_verification"]["pe_id"]
data["task_order_number"] = "1234567"
response = self.submit_data(client, data, extended=True)

View File

@@ -8,6 +8,7 @@ from tests.assert_util import dict_contains
ERROR_CLASS = "alert--error"
def test_submit_invalid_request_form(monkeypatch, client, user_session):
user_session()
response = client.post(
@@ -35,7 +36,9 @@ def test_owner_can_view_request(client, user_session):
user_session(user)
request = RequestFactory.create(creator=user)
response = client.get("/requests/new/1/{}".format(request.id), follow_redirects=True)
response = client.get(
"/requests/new/1/{}".format(request.id), follow_redirects=True
)
assert response.status_code == 200
@@ -45,7 +48,9 @@ def test_non_owner_cannot_view_request(client, user_session):
user_session(user)
request = RequestFactory.create()
response = client.get("/requests/new/1/{}".format(request.id), follow_redirects=True)
response = client.get(
"/requests/new/1/{}".format(request.id), follow_redirects=True
)
assert response.status_code == 404
@@ -56,7 +61,9 @@ def test_ccpo_can_view_request(client, user_session):
user_session(user)
request = RequestFactory.create()
response = client.get("/requests/new/1/{}".format(request.id), follow_redirects=True)
response = client.get(
"/requests/new/1/{}".format(request.id), follow_redirects=True
)
assert response.status_code == 200
@@ -80,7 +87,9 @@ def test_creator_info_is_autopopulated(monkeypatch, client, user_session):
assert "initial-value='{}'".format(user.email) in body
def test_creator_info_is_autopopulated_for_new_request(monkeypatch, client, user_session):
def test_creator_info_is_autopopulated_for_new_request(
monkeypatch, client, user_session
):
user = UserFactory.create()
user_session(user)
@@ -103,6 +112,7 @@ def test_non_creator_info_is_not_autopopulated(monkeypatch, client, user_session
assert not user.last_name in body
assert not user.email in body
def test_am_poc_causes_poc_to_be_autopopulated(client, user_session):
creator = UserFactory.create()
user_session(creator)
@@ -124,7 +134,7 @@ def test_not_am_poc_requires_poc_info_to_be_completed(client, user_session):
"/requests/new/3/{}".format(request.id),
headers={"Content-Type": "application/x-www-form-urlencoded"},
data="am_poc=no",
follow_redirects=True
follow_redirects=True,
)
assert ERROR_CLASS in response.data.decode()
@@ -156,7 +166,7 @@ def test_poc_details_can_be_autopopulated_on_new_request(client, user_session):
headers={"Content-Type": "application/x-www-form-urlencoded"},
data="am_poc=yes",
)
request_id = response.headers["Location"].split('/')[-1]
request_id = response.headers["Location"].split("/")[-1]
request = Requests.get(request_id)
assert request.body["primary_poc"]["dodid_poc"] == creator.dod_id
@@ -165,27 +175,31 @@ def test_poc_details_can_be_autopopulated_on_new_request(client, user_session):
def test_poc_autofill_checks_information_about_you_form_first(client, user_session):
creator = UserFactory.create()
user_session(creator)
request = RequestFactory.create(creator=creator, body={
"information_about_you": {
"fname_request": "Alice",
"lname_request": "Adams",
"email_request": "alice.adams@mail.mil"
}
})
poc_input = {
"am_poc": "yes",
}
request = RequestFactory.create(
creator=creator,
body={
"information_about_you": {
"fname_request": "Alice",
"lname_request": "Adams",
"email_request": "alice.adams@mail.mil",
}
},
)
poc_input = {"am_poc": "yes"}
client.post(
"/requests/new/3/{}".format(request.id),
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=urlencode(poc_input),
)
request = Requests.get(request.id)
assert dict_contains(request.body["primary_poc"], {
"fname_poc": "Alice",
"lname_poc": "Adams",
"email_poc": "alice.adams@mail.mil"
})
assert dict_contains(
request.body["primary_poc"],
{
"fname_poc": "Alice",
"lname_poc": "Adams",
"email_poc": "alice.adams@mail.mil",
},
)
def test_can_review_data(user_session, client):

View File

@@ -28,11 +28,16 @@ def test_submit_autoapproved_reviewed_request(monkeypatch, client, user_session)
user_session()
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", RequestStatus.PENDING_FINANCIAL_VERIFICATION)
monkeypatch.setattr(
"atst.models.request.Request.status",
RequestStatus.PENDING_FINANCIAL_VERIFICATION,
)
response = client.post(
"/requests/submit/1",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data="",
follow_redirects=False,
)
assert "/requests?modal=pendingFinancialVerification" in response.headers["Location"]
assert (
"/requests?modal=pendingFinancialVerification" in response.headers["Location"]
)

View File

@@ -15,8 +15,13 @@ def _fetch_user_info(c, t):
def test_successful_login_redirect_non_ccpo(client, monkeypatch):
monkeypatch.setattr("atst.domain.authnid.AuthenticationContext.authenticate", lambda *args: True)
monkeypatch.setattr("atst.domain.authnid.AuthenticationContext.get_user", lambda *args: UserFactory.create())
monkeypatch.setattr(
"atst.domain.authnid.AuthenticationContext.authenticate", lambda *args: True
)
monkeypatch.setattr(
"atst.domain.authnid.AuthenticationContext.get_user",
lambda *args: UserFactory.create(),
)
resp = client.get(
"/login-redirect",
@@ -31,10 +36,16 @@ def test_successful_login_redirect_non_ccpo(client, monkeypatch):
assert "requests" in resp.headers["Location"]
assert session["user_id"]
def test_successful_login_redirect_ccpo(client, monkeypatch):
monkeypatch.setattr("atst.domain.authnid.AuthenticationContext.authenticate", lambda *args: True)
monkeypatch.setattr(
"atst.domain.authnid.AuthenticationContext.authenticate", lambda *args: True
)
role = Roles.get("ccpo")
monkeypatch.setattr("atst.domain.authnid.AuthenticationContext.get_user", lambda *args: UserFactory.create(atat_role=role))
monkeypatch.setattr(
"atst.domain.authnid.AuthenticationContext.get_user",
lambda *args: UserFactory.create(atat_role=role),
)
resp = client.get(
"/login-redirect",
@@ -114,7 +125,9 @@ def test_crl_validation_on_login(client):
def test_creates_new_user_on_login(monkeypatch, client):
monkeypatch.setattr("atst.domain.authnid.AuthenticationContext.authenticate", lambda *args: True)
monkeypatch.setattr(
"atst.domain.authnid.AuthenticationContext.authenticate", lambda *args: True
)
cert_file = open("tests/fixtures/{}.crt".format(FIXTURE_EMAIL_ADDRESS)).read()
# ensure user does not exist

View File

@@ -3,15 +3,18 @@ from atst.eda_client import MockEDAClient
client = MockEDAClient()
def test_list_contracts():
results = client.list_contracts()
assert len(results) == 3
def test_get_contract():
result = client.get_contract("DCA10096D0052", "y")
assert result["contract_no"] == "DCA10096D0052"
assert result["amount"] == 2000000
def test_contract_not_found():
result = client.get_contract("abc", "y")
assert result is None

View File

@@ -3,13 +3,15 @@ import pytest
from atst.filters import dollars
@pytest.mark.parametrize("input,expected", [
('0', '$0'),
('123.00', '$123'),
('1234567', '$1,234,567'),
('-1234', '$-1,234'),
('one', '$0'),
])
@pytest.mark.parametrize(
"input,expected",
[
("0", "$0"),
("123.00", "$123"),
("1234567", "$1,234,567"),
("-1234", "$-1,234"),
("one", "$0"),
],
)
def test_dollar_fomatter(input, expected):
assert dollars(input) == expected

View File

@@ -1,6 +1,9 @@
import pytest
@pytest.mark.parametrize("path", (
@pytest.mark.parametrize(
"path",
(
"/",
"/home",
"/workspaces",
@@ -9,7 +12,8 @@ import pytest
"/users",
"/reports",
"/calculator",
))
),
)
def test_routes(path, client, user_session):
user_session()