title: how to test model form in django?
body: <p>wrote a test case to test the <em>FilterForm</em></p>
  
  <pre><code>class MyTestCreateFilter(TestCase):
  
    def test_createfilter(self):
      self.client = Client()     
      self.user = User.objects.create_superuser(username='bizi111',email='test5@example.com',password='bizi111')
      self.user = authenticate(username='bizi111', password='bizi111')
      #print self.user
      self.factory = RequestFactory()
      request = self.factory.get('/filter/new')
      request.user = self.user
      response = create_or_edit_filter(request)
      self.assertEqual(response.status_code, 200)
  
      filterform = FilterForm()
      #print filterform.is_valid()
      form_data = {'keyword': 'it','industry':'it','zip_code':'50005','distance':30}
  
      filteform = FilterForm(form_data)
  
      self.assertEqual(filteform.is_valid(), True)
  </code></pre>
  
  <p><strong>FilterForm has a clean method:</strong></p>
  
  <pre><code>    def clean(self):
          #print self.instance.user_profile
          user_profile = self.instance.user_profile
          keyword = self.cleaned_data.get("keyword")
          if Filter.objects.filter(user_profile=user_profile, keyword=keyword).exclude(id=self.instance.id).count() &gt; 0:
              msg = u"A filter with that keyword already exists!"
              self._errors["keyword"] = self.error_class([msg])
  
          return self.cleaned_data
  </code></pre>
  
  <p><strong>giving this error:</strong></p>
  
  <blockquote>
    <p>File "/home/suma/workspace2/bizintro/bizintro/forms.py", line 80, in
    clean
        user_profile = self.instance.user_profile   File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py",
    line 343, in <strong>get</strong>
        raise self.field.rel.to.DoesNotExist DoesNotExist</p>
  </blockquote>
  
  <p>how to solve it.</p>