Coverage for fastid / oauth / repositories.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-18 16:37 +0000

1from typing import Any 

2 

3from fastid.database.repository import SQLAlchemyRepository 

4from fastid.database.specification import Specification 

5from fastid.database.utils import UUIDv7 

6from fastid.oauth.models import OAuthAccount, OAuthProvider 

7 

8 

9class OAuthAccountRepository(SQLAlchemyRepository[OAuthAccount]): 

10 model_type = OAuthAccount 

11 

12 

13class OAuthProviderRepository(SQLAlchemyRepository[OAuthProvider]): 

14 model_type = OAuthProvider 

15 

16 

17class OAuthProviderNameSpecification(Specification): 

18 def __init__(self, name: str) -> None: 

19 self.name = name 

20 

21 def apply(self, stmt: Any) -> Any: 

22 return stmt.where(OAuthProvider.name == self.name) 

23 

24 

25class UserAccountSpecification(Specification): 

26 def __init__(self, user_id: UUIDv7, provider: str) -> None: 

27 self.user_id = user_id 

28 self.provider = provider 

29 

30 def apply(self, stmt: Any) -> Any: 

31 return stmt.where( 

32 OAuthAccount.user_id == self.user_id, 

33 OAuthAccount.provider == self.provider, 

34 ) 

35 

36 

37class UserAccountPageSpecification(Specification): 

38 def __init__(self, user_id: UUIDv7) -> None: 

39 self.user_id = user_id 

40 

41 def apply(self, stmt: Any) -> Any: 

42 return stmt.where(OAuthAccount.user_id == self.user_id) 

43 

44 

45class ProviderAccountSpecification(Specification): 

46 def __init__(self, provider: str, account_id: str) -> None: 

47 self.account_id = account_id 

48 self.provider = provider 

49 

50 def apply(self, stmt: Any) -> Any: 

51 return stmt.where( 

52 OAuthAccount.provider == self.provider, 

53 OAuthAccount.account_id == self.account_id, 

54 )