Coverage for postrfp / web / mounts.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-12-03 01:35 +0000

1from postrfp import conf 

2 

3from postrfp.web.hooks import WebhookApp 

4from .apps import ( 

5 TokenAuthenticationApp, 

6 BuyerApp, 

7 VendorApp, 

8 FsmApp, 

9 RefApp, 

10 InternalApp, 

11) 

12 

13 

14def build_app_mounts(session_factory, auth_policies: dict) -> dict: 

15 """Build WSGI application mount dictionary from configuration. 

16 

17 Args: 

18 session_factory: SQLAlchemy session factory 

19 auth_policies: Dict mapping app types to auth policy instances 

20 

21 Returns: 

22 Dict mapping paths to WSGI app instances 

23 """ 

24 if conf.CONF is None: 

25 raise Exception( 

26 "--!!--postrfp not configured. Call utils.configure_postrfp()--" 

27 ) 

28 

29 # Define app configurations: (path_attr, app_class, auth_policy_key) 

30 app_configs = [ 

31 ("app_path_auth", TokenAuthenticationApp, "auth"), 

32 ("app_path_hooks", WebhookApp, "hooks"), 

33 ("app_path_buyer", BuyerApp, "buyer"), 

34 ("app_path_vendor", VendorApp, "vendor"), 

35 ("app_path_fsm", FsmApp, "fsm"), 

36 ("app_path_ref", RefApp, "ref"), 

37 ("app_path_internal", InternalApp, "internal"), 

38 ] 

39 

40 mounts = {} 

41 

42 for path_attr, app_class, auth_key in app_configs: 

43 path = getattr(conf.CONF, path_attr) 

44 if path is not None: 

45 app_instance = app_class( 

46 session_factory=session_factory, auth_policy=auth_policies.get(auth_key) 

47 ) 

48 mounts[path] = app_instance 

49 

50 return mounts