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

14 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-11 02:25 +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.container import ( # type: ignore[import-untyped] 

9 ContainerResolverProtocol, 

10 ) 

11 

12 

13class AdminWebContributor: 

14 """Web contributor for the admin package. 

15 

16 Resolves and delegates to the AdminBundle's mount_to_app method 

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

18 the bundle handles all mounting. 

19 """ 

20 

21 @property 

22 def contributor_id(self) -> str: 

23 """Return unique identifier for this contributor. 

24 

25 Returns: 

26 The string "admin". 

27 """ 

28 return "admin" 

29 

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

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

32 

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

34 

35 Returns: 

36 Empty list. 

37 """ 

38 return [] 

39 

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

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

42 

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

44 

45 Returns: 

46 Empty list. 

47 """ 

48 return [] 

49 

50 async def mount_to_app( 

51 self, app: Any, container: ContainerResolverProtocol 

52 ) -> None: 

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

54 

55 Resolves the admin_bundle service (bypassing visibility checks) 

56 and delegates to its mount_to_app method if available. 

57 

58 Args: 

59 app: The ASGI application (typically Starlette). 

60 container: DI container for resolving the admin bundle. 

61 """ 

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

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

64 await admin_bundle.mount_to_app(app, container)