Coverage for api/serializers/oauth2_serializers.py: 100%
34 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 import serializers
3from oauth2_provider.models import Application
5from api.models import OAuth2Registration
8class OAuth2RegistrationSerializer(serializers.ModelSerializer):
9 class Meta:
10 model = OAuth2Registration
11 fields = ("name", "description", "email")
12 extra_kwargs = {
13 "name": {
14 "help_text": (
15 "A unique human-readable name for your application or project. "
16 "This name must be unique across all registered Openverse API "
17 "applications."
18 )
19 },
20 "description": {
21 "help_text": (
22 "A description of what you are trying to achieve with your "
23 "project using the API. Please provide as much detail as possible."
24 )
25 },
26 "email": {
27 "help_text": (
28 "A valid email address that Openverse can use to contact you about "
29 "your use case or data consumption."
30 )
31 },
32 }
35class OAuth2ApplicationSerializer(serializers.Serializer):
36 client_id = serializers.CharField(
37 help_text="The unique, public identifier of your application.",
38 )
39 client_secret = serializers.CharField(
40 help_text="The secret key used to authenticate your application.",
41 )
42 name = serializers.CharField(
43 help_text="The name of your application or project.",
44 )
45 msg = serializers.CharField(
46 help_text="Some additional information about the application.",
47 )
50class OAuth2RegistrationSuccessful(serializers.ModelSerializer):
51 name = serializers.CharField(
52 help_text="A unique human-readable name for your application "
53 "or project requiring access to the Openverse API."
54 )
55 client_id = serializers.CharField(
56 help_text="A publicly exposed string used by Openverse API "
57 "to identify the application."
58 )
59 client_secret = serializers.CharField(
60 help_text="A private string that authenticates the identity "
61 "of the application to the Openverse API."
62 )
64 class Meta:
65 model = Application
66 fields = ("name", "client_id", "client_secret")
69class OAuth2KeyInfoSerializer(serializers.Serializer):
70 requests_this_minute = serializers.IntegerField(
71 help_text="The number of requests your key has performed in the last minute.",
72 allow_null=True,
73 )
74 requests_today = serializers.IntegerField(
75 help_text="The number of requests your key has performed in the last day.",
76 allow_null=True,
77 )
78 rate_limit_model = serializers.CharField(
79 help_text="The type of rate limit applied to your key. Can be "
80 "'standard' or 'enhanced'; enhanced users enjoy higher rate "
81 "limits than their standard key counterparts. Contact "
82 "Openverse if you need a higher rate limit."
83 )
84 verified = serializers.BooleanField(
85 help_text="Whether the application has verified the submitted email address."
86 )
89class OAuth2TokenRequestSerializer(serializers.Serializer):
90 """
91 Serializes a request for an access token.
93 This is a dummy serializer for OpenAPI and is not actually used.
94 """
96 client_id = serializers.CharField(
97 help_text="The unique, public identifier of your application.",
98 )
100 client_secret = serializers.CharField(
101 help_text="The secret key used to authenticate your application.",
102 )
104 grant_type = serializers.ChoiceField(choices=["client_credentials"])
107class OAuth2TokenSerializer(serializers.Serializer):
108 """
109 Serializes the response for an access token.
111 This is a dummy serializer for OpenAPI and is not actually used.
112 """
114 access_token = serializers.CharField(
115 help_text="The access token that can be used to authenticate requests.",
116 )
117 token_type = serializers.CharField(
118 help_text="The type of token. This will always be 'Bearer'.",
119 )
120 expires_in = serializers.IntegerField(
121 help_text="The number of seconds until the token expires.",
122 )
123 scope = serializers.CharField(
124 help_text="The scope of the token.",
125 )