I’m having a heck of a time validating a 6-digit number:
# forms.py
class TheForm(forms.Form):
code = forms.RegexField(regex=r'^\d{6}$')
# tests.py
class TheFormTestCase(TestCase):
def test_the_form(self):
form = TheForm(initial={'code': '123456'})
self.assertTrue(form.is_valid(),
'Form should accept a string of 6 characters '
'that are digits')
My test case is returning invalid. Can someone please point out what I’m doing wrong?
As mentioned in the Django documentation:
You should use
dataargument: