Coverage for src/kwai/modules/club/domain/value_objects.py: 94%

35 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module for defining value objects for the members module.""" 

2 

3from dataclasses import dataclass 

4from enum import Enum 

5 

6from kwai.core.domain.value_objects.date import Date 

7from kwai.modules.club.domain.country import CountryEntity 

8 

9 

10@dataclass(kw_only=True, frozen=True, slots=True) 

11class License: 

12 """A license of a member.""" 

13 

14 number: str 

15 end_date: Date 

16 

17 @property 

18 def expired(self): 

19 """Is this license expired?""" 

20 return self.end_date.past 

21 

22 def __str__(self) -> str: 

23 """Return a string representation of a license.""" 

24 return self.number 

25 

26 

27class Gender(Enum): 

28 """The gender of a person.""" 

29 

30 UNKNOWN = 0 

31 MALE = 1 

32 FEMALE = 2 

33 

34 

35@dataclass(frozen=True, slots=True) 

36class Birthdate: 

37 """A birthdate of a person.""" 

38 

39 date: Date 

40 

41 @property 

42 def age(self) -> int: 

43 """Return the age on the current day.""" 

44 return self.date.get_age(self.date.today()) 

45 

46 def get_age_in_year(self, year: int) -> int: 

47 """Return the age that will be reached in the given year.""" 

48 date = Date.create(year, 12, 31) 

49 return self.date.get_age(date) 

50 

51 def __str__(self) -> str: 

52 """Return a string representation of a birthdate.""" 

53 return str(self.date) 

54 

55 

56@dataclass(kw_only=True, frozen=True, slots=True) 

57class Address: 

58 """An address.""" 

59 

60 address: str 

61 postal_code: str 

62 city: str 

63 county: str 

64 country: CountryEntity