示例#1
0
 def wrapper(*args, **kwargs):
     token = kwargs.get('authorization')
     if not token:
         return JSONResponse(status_code=403, content="Forbidden")
     identity = RequestScope(authorization=token)
     if highest_role(identity._roles()) < role:
         return JSONResponse(status_code=403, content="Forbidden")
     return func(*args, **kwargs)
    def test_from_request(self, auth):
        request = Mock()
        request.headers = MockHeaders(auth=auth,
                                      locale='en',
                                      header={'aa': '1234'})

        req_scope = RequestScope.from_request(request)

        assert req_scope.localization() == 'en'
        assert req_scope.trace_header() == {'aa': '1234'}
 def get_identity(self, request):
     """Get the identity of the logged user"""
     try:
         return RequestScope.from_request(request)
     except ValueError:
         self.bad_request({"jwt": "invalid"})
    def test_trace_header_none(self, auth):
        req_scope = RequestScope(authorization=auth)

        trace_header = req_scope.trace_header()

        assert trace_header == {}
    def test_trace_header(self, auth):
        req_scope = RequestScope(authorization=auth, trace={'aa': 'bb'})

        trace_header = req_scope.trace_header()

        assert trace_header == {'aa': 'bb'}
    def test_localization_none(self, auth):
        req_scope = RequestScope(authorization=auth)

        localization = req_scope.localization()

        assert localization == 'ja'
    def test_localization(self, auth):
        req_scope = RequestScope(authorization=auth, accept_language='en')

        localization = req_scope.localization()

        assert localization == 'en'