Coverage for postrfp/web/apps/buyer.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-22 21:34 +0000

1import logging 

2from typing import Callable 

3 

4import webob.exc 

5 

6from postrfp.web.base import WSGIApp 

7from postrfp.model.humans import OrganisationType 

8from postrfp.web.suxint import Sux 

9 

10log = logging.getLogger(__name__) 

11 

12 

13buyer_sux = Sux( 

14 "postrfp.buyer.api.endpoints", 

15 "postrfp.web.adaptors.core", 

16 api_name="PostRFP Buyer API", 

17) 

18 

19 

20class BuyerApp(WSGIApp): 

21 routes: dict[str, Callable] = {} 

22 

23 def validate_user(self, request) -> None: 

24 user = request.user 

25 if user.organisation.type not in ( 

26 OrganisationType.CONSULTANT, 

27 OrganisationType.BUYER, 

28 ): 

29 log.warning( 

30 "Denying access to %s for %s (Not Consulant or Buyer user)", 

31 request.url, 

32 user, 

33 ) 

34 raise webob.exc.HTTPUnauthorized("URL forbidden for Respondent users") 

35 

36 def build_sux(self) -> None: 

37 self.sux_instance = buyer_sux 

38 

39 

40@BuyerApp.route("/raise-check") 

41def raise_check(request) -> None: 

42 """Check exception handling""" 

43 raise Exception("Raised test exception to check exception handling")