title: Django: Testing the 'clean' method of a custom ModelForm using Model-Mommy
body: <p>======= <strong>Update</strong> =======</p>
  
  <p>@JF brought forward a brilliant perspective for the use of <a href="https://github.com/vandersonmota/model_mommy" rel="nofollow">model mommy</a> in ModelForms. </p>
  
  <p>With the following code, I managed to automatically generate random data for all the fields of the model, except for the ones I would like to manipulate.</p>
  
  <p>tests.py:</p>
  
  <pre><code>from django.test import TestCase
  from houses.forms import ManForm
  from houses.models import Man
  
  class ModelsTest(TestCase):
  
      def test_Man(self):
          man = mommy.make('Man', age=20)
          data = {each_field.name: getattr(man, each_field.name) for each_field in man._meta.fields}
          data.update({'age_verification': 20})
          form = ManForm(data)
          self.assertTrue (form.is_valid())
  </code></pre>
  
  <hr>
  
  <p>models.py</p>
  
  <pre><code>from django.db import models
  
  class Man(models.Model):
      name = models.CharField(max_length = 12)
      age = models.PositiveSmallIntegerField()
  </code></pre>
  
  <p>forms.py:</p>
  
  <pre><code>from my_app.models import Man
  from django import forms
  from django.core.exceptions import ValidationError
  
  class ManForm(forms.ModelForm):
      age_verification = forms.IntegerField()
  
      def clean(self):
          if not self.cleaned_data['age'] == self.cleaned_data['age_verification']:
              raise ValidationError("Is this a LIE?")
  
      class Meta:
          model = Man
          fields = ['name', 'age', 'age_verification']    
  </code></pre>
  
  <p>For the time being, I test it like this:</p>
  
  <p>tests.py:</p>
  
  <pre><code>from django.test import TestCase
  from houses.forms import ManForm
  
  class ModelsTest(TestCase):
  
      def test_Man(self):
          data = {
              'name' = 'John',
              'age' = 20,
              'ege_verification' = 20,
          }
          form = ManForm(data)
  </code></pre>
  
  <p>Is there a tool that provides random data for Forms? 
  Or ... can I use the <a href="https://www.djangopackages.com/grids/g/fixtures/" rel="nofollow">available tools</a> for models for this purpose? 
  Searching the docs of those supporting Python 3, I did not understand how this could be achieved.</p>
  
  <p>The only one that clearly provides such a service is <a href="https://www.djangopackages.com/packages/p/django-whatever/" rel="nofollow">Django-Whatever</a> which is not python3 compatible. </p>