Forms testing
For example, You want to test this django Form:
class ExampleForm(forms.Form):
"""
Example form class
"""
name = forms.CharField(max_length=5)
number = forms.IntegerField(initial=3)
This is the test. We use TrueForm model and assertTrueForm:
@tag('dry')
class ExampleFromTestCase(SimpleTestCase):
"""
Example Form Test Class
"""
def test_form(self):
"""
Example Test with django-dry-tests
:return:
"""
true_form = TrueForm( # Set Up TrueForm instance
Fields( # TrueForm Fields
count=2, # check fields count
names=[
'number', 'name'
], # check field names
types={
'name': forms.CharField,
'number': forms.IntegerField
} # check fields types
),
)
current_form = ExampleForm() # Get project form
self.assertTrueForm(current_form, true_form) # use this main assert to check all conditions