Show/hide additional fields when annual is more than a million
This commit is contained in:
parent
95267f6031
commit
0ccdb8ecfd
@ -1,6 +1,6 @@
|
||||
from wtforms.fields.html5 import IntegerField
|
||||
from wtforms.fields import RadioField, TextAreaField, SelectField
|
||||
from wtforms.validators import Optional
|
||||
from wtforms.validators import Optional, Required
|
||||
from .fields import DateField
|
||||
from .forms import ValidatedForm
|
||||
|
||||
@ -20,6 +20,15 @@ class RequestForm(ValidatedForm):
|
||||
self.organization_providing_assistance.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)
|
||||
|
||||
# Details of Use: General
|
||||
|
@ -50,8 +50,10 @@
|
||||
{{ TextInput(f.estimated_monthly_spend, validation='dollars') }}
|
||||
<p>So this means you are spending approximately <b>!{ annualSpendStr }</b> annually</p>
|
||||
{{ TextInput(f.dollar_value, validation='dollars') }}
|
||||
{{ TextInput(f.number_user_sessions, validation='integer') }}
|
||||
{{ TextInput(f.average_daily_traffic, placeholder='Gigabytes per day', validation='gigabytes') }}
|
||||
<template v-if="annualSpend > 1000000">
|
||||
{{ 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') }}
|
||||
|
||||
</div>
|
||||
|
@ -9,12 +9,21 @@ class TestRequestForm:
|
||||
'dod_component': 'us_air_force',
|
||||
'jedi_usage': 'cloud-ify all the things',
|
||||
'num_software_systems': '12',
|
||||
'estimated_monthly_spend': '34',
|
||||
'estimated_monthly_spend': '1000000',
|
||||
'dollar_value': '42',
|
||||
'number_user_sessions': '6',
|
||||
'average_daily_traffic': '0',
|
||||
'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):
|
||||
extra_data = { 'jedi_migration': 'no' }
|
||||
@ -36,28 +45,41 @@ class TestRequestForm:
|
||||
}
|
||||
|
||||
def test_require_organization_when_technical_support_team(self):
|
||||
extra_data = {
|
||||
'jedi_migration': 'yes',
|
||||
'rationalization_software_systems': 'yes',
|
||||
'technical_support_team': 'yes',
|
||||
'engineering_assessment': 'yes',
|
||||
'data_transfers': 'less_than_100gb',
|
||||
'expected_completion_date': 'less_than_1_month'
|
||||
}
|
||||
request_form = RequestForm(data={ **self.form_data, **extra_data })
|
||||
data = { **self.form_data, **self.migration_data }
|
||||
del data['organization_providing_assistance']
|
||||
|
||||
request_form = RequestForm(data=data)
|
||||
assert not request_form.validate()
|
||||
assert request_form.errors == {
|
||||
'organization_providing_assistance': ['Not a valid choice'],
|
||||
}
|
||||
|
||||
def test_valid_form_data(self):
|
||||
extra_data = {
|
||||
'jedi_migration': 'yes',
|
||||
'rationalization_software_systems': 'yes',
|
||||
'technical_support_team': 'no',
|
||||
'engineering_assessment': 'yes',
|
||||
'data_transfers': 'less_than_100gb',
|
||||
'expected_completion_date': 'less_than_1_month'
|
||||
}
|
||||
request_form = RequestForm(data={ **self.form_data, **extra_data })
|
||||
data = { **self.form_data, **self.migration_data }
|
||||
data['technical_support_team'] = 'no'
|
||||
del data['organization_providing_assistance']
|
||||
|
||||
request_form = RequestForm(data=data)
|
||||
assert request_form.validate()
|
||||
|
||||
def test_sessions_required_for_large_projects(self):
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user