Show/hide additional fields when annual is more than a million

This commit is contained in:
Patrick Smith 2018-08-13 10:32:39 -04:00
parent 95267f6031
commit 0ccdb8ecfd
3 changed files with 55 additions and 22 deletions

View File

@ -1,6 +1,6 @@
from wtforms.fields.html5 import IntegerField from wtforms.fields.html5 import IntegerField
from wtforms.fields import RadioField, TextAreaField, SelectField from wtforms.fields import RadioField, TextAreaField, SelectField
from wtforms.validators import Optional from wtforms.validators import Optional, Required
from .fields import DateField from .fields import DateField
from .forms import ValidatedForm from .forms import ValidatedForm
@ -20,6 +20,15 @@ class RequestForm(ValidatedForm):
self.organization_providing_assistance.validators.append(Optional()) self.organization_providing_assistance.validators.append(Optional())
self.cloud_native.validators.append(Optional()) self.cloud_native.validators.append(Optional())
try:
annual_spend = int(self.estimated_monthly_spend.data or 0) * 12
except ValueError:
annual_spend = 0
if annual_spend > 1_000_000:
self.number_user_sessions.validators.append(Required())
self.average_daily_traffic.validators.append(Required())
return super(RequestForm, self).validate(*args, **kwargs) return super(RequestForm, self).validate(*args, **kwargs)
# Details of Use: General # Details of Use: General

View File

@ -50,8 +50,10 @@
{{ TextInput(f.estimated_monthly_spend, validation='dollars') }} {{ TextInput(f.estimated_monthly_spend, validation='dollars') }}
<p>So this means you are spending approximately <b>!{ annualSpendStr }</b> annually</p> <p>So this means you are spending approximately <b>!{ annualSpendStr }</b> annually</p>
{{ TextInput(f.dollar_value, validation='dollars') }} {{ TextInput(f.dollar_value, validation='dollars') }}
{{ TextInput(f.number_user_sessions, validation='integer') }} <template v-if="annualSpend > 1000000">
{{ TextInput(f.average_daily_traffic, placeholder='Gigabytes per day', validation='gigabytes') }} {{ TextInput(f.number_user_sessions, validation='integer') }}
{{ TextInput(f.average_daily_traffic, placeholder='Gigabytes per day', validation='gigabytes') }}
</template>
{{ TextInput(f.start_date, validation='date', placeholder='MM / DD / YYYY') }} {{ TextInput(f.start_date, validation='date', placeholder='MM / DD / YYYY') }}
</div> </div>

View File

@ -9,12 +9,21 @@ class TestRequestForm:
'dod_component': 'us_air_force', 'dod_component': 'us_air_force',
'jedi_usage': 'cloud-ify all the things', 'jedi_usage': 'cloud-ify all the things',
'num_software_systems': '12', 'num_software_systems': '12',
'estimated_monthly_spend': '34', 'estimated_monthly_spend': '1000000',
'dollar_value': '42', 'dollar_value': '42',
'number_user_sessions': '6', 'number_user_sessions': '6',
'average_daily_traffic': '0', 'average_daily_traffic': '0',
'start_date': '12/12/2012', 'start_date': '12/12/2012',
} }
migration_data = {
'jedi_migration': 'yes',
'rationalization_software_systems': 'yes',
'technical_support_team': 'yes',
'organization_providing_assistance': 'in_house_staff',
'engineering_assessment': 'yes',
'data_transfers': 'less_than_100gb',
'expected_completion_date': 'less_than_1_month'
}
def test_require_cloud_native_when_not_migrating(self): def test_require_cloud_native_when_not_migrating(self):
extra_data = { 'jedi_migration': 'no' } extra_data = { 'jedi_migration': 'no' }
@ -36,28 +45,41 @@ class TestRequestForm:
} }
def test_require_organization_when_technical_support_team(self): def test_require_organization_when_technical_support_team(self):
extra_data = { data = { **self.form_data, **self.migration_data }
'jedi_migration': 'yes', del data['organization_providing_assistance']
'rationalization_software_systems': 'yes',
'technical_support_team': 'yes', request_form = RequestForm(data=data)
'engineering_assessment': 'yes',
'data_transfers': 'less_than_100gb',
'expected_completion_date': 'less_than_1_month'
}
request_form = RequestForm(data={ **self.form_data, **extra_data })
assert not request_form.validate() assert not request_form.validate()
assert request_form.errors == { assert request_form.errors == {
'organization_providing_assistance': ['Not a valid choice'], 'organization_providing_assistance': ['Not a valid choice'],
} }
def test_valid_form_data(self): def test_valid_form_data(self):
extra_data = { data = { **self.form_data, **self.migration_data }
'jedi_migration': 'yes', data['technical_support_team'] = 'no'
'rationalization_software_systems': 'yes', del data['organization_providing_assistance']
'technical_support_team': 'no',
'engineering_assessment': 'yes', request_form = RequestForm(data=data)
'data_transfers': 'less_than_100gb', assert request_form.validate()
'expected_completion_date': 'less_than_1_month'
} def test_sessions_required_for_large_projects(self):
request_form = RequestForm(data={ **self.form_data, **extra_data }) data = { **self.form_data, **self.migration_data }
data['estimated_monthly_spend'] = '9999999'
del data['number_user_sessions']
del data['average_daily_traffic']
request_form = RequestForm(data=data)
assert not request_form.validate()
assert request_form.errors == {
'number_user_sessions': ['This field is required.'],
'average_daily_traffic': ['This field is required.'],
}
def test_sessions_not_required_invalid_monthly_spend(self):
data = { **self.form_data, **self.migration_data }
data['estimated_monthly_spend'] = 'foo'
del data['number_user_sessions']
del data['average_daily_traffic']
request_form = RequestForm(data=data)
assert request_form.validate() assert request_form.validate()