Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rest_framework-stubs/test.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ class APIClient(APIRequestFactory, DjangoClient):

class APITransactionTestCase(testcases.TransactionTestCase):
client_class: Type[APIClient] = ...
client: APIClient

class APITestCase(testcases.TestCase):
client_class: Type[APIClient] = ...
client: APIClient

class APISimpleTestCase(testcases.SimpleTestCase):
client_class: Type[APIClient] = ...
client: APIClient

class APILiveServerTestCase(testcases.LiveServerTestCase):
client_class: Type[APIClient] = ...
client: APIClient

class URLPatternsTestCase(testcases.SimpleTestCase): ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

28 changes: 28 additions & 0 deletions tests/typecheck/test_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- case: test_testcases_client_api
parametrized:
- test_class: APITransactionTestCase
- test_class: APITestCase
- test_class: APISimpleTestCase
- test_class: APILiveServerTestCase
main: |
from rest_framework import test, status

class MyTest(test.{{ test_class }}):
def test_example(self) -> None:
reveal_type(self.client) # N: Revealed type is "rest_framework.test.APIClient"
response = self.client.get('/', format="json")
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.data, {"detail": {"not_found"}})

- case: test_testcases_client_api_urlpatterns
main: |
from typing import Union, List
from django.urls import URLPattern, URLResolver
from rest_framework import test, status

class MyTest(test.URLPatternsTestCase):
urlpatterns : List[Union[URLPattern, URLResolver]] = []
def test_example(self) -> None:
reveal_type(self.client) # N: Revealed type is "django.test.client.Client"
response = self.client.get('/', format="json")
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)