rename and consolidate new request forms into one namespace
This commit is contained in:
parent
a96af2d095
commit
e863f85319
@ -1,6 +1,7 @@
|
||||
from wtforms.fields.html5 import DateField, IntegerField
|
||||
from wtforms.fields import RadioField, TextAreaField
|
||||
from wtforms.validators import Optional, Required
|
||||
import pendulum
|
||||
from wtforms.fields.html5 import DateField, EmailField, IntegerField, TelField
|
||||
from wtforms.fields import BooleanField, RadioField, StringField, TextAreaField
|
||||
from wtforms.validators import Email, Length, Optional, Required
|
||||
|
||||
from .fields import SelectField
|
||||
from .forms import ValidatedForm
|
||||
@ -10,10 +11,11 @@ from .data import (
|
||||
DATA_TRANSFER_AMOUNTS,
|
||||
COMPLETION_DATE_RANGES,
|
||||
)
|
||||
from .validators import Alphabet, DateRange, PhoneNumber, IsNumber
|
||||
from atst.domain.requests import Requests
|
||||
|
||||
|
||||
class RequestForm(ValidatedForm):
|
||||
class DetailsOfUseForm(ValidatedForm):
|
||||
def validate(self, *args, **kwargs):
|
||||
if self.jedi_migration.data == "no":
|
||||
self.rationalization_software_systems.validators.append(Optional())
|
||||
@ -36,7 +38,7 @@ class RequestForm(ValidatedForm):
|
||||
self.number_user_sessions.validators.append(Required())
|
||||
self.average_daily_traffic.validators.append(Required())
|
||||
|
||||
return super(RequestForm, self).validate(*args, **kwargs)
|
||||
return super(DetailsOfUseForm, self).validate(*args, **kwargs)
|
||||
|
||||
# Details of Use: General
|
||||
dod_component = SelectField(
|
||||
@ -137,3 +139,91 @@ class RequestForm(ValidatedForm):
|
||||
validators=[Required()],
|
||||
format="%m/%d/%Y",
|
||||
)
|
||||
|
||||
|
||||
class InformationAboutYouForm(ValidatedForm):
|
||||
fname_request = StringField("First Name", validators=[Required(), Alphabet()])
|
||||
|
||||
lname_request = StringField("Last Name", validators=[Required(), Alphabet()])
|
||||
|
||||
email_request = EmailField("E-mail Address", validators=[Required(), Email()])
|
||||
|
||||
phone_number = TelField(
|
||||
"Phone Number",
|
||||
description="Enter a 10-digit phone number",
|
||||
validators=[Required(), PhoneNumber()],
|
||||
)
|
||||
|
||||
service_branch = SelectField(
|
||||
"Service Branch or Agency",
|
||||
description="Which services and organizations do you belong to within the DoD?",
|
||||
choices=SERVICE_BRANCHES,
|
||||
)
|
||||
|
||||
citizenship = RadioField(
|
||||
description="What is your citizenship status?",
|
||||
choices=[
|
||||
("United States", "United States"),
|
||||
("Foreign National", "Foreign National"),
|
||||
("Other", "Other"),
|
||||
],
|
||||
validators=[Required()],
|
||||
)
|
||||
|
||||
designation = RadioField(
|
||||
"Designation of Person",
|
||||
description="What is your designation within the DoD?",
|
||||
choices=[
|
||||
("military", "Military"),
|
||||
("civilian", "Civilian"),
|
||||
("contractor", "Contractor"),
|
||||
],
|
||||
validators=[Required()],
|
||||
)
|
||||
|
||||
date_latest_training = DateField(
|
||||
"Latest Information Assurance (IA) Training Completion Date",
|
||||
description='To complete the training, you can find it in <a class="icon-link" href="https://iatraining.disa.mil/eta/disa_cac2018/launchPage.htm" target="_blank">Information Assurance Cyber Awareness Challange</a> website.',
|
||||
validators=[
|
||||
Required(),
|
||||
DateRange(
|
||||
lower_bound=pendulum.duration(years=1),
|
||||
upper_bound=pendulum.duration(days=0),
|
||||
message="Must be a date within the last year.",
|
||||
),
|
||||
],
|
||||
format="%m/%d/%Y",
|
||||
)
|
||||
|
||||
|
||||
class WorkspaceOwnerForm(ValidatedForm):
|
||||
def validate(self, *args, **kwargs):
|
||||
if self.am_poc.data:
|
||||
# Prepend Optional validators so that the validation chain
|
||||
# halts if no data exists.
|
||||
self.fname_poc.validators.insert(0, Optional())
|
||||
self.lname_poc.validators.insert(0, Optional())
|
||||
self.email_poc.validators.insert(0, Optional())
|
||||
self.dodid_poc.validators.insert(0, Optional())
|
||||
|
||||
return super().validate(*args, **kwargs)
|
||||
|
||||
am_poc = BooleanField(
|
||||
"I am the Workspace Owner",
|
||||
default=False,
|
||||
false_values=(False, "false", "False", "no", ""),
|
||||
)
|
||||
|
||||
fname_poc = StringField("First Name", validators=[Required()])
|
||||
|
||||
lname_poc = StringField("Last Name", validators=[Required()])
|
||||
|
||||
email_poc = EmailField("Email Address", validators=[Required(), Email()])
|
||||
|
||||
dodid_poc = StringField(
|
||||
"DOD ID", validators=[Required(), Length(min=10), IsNumber()]
|
||||
)
|
||||
|
||||
|
||||
class ReviewAndSubmitForm(ValidatedForm):
|
||||
reviewed = BooleanField("I have reviewed this data and it is correct.")
|
@ -1,64 +0,0 @@
|
||||
from wtforms.fields.html5 import DateField, EmailField, TelField
|
||||
from wtforms.fields import RadioField, StringField
|
||||
from wtforms.validators import Required, Email
|
||||
import pendulum
|
||||
|
||||
from .fields import SelectField
|
||||
from .forms import ValidatedForm
|
||||
from .validators import DateRange, PhoneNumber, Alphabet
|
||||
from .data import SERVICE_BRANCHES
|
||||
|
||||
|
||||
class OrgForm(ValidatedForm):
|
||||
fname_request = StringField("First Name", validators=[Required(), Alphabet()])
|
||||
|
||||
lname_request = StringField("Last Name", validators=[Required(), Alphabet()])
|
||||
|
||||
email_request = EmailField("E-mail Address", validators=[Required(), Email()])
|
||||
|
||||
phone_number = TelField(
|
||||
"Phone Number",
|
||||
description="Enter a 10-digit phone number",
|
||||
validators=[Required(), PhoneNumber()],
|
||||
)
|
||||
|
||||
service_branch = SelectField(
|
||||
"Service Branch or Agency",
|
||||
description="Which services and organizations do you belong to within the DoD?",
|
||||
choices=SERVICE_BRANCHES,
|
||||
)
|
||||
|
||||
citizenship = RadioField(
|
||||
description="What is your citizenship status?",
|
||||
choices=[
|
||||
("United States", "United States"),
|
||||
("Foreign National", "Foreign National"),
|
||||
("Other", "Other"),
|
||||
],
|
||||
validators=[Required()],
|
||||
)
|
||||
|
||||
designation = RadioField(
|
||||
"Designation of Person",
|
||||
description="What is your designation within the DoD?",
|
||||
choices=[
|
||||
("military", "Military"),
|
||||
("civilian", "Civilian"),
|
||||
("contractor", "Contractor"),
|
||||
],
|
||||
validators=[Required()],
|
||||
)
|
||||
|
||||
date_latest_training = DateField(
|
||||
"Latest Information Assurance (IA) Training Completion Date",
|
||||
description='To complete the training, you can find it in <a class="icon-link" href="https://iatraining.disa.mil/eta/disa_cac2018/launchPage.htm" target="_blank">Information Assurance Cyber Awareness Challange</a> website.',
|
||||
validators=[
|
||||
Required(),
|
||||
DateRange(
|
||||
lower_bound=pendulum.duration(years=1),
|
||||
upper_bound=pendulum.duration(days=0),
|
||||
message="Must be a date within the last year.",
|
||||
),
|
||||
],
|
||||
format="%m/%d/%Y",
|
||||
)
|
@ -1,34 +0,0 @@
|
||||
from wtforms.fields import StringField, BooleanField
|
||||
from wtforms.fields.html5 import EmailField
|
||||
from wtforms.validators import Required, Email, Length, Optional
|
||||
from .forms import ValidatedForm
|
||||
from .validators import IsNumber
|
||||
|
||||
|
||||
class POCForm(ValidatedForm):
|
||||
def validate(self, *args, **kwargs):
|
||||
if self.am_poc.data:
|
||||
# Prepend Optional validators so that the validation chain
|
||||
# halts if no data exists.
|
||||
self.fname_poc.validators.insert(0, Optional())
|
||||
self.lname_poc.validators.insert(0, Optional())
|
||||
self.email_poc.validators.insert(0, Optional())
|
||||
self.dodid_poc.validators.insert(0, Optional())
|
||||
|
||||
return super().validate(*args, **kwargs)
|
||||
|
||||
am_poc = BooleanField(
|
||||
"I am the Workspace Owner",
|
||||
default=False,
|
||||
false_values=(False, "false", "False", "no", ""),
|
||||
)
|
||||
|
||||
fname_poc = StringField("First Name", validators=[Required()])
|
||||
|
||||
lname_poc = StringField("Last Name", validators=[Required()])
|
||||
|
||||
email_poc = EmailField("Email Address", validators=[Required(), Email()])
|
||||
|
||||
dodid_poc = StringField(
|
||||
"DOD ID", validators=[Required(), Length(min=10), IsNumber()]
|
||||
)
|
@ -1,7 +0,0 @@
|
||||
from wtforms.fields import BooleanField
|
||||
|
||||
from .forms import ValidatedForm
|
||||
|
||||
|
||||
class ReviewForm(ValidatedForm):
|
||||
reviewed = BooleanField("I have reviewed this data and it is correct.")
|
@ -1,10 +1,7 @@
|
||||
from collections import defaultdict
|
||||
|
||||
from atst.domain.requests import Requests
|
||||
from atst.forms.request import RequestForm
|
||||
from atst.forms.org import OrgForm
|
||||
from atst.forms.poc import POCForm
|
||||
from atst.forms.review import ReviewForm
|
||||
import atst.forms.new_request as request_forms
|
||||
|
||||
|
||||
class JEDIRequestFlow(object):
|
||||
@ -58,9 +55,9 @@ class JEDIRequestFlow(object):
|
||||
def form_class(self):
|
||||
return self.current_screen["form"]
|
||||
|
||||
# maps user data to fields in OrgForm; this should be moved into the
|
||||
# request initialization process when we have a request schema, or we just
|
||||
# shouldn't record this data on the request
|
||||
# maps user data to fields in InformationAboutYouForm; this should be moved
|
||||
# into the request initialization process when we have a request schema, or
|
||||
# we just shouldn't record this data on the request
|
||||
def map_user_data(self, user):
|
||||
return {
|
||||
"fname_request": user.first_name,
|
||||
@ -102,18 +99,22 @@ class JEDIRequestFlow(object):
|
||||
{
|
||||
"title": "Details of Use",
|
||||
"section": "details_of_use",
|
||||
"form": RequestForm,
|
||||
"form": request_forms.DetailsOfUseForm,
|
||||
},
|
||||
{
|
||||
"title": "Information About You",
|
||||
"section": "information_about_you",
|
||||
"form": OrgForm,
|
||||
"form": request_forms.InformationAboutYouForm,
|
||||
},
|
||||
{
|
||||
"title": "Workspace Owner",
|
||||
"section": "primary_poc",
|
||||
"form": request_forms.WorkspaceOwnerForm,
|
||||
},
|
||||
{"title": "Workspace Owner", "section": "primary_poc", "form": POCForm},
|
||||
{
|
||||
"title": "Review & Submit",
|
||||
"section": "review_submit",
|
||||
"form": ReviewForm,
|
||||
"form": request_forms.ReviewAndSubmitForm,
|
||||
},
|
||||
]
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from atst.forms.request import RequestForm
|
||||
from atst.forms.new_request import DetailsOfUseForm
|
||||
|
||||
|
||||
class TestRequestForm:
|
||||
class TestDetailsOfUseForm:
|
||||
|
||||
form_data = {
|
||||
"dod_component": "Army and Air Force Exchange Service",
|
||||
@ -27,7 +27,7 @@ class TestRequestForm:
|
||||
|
||||
def test_require_cloud_native_when_not_migrating(self):
|
||||
extra_data = {"jedi_migration": "no"}
|
||||
request_form = RequestForm(data={**self.form_data, **extra_data})
|
||||
request_form = DetailsOfUseForm(data={**self.form_data, **extra_data})
|
||||
assert not request_form.validate()
|
||||
assert request_form.errors == {"cloud_native": ["Not a valid choice"]}
|
||||
|
||||
@ -37,7 +37,7 @@ class TestRequestForm:
|
||||
"data_transfers": "",
|
||||
"expected_completion_date": "",
|
||||
}
|
||||
request_form = RequestForm(data={**self.form_data, **extra_data})
|
||||
request_form = DetailsOfUseForm(data={**self.form_data, **extra_data})
|
||||
assert not request_form.validate()
|
||||
assert request_form.errors == {
|
||||
"rationalization_software_systems": ["Not a valid choice"],
|
||||
@ -52,7 +52,7 @@ class TestRequestForm:
|
||||
data = {**self.form_data, **self.migration_data}
|
||||
del data["organization_providing_assistance"]
|
||||
|
||||
request_form = RequestForm(data=data)
|
||||
request_form = DetailsOfUseForm(data=data)
|
||||
assert not request_form.validate()
|
||||
assert request_form.errors == {
|
||||
"organization_providing_assistance": ["Not a valid choice"]
|
||||
@ -63,7 +63,7 @@ class TestRequestForm:
|
||||
data["technical_support_team"] = "no"
|
||||
del data["organization_providing_assistance"]
|
||||
|
||||
request_form = RequestForm(data=data)
|
||||
request_form = DetailsOfUseForm(data=data)
|
||||
assert request_form.validate()
|
||||
|
||||
def test_sessions_required_for_large_projects(self):
|
||||
@ -72,7 +72,7 @@ class TestRequestForm:
|
||||
del data["number_user_sessions"]
|
||||
del data["average_daily_traffic"]
|
||||
|
||||
request_form = RequestForm(data=data)
|
||||
request_form = DetailsOfUseForm(data=data)
|
||||
assert not request_form.validate()
|
||||
assert request_form.errors == {
|
||||
"number_user_sessions": ["This field is required."],
|
||||
@ -85,5 +85,5 @@ class TestRequestForm:
|
||||
del data["number_user_sessions"]
|
||||
del data["average_daily_traffic"]
|
||||
|
||||
request_form = RequestForm(data=data)
|
||||
request_form = DetailsOfUseForm(data=data)
|
||||
assert request_form.validate()
|
@ -21,7 +21,9 @@ def test_submit_invalid_request_form(monkeypatch, client, user_session):
|
||||
|
||||
def test_submit_valid_request_form(monkeypatch, client, user_session):
|
||||
user_session()
|
||||
monkeypatch.setattr("atst.forms.request.RequestForm.validate", lambda s: True)
|
||||
monkeypatch.setattr(
|
||||
"atst.forms.new_request.DetailsOfUseForm.validate", lambda s: True
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
"/requests/new/1",
|
||||
|
Loading…
x
Reference in New Issue
Block a user