我正在尝试编写一个测试来注册用户。我无法验证表单,因为我不知道如何向表单提交有效日期。这是违规代码:
class AccountManagementTest(TestCase):
def test_signup(self):
response = self.client.post(reverse('register'), {
'first_name': 'Gandalf',
'last_name': 'TheGrey',
'email': 'gandalf@me.com',
'password1': 'SauronSucks',
'password2': 'SauronSucks',
'birthdate': datetime(1956, 1, 1),
'tos': True})
Run Code Online (Sandbox Code Playgroud)
我可以输出response.content之后,表单中的错误是“请输入有效日期。” 我没有覆盖表单中的clean方法birthdate。这是表单中日期字段的声明:
birthdate = forms.DateField(
widget=SelectDateWidget(
years=range(this_year-90, this_year-12)[::-1]),
required=True,)
Run Code Online (Sandbox Code Playgroud)
我怎么给它发送一个有效的日期?