Coverage for src/lexigram/admin/web/contributor.py: 0%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-24 23:18 +0800

1"""Admin web contributor for route and middleware registration.""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING, Any 

6 

7if TYPE_CHECKING: 

8 from lexigram.contracts.core.di import ContainerResolverProtocol 

9 

10 

11class AdminWebContributor: 

12 """Web contributor for the admin package. 

13 

14 Resolves and delegates to the AdminBundle's mount_to_app method 

15 if available. Does not contribute controllers or middleware directly; 

16 the bundle handles all mounting. 

17 """ 

18 

19 @property 

20 def contributor_id(self) -> str: 

21 """Return unique identifier for this contributor. 

22 

23 Returns: 

24 The string "admin". 

25 """ 

26 return "admin" 

27 

28 def get_controllers(self) -> list[type[Any]]: 

29 """Return controllers contributed by the admin package. 

30 

31 Admin uses the bundle pattern and does not contribute controllers directly. 

32 

33 Returns: 

34 Empty list. 

35 """ 

36 return [] 

37 

38 def get_middleware(self) -> list[type[Any]]: 

39 """Return middleware contributed by the admin package. 

40 

41 Admin uses the bundle pattern and does not contribute middleware directly. 

42 

43 Returns: 

44 Empty list. 

45 """ 

46 return [] 

47 

48 async def mount_to_app( 

49 self, app: Any, container: ContainerResolverProtocol 

50 ) -> None: 

51 """Mount admin routes to the web application. 

52 

53 Resolves the admin_bundle service (bypassing visibility checks) 

54 and delegates to its mount_to_app method if available. 

55 

56 Args: 

57 app: The ASGI application (typically Starlette). 

58 container: DI container for resolving the admin bundle. 

59 """ 

60 admin_bundle = await container.resolve("admin_bundle", bypass_visibility=True) 

61 if admin_bundle and hasattr(admin_bundle, "mount_to_app"): 

62 await admin_bundle.mount_to_app(app, container)