Skip to content

Commit

Permalink
fix: abstract api test case and client
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Nov 6, 2024
1 parent 5a85de9 commit 5b1d3bd
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 219 deletions.
4 changes: 2 additions & 2 deletions codeforlife/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Custom test cases.
"""

from .api import APITestCase
from .api_client import APIClient
from .api import APITestCase, BaseAPITestCase
from .api_client import APIClient, BaseAPIClient
from .api_request_factory import APIRequestFactory, BaseAPIRequestFactory
from .cron import CronTestCase
from .model import ModelTestCase
Expand Down
19 changes: 15 additions & 4 deletions codeforlife/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import typing as t

from .api_client import APIClient
from .api_client import APIClient, BaseAPIClient
from .test import TestCase

# pylint: disable=duplicate-code
Expand All @@ -15,14 +15,25 @@
RequestUser = t.TypeVar("RequestUser", bound=User)
else:
RequestUser = t.TypeVar("RequestUser")

AnyBaseAPIClient = t.TypeVar("AnyBaseAPIClient", bound=BaseAPIClient)
# pylint: enable=duplicate-code


class APITestCase(TestCase, t.Generic[RequestUser]):
class BaseAPITestCase(TestCase, t.Generic[AnyBaseAPIClient]):
"""Base API test case to be inherited by all other API test cases."""

client: AnyBaseAPIClient
client_class: t.Type[AnyBaseAPIClient]


class APITestCase(
BaseAPITestCase[APIClient[RequestUser]],
t.Generic[RequestUser],
):
"""Base API test case to be inherited by all other API test cases."""

client: APIClient[RequestUser]
client_class: t.Type[APIClient[RequestUser]] = APIClient
client_class = APIClient

@classmethod
def get_request_user_class(cls) -> t.Type[RequestUser]:
Expand Down
Loading

0 comments on commit 5b1d3bd

Please sign in to comment.