Coverage for polar/customer_portal/schemas/benefit_grant.py: 97%
79 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
1from datetime import datetime 1a
2from typing import Annotated, Literal, TypedDict 1a
4from pydantic import UUID4, Discriminator, TypeAdapter 1a
6from polar.benefit.strategies.custom.properties import BenefitGrantCustomProperties 1a
7from polar.benefit.strategies.custom.schemas import BenefitCustomSubscriber 1a
8from polar.benefit.strategies.discord.properties import BenefitGrantDiscordProperties 1a
9from polar.benefit.strategies.discord.schemas import BenefitDiscordSubscriber 1a
10from polar.benefit.strategies.downloadables.properties import ( 1a
11 BenefitGrantDownloadablesProperties,
12)
13from polar.benefit.strategies.downloadables.schemas import ( 1a
14 BenefitDownloadablesSubscriber,
15)
16from polar.benefit.strategies.github_repository.properties import ( 1a
17 BenefitGrantGitHubRepositoryProperties,
18)
19from polar.benefit.strategies.github_repository.schemas import ( 1a
20 BenefitGitHubRepositorySubscriber,
21)
22from polar.benefit.strategies.license_keys.properties import ( 1a
23 BenefitGrantLicenseKeysProperties,
24)
25from polar.benefit.strategies.license_keys.schemas import BenefitLicenseKeysSubscriber 1a
26from polar.benefit.strategies.meter_credit.properties import ( 1a
27 BenefitGrantMeterCreditProperties,
28)
29from polar.benefit.strategies.meter_credit.schemas import BenefitMeterCreditSubscriber 1a
30from polar.kit.schemas import ( 1a
31 ClassName,
32 IDSchema,
33 MergeJSONSchema,
34 Schema,
35 SetSchemaReference,
36 TimestampedSchema,
37)
38from polar.models.benefit import BenefitType 1a
39from polar.models.customer import CustomerOAuthPlatform 1a
41from .customer import CustomerPortalCustomer 1a
44class CustomerBenefitGrantBase(IDSchema, TimestampedSchema): 1a
45 granted_at: datetime | None 1a
46 revoked_at: datetime | None 1a
47 customer_id: UUID4 1a
48 benefit_id: UUID4 1a
49 subscription_id: UUID4 | None 1a
50 order_id: UUID4 | None 1a
51 is_granted: bool 1a
52 is_revoked: bool 1a
55class CustomerBenefitGrantDiscord(CustomerBenefitGrantBase): 1a
56 customer: CustomerPortalCustomer 1a
57 benefit: BenefitDiscordSubscriber 1a
58 properties: BenefitGrantDiscordProperties 1a
61class CustomerBenefitGrantGitHubRepository(CustomerBenefitGrantBase): 1a
62 customer: CustomerPortalCustomer 1a
63 benefit: BenefitGitHubRepositorySubscriber 1a
64 properties: BenefitGrantGitHubRepositoryProperties 1a
67class CustomerBenefitGrantDownloadables(CustomerBenefitGrantBase): 1a
68 customer: CustomerPortalCustomer 1a
69 benefit: BenefitDownloadablesSubscriber 1a
70 properties: BenefitGrantDownloadablesProperties 1a
73class CustomerBenefitGrantLicenseKeys(CustomerBenefitGrantBase): 1a
74 customer: CustomerPortalCustomer 1a
75 benefit: BenefitLicenseKeysSubscriber 1a
76 properties: BenefitGrantLicenseKeysProperties 1a
79class CustomerBenefitGrantCustom(CustomerBenefitGrantBase): 1a
80 customer: CustomerPortalCustomer 1a
81 benefit: BenefitCustomSubscriber 1a
82 properties: BenefitGrantCustomProperties 1a
85class CustomerBenefitGrantMeterCredit(CustomerBenefitGrantBase): 1a
86 customer: CustomerPortalCustomer 1a
87 benefit: BenefitMeterCreditSubscriber 1a
88 properties: BenefitGrantMeterCreditProperties 1a
91CustomerBenefitGrant = Annotated[ 1a
92 CustomerBenefitGrantDiscord
93 | CustomerBenefitGrantGitHubRepository
94 | CustomerBenefitGrantDownloadables
95 | CustomerBenefitGrantLicenseKeys
96 | CustomerBenefitGrantCustom
97 | CustomerBenefitGrantMeterCredit,
98 SetSchemaReference("CustomerBenefitGrant"),
99 MergeJSONSchema({"title": "CustomerBenefitGrant"}),
100 ClassName("CustomerBenefitGrant"),
101]
102CustomerBenefitGrantAdapter: TypeAdapter[CustomerBenefitGrant] = TypeAdapter( 1a
103 CustomerBenefitGrant
104)
107class CustomerBenefitGrantUpdateBase(Schema): 1a
108 benefit_type: BenefitType 1a
111class CustomerBenefitGrantDiscordPropertiesUpdate(TypedDict): 1a
112 account_id: str | None 1a
115class CustomerBenefitGrantDiscordUpdate(CustomerBenefitGrantUpdateBase): 1a
116 benefit_type: Literal[BenefitType.discord] 1a
117 properties: CustomerBenefitGrantDiscordPropertiesUpdate 1a
119 def get_oauth_platform(self) -> Literal[CustomerOAuthPlatform.discord]: 1a
120 return CustomerOAuthPlatform.discord
123class CustomerBenefitGrantGitHubRepositoryPropertiesUpdate(TypedDict): 1a
124 account_id: str | None 1a
127class CustomerBenefitGrantGitHubRepositoryUpdate(CustomerBenefitGrantUpdateBase): 1a
128 benefit_type: Literal[BenefitType.github_repository] 1a
129 properties: CustomerBenefitGrantGitHubRepositoryPropertiesUpdate 1a
131 def get_oauth_platform(self) -> Literal[CustomerOAuthPlatform.github]: 1a
132 return CustomerOAuthPlatform.github
135class CustomerBenefitGrantDownloadablesUpdate(CustomerBenefitGrantUpdateBase): 1a
136 benefit_type: Literal[BenefitType.downloadables] 1a
139class CustomerBenefitGrantLicenseKeysUpdate(CustomerBenefitGrantUpdateBase): 1a
140 benefit_type: Literal[BenefitType.license_keys] 1a
143class CustomerBenefitGrantCustomUpdate(CustomerBenefitGrantUpdateBase): 1a
144 benefit_type: Literal[BenefitType.custom] 1a
147class CustomerBenefitGrantMeterCreditUpdate(CustomerBenefitGrantUpdateBase): 1a
148 benefit_type: Literal[BenefitType.meter_credit] 1a
151CustomerBenefitGrantUpdate = Annotated[ 1a
152 CustomerBenefitGrantDiscordUpdate
153 | CustomerBenefitGrantGitHubRepositoryUpdate
154 | CustomerBenefitGrantDownloadablesUpdate
155 | CustomerBenefitGrantLicenseKeysUpdate
156 | CustomerBenefitGrantCustomUpdate
157 | CustomerBenefitGrantMeterCreditUpdate,
158 SetSchemaReference("CustomerBenefitGrantUpdate"),
159 MergeJSONSchema({"title": "CustomerBenefitGrantUpdate"}),
160 Discriminator("benefit_type"),
161]