1
votes

Test case setUp() that first creates a user and the try's to force authenticate the user but a wired error occurs...

TypeError: force_authenticate() missing 1 required positional argument: 'self'

class PrivateUserApiTest(TestCase):
    """ Test API that require authentication """

    def setUp(self):
        self.user = create_user(
            email="[email protected]",
            password="testpass",
            name="testName"
        )
        print(self.user)
        self.client = APIClient
        self.client.force_authenticate(user=self.user) # <-- 
1
there should be self.client=APIClient() - Bhavya Parikh
First check if your force_authenticate method has first argument self, such as: def force_authenticate(self, user, other, arguments):. - Leon Markes
@BhavyaParikh True, it works - Amir Rezazadeh

1 Answers

0
votes

as @BhavyaParikh said, instead of this:

self.client = APIClient

do this:

self.client = APIClient()