Coverage for polar/customer_meter/schemas.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 12:42 +0000

1from typing import Annotated 

2 

3from fastapi import Path 

4from pydantic import UUID4, Field 

5 

6from polar.customer.schemas.customer import Customer 

7from polar.kit.schemas import ( 

8 CUSTOMER_ID_EXAMPLE, 

9 METER_ID_EXAMPLE, 

10 IDSchema, 

11 TimestampedSchema, 

12) 

13from polar.meter.schemas import Meter 

14 

15CustomerMeterID = Annotated[UUID4, Path(description="The customer meter ID.")] 

16 

17 

18class CustomerMeterBase(TimestampedSchema, IDSchema): 

19 customer_id: UUID4 = Field( 

20 description="The ID of the customer.", examples=[CUSTOMER_ID_EXAMPLE] 

21 ) 

22 meter_id: UUID4 = Field( 

23 description="The ID of the meter.", examples=[METER_ID_EXAMPLE] 

24 ) 

25 consumed_units: float = Field( 

26 description="The number of consumed units.", examples=[25.0] 

27 ) 

28 credited_units: int = Field( 

29 description="The number of credited units.", examples=[100] 

30 ) 

31 balance: float = Field( 

32 description=( 

33 "The balance of the meter, " 

34 "i.e. the difference between credited and consumed units." 

35 ), 

36 examples=[75.0], 

37 ) 

38 

39 

40class CustomerMeter(CustomerMeterBase): 

41 """An active customer meter, with current consumed and credited units.""" 

42 

43 customer: Customer = Field(description="The customer associated with this meter.") 

44 meter: Meter = Field(description="The meter associated with this customer.")