From 368b30f1a3952d90e9e4b5c379758e867226f37d Mon Sep 17 00:00:00 2001 From: Xavier Francisco <98830734+XF-FW@users.noreply.github.com> Date: Thu, 31 Mar 2022 09:19:05 +0000 Subject: [PATCH 1/3] Update test.pyi --- rest_framework-stubs/test.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rest_framework-stubs/test.pyi b/rest_framework-stubs/test.pyi index 00f5a6617..0b862369e 100644 --- a/rest_framework-stubs/test.pyi +++ b/rest_framework-stubs/test.pyi @@ -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): ... From c8e29cf5d5a978c536875fa2ded3ded545c4339e Mon Sep 17 00:00:00 2001 From: Xavier Francisco Date: Sat, 28 May 2022 02:04:58 +0000 Subject: [PATCH 2/3] Add test --- tests/typecheck/test_test.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/typecheck/test_test.yml diff --git a/tests/typecheck/test_test.yml b/tests/typecheck/test_test.yml new file mode 100644 index 000000000..17c0bb5ed --- /dev/null +++ b/tests/typecheck/test_test.yml @@ -0,0 +1,9 @@ +- case: test_api_test_case + main: | + from rest_framework import test, status + + class MyTest(test.APITestCase): + def test_example(self) -> None: + response = self.client.get('/', format="json") + self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + self.assertEqual(response.data, {"detail": {"not_found"}}) From 75ca712f7f3924a27d09afd162d65328da9fdf66 Mon Sep 17 00:00:00 2001 From: Xavier Francisco Date: Sun, 29 May 2022 03:07:08 +0000 Subject: [PATCH 3/3] Update tests --- tests/typecheck/test_test.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/typecheck/test_test.yml b/tests/typecheck/test_test.yml index 17c0bb5ed..69940d325 100644 --- a/tests/typecheck/test_test.yml +++ b/tests/typecheck/test_test.yml @@ -1,9 +1,28 @@ -- case: test_api_test_case +- 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.APITestCase): + 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)