title: Django test client post data
body: <p><strong>The problem has been solved thanks to Thaian, by adding a login to the beginning of the 'test_create' function, as you need to be logged in on this site to use the createview</strong></p>
  
  <p>I am currently writing a test for a createview and I am unable to post data to it. </p>
  
  <p>The object being tested has the following model</p>
  
  <pre><code>class Role(models.Model):
      name = models.CharField(max_length=255)
      linked_tenant = models.ForeignKey(Tenant, blank=True, null=True)
  </code></pre>
  
  <p>And is used in the following (generic) view</p>
  
  <pre><code>class RolCreate(TenantRootedMixin, CreateView):
      model = RolTemplate
      form_class = RoleForm
  
      def get_form_kwargs(self):
          kwargs = super(RolCreate, self).get_form_kwargs()
          kwargs['linked_tenant'] = self.request.tenant
          return kwargs
  
      def form_valid(self, form):
          form.instance.linked_tenant = self.kwargs.get('tenant')
          return super(RolCreate, self).form_valid(form)
  
      def get_success_url(self, **kwargs):
          return reverse('rol_list', args=[self.request.tenant.slug])
  </code></pre>
  
  <p>And this is the test that I am using. </p>
  
  <pre><code>class RolCreate_tests(TestCase):
  
      def setUp(self):
          self.tenant = get_tenant()
          self.role = get_role(self.tenant)
          self.client = Client(HTTP_HOST='tc.tc:8000')
          self.user = get_user(self.tenant)
  
      def test_create(self):
  
          response = self.client.post(reverse('rolcreate'), {'name' : 'new_object'})
          self.assertEqual(response.status_code, 302)
          test_against = Role.objects.get(name='new_object')
          self.assertEqual(test_against, self.tenant)
  </code></pre>
  
  <p>The assertion that throws the error is the 'get' request at the end. </p>
  
  <pre><code>DoesNotExist: Role matching query does not exist.
  </code></pre>
  
  <p>So the object is not created, yet the test does validate the 302 view, meaning a post is being made. I do not understand why this test is failing to do what it should. Could someone here help me?</p>
  
  <p>=====</p>
  
  <p>After Thaians suggestions I got the following values:</p>
  
  <pre><code>(Pdb) print(self.client.post)
  &lt;bound method Client.post of &lt;django.test.client.Client object at     0x10f20da50&gt;&gt;
  
  Pdb) response
  &lt;HttpResponseRedirect status_code=302, "text/html; charset=utf-8", url="/accounts/login/?next=/my/role/create/"&gt;
  (Pdb) print(response)
  Vary: Cookie
  Content-Length: 0
  Content-Type: text/html; charset=utf-8
  Location: /accounts/login/?next=/my/role/create/
  </code></pre>