Login, Register and Logout test failed AssertionError: 200 != 302 django

If you want to test that the user was successfully redirected (response code 302) then you can remove follow=True:

    def test_logged_out_user_was_redirected(self):
        self.client.login(email='[email protected]', password='testpassword')
        response = self.client.post(reverse('logout'))
        self.assertEquals(response.status_code, 302)

If you want to ensure that they were redirected to the right place you can set follow=True, set the code to 200, and use assertTemplateUsed:

    def test_logout_redirect_succeeds(self):
        self.client.login(email='[email protected]', password='testpassword')
        response = self.client.post(reverse('logout'), follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTemplateUsed(self.response, 'my_app/redirect_page.html')`

When you have follow=True the response code will be 200 if it succeeds, not 302.

I asked this question a long time ago and learned that follow=True was not possible in pytest. In the process I learned a bit about using the follow=True flag.

I am guessing the only test failing right now is test_logout. Your code for this is:

        response = self.client.post(reverse('logout'), follow=True)
        self.assertEquals(response.status_code, 302)

Please let me know if you have any questions or need for clarification and I can clean this up. If I am mistaken let me know.