djangorestframework-stubs icon indicating copy to clipboard operation
djangorestframework-stubs copied to clipboard

APIClient methods Response return

Open martinlehoux opened this issue 4 years ago • 1 comments

DRF defines APITestCase this way:

class APITestCase(testcases.TestCase):
    client_class = APIClient

So typing doesn't infer the new client type, and uses instead Django Client, which has the correct return type for its HTTP methods (method) get: (path: str, data: Any = ..., follow: bool = ..., secure: bool = ..., **extra: Any) -> HttpResponse

But when I subclass APITestCase and want to customize it and type it with:

class TokenAuthAPITestCase(APITestCase):
    client: APIClient

I have this return type for APIClient.post: (method) get: (path: Unknown, data: Unknown = None, follow: Unknown = False, **extra: Unknown) -> Unknown | WSGIRequest

Shouldn't it return a rest_framework.response.Response instance?

Let me know if I'm right, and in this case if I can help with that

martinlehoux avatar Jan 29 '21 08:01 martinlehoux

I'm getting the same error in my tests - it seems that self.client is typed as django.test.client.Client in my tests, instead of the expected APIClient, even though my test class subclasses APITestCase.

YPCrumble avatar Jan 14 '22 19:01 YPCrumble

Sounds like it was fixed :)

martinlehoux avatar Dec 15 '22 22:12 martinlehoux