I am trying to unit test a form which includes a date selector. It is saved in the model as DateTimeField
and in the form uses a DatePickerInput
widget.
This is the test:
def test_form_validation_for_blank_items(self):
user = User.objects.create_superuser('username')
self.client.force_login(user)
form = PersonalInformationForm(data={
'first_name': '',
'surname': '',
'gender': '',
'dob': ''})
self.assertFalse(form.is_valid())
self.assertEqual(form.errors, {
'first_name': ['This field is required.'],
'surname': ['This field is required.'],
'gender': ['This field is required.'],
})
And the error that's thrown:
AttributeError: 'NoneType' object has no attribute 'year'
My other fields are fine, but I was wondering how to unit test a blank DateTimeField
model with a DatePickerInput
widget.
Thank you.