basic task order number validation
This commit is contained in:
parent
42325d5a28
commit
4c1ffecea5
@ -18,6 +18,7 @@ from atst.routes.dev import bp as dev_routes
|
|||||||
from atst.routes.errors import make_error_pages
|
from atst.routes.errors import make_error_pages
|
||||||
from atst.domain.authnid.crl import CRLCache
|
from atst.domain.authnid.crl import CRLCache
|
||||||
from atst.domain.auth import apply_authentication
|
from atst.domain.auth import apply_authentication
|
||||||
|
from atst.eda_client import MockEDAClient
|
||||||
|
|
||||||
|
|
||||||
ENV = os.getenv("FLASK_ENV", "dev")
|
ENV = os.getenv("FLASK_ENV", "dev")
|
||||||
@ -41,6 +42,7 @@ def make_app(config):
|
|||||||
make_flask_callbacks(app)
|
make_flask_callbacks(app)
|
||||||
make_crl_validator(app)
|
make_crl_validator(app)
|
||||||
register_filters(app)
|
register_filters(app)
|
||||||
|
make_eda_client(app)
|
||||||
|
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
csrf.init_app(app)
|
csrf.init_app(app)
|
||||||
@ -139,3 +141,5 @@ def make_crl_validator(app):
|
|||||||
crl_locations.append(filename.absolute())
|
crl_locations.append(filename.absolute())
|
||||||
app.crl_cache = CRLCache(app.config["CA_CHAIN"], crl_locations, logger=app.logger)
|
app.crl_cache = CRLCache(app.config["CA_CHAIN"], crl_locations, logger=app.logger)
|
||||||
|
|
||||||
|
def make_eda_client(app):
|
||||||
|
app.eda_client = MockEDAClient()
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import re
|
import re
|
||||||
from wtforms.fields.html5 import EmailField
|
from wtforms.fields.html5 import EmailField
|
||||||
from wtforms.fields import StringField
|
from wtforms.fields import StringField
|
||||||
from wtforms.validators import Required, Email, Regexp
|
from wtforms.validators import Required, Email, Regexp, ValidationError
|
||||||
|
|
||||||
from atst.domain.exceptions import NotFoundError
|
from atst.domain.exceptions import NotFoundError
|
||||||
from atst.domain.pe_numbers import PENumbers
|
from atst.domain.pe_numbers import PENumbers
|
||||||
|
from atst.domain.task_orders import TaskOrders
|
||||||
|
|
||||||
from .fields import NewlineListField, SelectField
|
from .fields import NewlineListField, SelectField
|
||||||
from .forms import ValidatedForm
|
from .forms import ValidatedForm
|
||||||
@ -114,7 +115,17 @@ class BaseFinancialForm(ValidatedForm):
|
|||||||
|
|
||||||
|
|
||||||
class FinancialForm(BaseFinancialForm):
|
class FinancialForm(BaseFinancialForm):
|
||||||
pass
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.eda_client = kwargs.get("eda_client")
|
||||||
|
if self.eda_client:
|
||||||
|
del(kwargs["eda_client"])
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def validate_task_order_id(form, field):
|
||||||
|
try:
|
||||||
|
TaskOrders.get(field.data, client=form.eda_client)
|
||||||
|
except NotFoundError:
|
||||||
|
raise ValidationError("Task Order number not found")
|
||||||
|
|
||||||
|
|
||||||
class ExtendedFinancialForm(BaseFinancialForm):
|
class ExtendedFinancialForm(BaseFinancialForm):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from flask import render_template, redirect, url_for
|
from flask import render_template, redirect, url_for
|
||||||
from flask import request as http_request
|
from flask import request as http_request
|
||||||
|
from flask import current_app as app
|
||||||
|
|
||||||
from . import requests_bp
|
from . import requests_bp
|
||||||
from atst.domain.requests import Requests
|
from atst.domain.requests import Requests
|
||||||
@ -10,7 +11,7 @@ def financial_form(data):
|
|||||||
if http_request.args.get("extended"):
|
if http_request.args.get("extended"):
|
||||||
return ExtendedFinancialForm(data=data)
|
return ExtendedFinancialForm(data=data)
|
||||||
else:
|
else:
|
||||||
return FinancialForm(data=data)
|
return FinancialForm(data=data, eda_client=app.eda_client)
|
||||||
|
|
||||||
|
|
||||||
@requests_bp.route("/requests/verify/<string:request_id>", methods=["GET"])
|
@requests_bp.route("/requests/verify/<string:request_id>", methods=["GET"])
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from atst.forms.financial import suggest_pe_id, FinancialForm, ExtendedFinancialForm
|
from atst.forms.financial import suggest_pe_id, FinancialForm, ExtendedFinancialForm
|
||||||
|
from atst.eda_client import MockEDAClient
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("input_,expected", [
|
@pytest.mark.parametrize("input_,expected", [
|
||||||
@ -67,3 +68,15 @@ def test_ba_code_validation(input_, expected):
|
|||||||
is_valid = "ba_code" not in form.errors
|
is_valid = "ba_code" not in form.errors
|
||||||
|
|
||||||
assert is_valid == expected
|
assert is_valid == expected
|
||||||
|
|
||||||
|
def test_task_order_id_validation():
|
||||||
|
form_invalid = FinancialForm(data={"task_order_id": "1234"}, eda_client=MockEDAClient())
|
||||||
|
form_invalid.validate()
|
||||||
|
|
||||||
|
assert "task_order_id" in form_invalid.errors
|
||||||
|
|
||||||
|
form_valid = FinancialForm(data={"task_order_id": MockEDAClient.MOCK_CONTRACT_NUMBER}, eda_client=MockEDAClient())
|
||||||
|
form_valid.validate()
|
||||||
|
|
||||||
|
assert "task_order_id" not in form_valid.errors
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user