Validate that start_date is in the future
This commit is contained in:
parent
955a735f96
commit
b42b9812b0
@ -1,7 +1,7 @@
|
|||||||
import pendulum
|
import pendulum
|
||||||
from wtforms.fields.html5 import DateField, EmailField, IntegerField, TelField
|
from wtforms.fields.html5 import DateField, EmailField, IntegerField, TelField
|
||||||
from wtforms.fields import BooleanField, RadioField, StringField, TextAreaField
|
from wtforms.fields import BooleanField, RadioField, StringField, TextAreaField
|
||||||
from wtforms.validators import Email, Length, Optional, Required
|
from wtforms.validators import Email, Length, Optional, Required, DataRequired
|
||||||
|
|
||||||
from .fields import SelectField
|
from .fields import SelectField
|
||||||
from .forms import ValidatedForm
|
from .forms import ValidatedForm
|
||||||
@ -136,7 +136,14 @@ class DetailsOfUseForm(ValidatedForm):
|
|||||||
|
|
||||||
start_date = DateField(
|
start_date = DateField(
|
||||||
description="When do you expect to start using the JEDI Cloud (not for billing purposes)?",
|
description="When do you expect to start using the JEDI Cloud (not for billing purposes)?",
|
||||||
validators=[Required()],
|
validators=[
|
||||||
|
DataRequired(),
|
||||||
|
DateRange(
|
||||||
|
lower_bound=pendulum.duration(days=1),
|
||||||
|
upper_bound=None,
|
||||||
|
message="Must be a date in the future.",
|
||||||
|
),
|
||||||
|
],
|
||||||
format="%m/%d/%Y",
|
format="%m/%d/%Y",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
import re
|
import re
|
||||||
from wtforms.validators import ValidationError
|
from wtforms.validators import ValidationError
|
||||||
import pendulum
|
import pendulum
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def DateRange(lower_bound=None, upper_bound=None, message=None):
|
def DateRange(lower_bound=None, upper_bound=None, message=None):
|
||||||
def _date_range(form, field):
|
def _date_range(form, field):
|
||||||
now = pendulum.now().date()
|
now = pendulum.now().date()
|
||||||
|
|
||||||
|
if isinstance(field.data, str):
|
||||||
|
date = datetime.strptime(field.data, field.format)
|
||||||
|
else:
|
||||||
date = field.data
|
date = field.data
|
||||||
|
|
||||||
if lower_bound is not None:
|
if lower_bound is not None:
|
||||||
|
@ -13,7 +13,7 @@ class TestDetailsOfUseForm:
|
|||||||
"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/2050",
|
||||||
}
|
}
|
||||||
migration_data = {
|
migration_data = {
|
||||||
"jedi_migration": "yes",
|
"jedi_migration": "yes",
|
||||||
@ -87,3 +87,11 @@ class TestDetailsOfUseForm:
|
|||||||
|
|
||||||
request_form = DetailsOfUseForm(data=data)
|
request_form = DetailsOfUseForm(data=data)
|
||||||
assert request_form.validate()
|
assert request_form.validate()
|
||||||
|
|
||||||
|
def test_start_date_must_be_in_the_future(self):
|
||||||
|
data = {**self.form_data, **self.migration_data}
|
||||||
|
data["start_date"] = "01/01/2018"
|
||||||
|
|
||||||
|
request_form = DetailsOfUseForm(data=data)
|
||||||
|
assert not request_form.validate()
|
||||||
|
assert "Must be a date in the future." in request_form.errors["start_date"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user