Coverage for api/docs/oauth2_docs.py: 100%
7 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 06:14 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 06:14 +0000
1from rest_framework.exceptions import (
2 APIException,
3 NotAuthenticated,
4 ValidationError,
5)
7from api.docs.base_docs import custom_extend_schema
8from api.examples import (
9 auth_key_info_200_example,
10 auth_key_info_curl,
11 auth_register_201_example,
12 auth_register_curl,
13 auth_token_200_example,
14 auth_token_curl,
15)
16from api.serializers.oauth2_serializers import (
17 OAuth2ApplicationSerializer,
18 OAuth2KeyInfoSerializer,
19 OAuth2RegistrationSerializer,
20 OAuth2TokenRequestSerializer,
21 OAuth2TokenSerializer,
22)
25register = custom_extend_schema(
26 operation_id="register",
27 request=OAuth2RegistrationSerializer,
28 res={
29 201: (OAuth2ApplicationSerializer, auth_register_201_example),
30 400: (ValidationError, None),
31 401: ({"type": "object", "properties": {"error": {"type": "string"}}}, None),
32 429: (
33 APIException("Request was throttled. Expected available in 1 second.", 429),
34 None,
35 ),
36 },
37 eg=[auth_register_curl],
38)
40key_info = custom_extend_schema(
41 operation_id="key_info",
42 res={
43 200: (OAuth2KeyInfoSerializer, auth_key_info_200_example),
44 401: (NotAuthenticated, None),
45 429: (
46 APIException("Request was throttled. Expected available in 1 second.", 429),
47 None,
48 ),
49 500: (APIException, None),
50 },
51 eg=[auth_key_info_curl],
52)
54token = custom_extend_schema(
55 operation_id="token",
56 request={"application/x-www-form-urlencoded": OAuth2TokenRequestSerializer},
57 res={
58 200: (OAuth2TokenSerializer, auth_token_200_example),
59 401: (NotAuthenticated, None),
60 400: (APIException("Invalid credentials", 400), None),
61 },
62 eg=[auth_token_curl],
63)