Coverage for rfpy/buyer/webapp.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-24 10:52 +0000

1import logging 

2from typing import Callable 

3 

4import webob.exc 

5 

6from rfpy.web.base import WSGIApp 

7from rfpy.model.humans import OrganisationType 

8from rfpy.suxint import Sux 

9 

10log = logging.getLogger(__name__) 

11 

12 

13buyer_sux = Sux("rfpy.api.endpoints", "rfpy.adaptors", api_name="PostRFP Buyer API") 

14 

15 

16class BuyerApp(WSGIApp): 

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

18 

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

20 user = request.user 

21 if user.organisation.type not in ( 

22 OrganisationType.CONSULTANT, 

23 OrganisationType.BUYER, 

24 ): 

25 log.warning( 

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

27 request.url, 

28 user, 

29 ) 

30 raise webob.exc.HTTPForbidden("URL forbidden for Respondent users") 

31 

32 def build_sux(self) -> None: 

33 self.sux_instance = buyer_sux 

34 

35 

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

37def raise_check(request) -> None: 

38 """Check exception handling""" 

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