[Answered ]-Django test for a page that redirects

1👍

Then just login first after instancing your client. Your view only works by logging in, so you need to login first?

client.login(email="testuser1@example.com", password="testpass123")

Or whatever user login works in your test setUp

Edit: use a setUp for all your tests, so you have some initial data for all of them:

class TestViews(TestCase):
    def setUp(self):
        self.user = get_user_model().objects.create_user(email="testuser1@example.com",password="testpass123",)
    def test_that_membership_resolves(self):
        client = Client()
        client.login(email="testuser1@example.com", password="testpass123")
        response = client.post('/membership/', {
            # I then pass the necessary values in a dictionary
            ...
            ...
        })
        self.assertRedirects(response, reverse("src:dashboard"))


    def test_whatever_else_comes_next_to_test(self):
        # use your setUp data again for another test

Leave a comment