def render(self, data, accepted_media_type=None, renderer_context=None): request = _get_request(renderer_context) if not data: return _default_not_found_response(renderer_context, request) name = data.get("internal_name") cache_key = f"{self.media_type}/{name}" if name else None logger.debug("generating report %s", cache_key) if cache_key and not DEBUG: cached = cache.get(cache_key) if cached: return cached params = load_params() # separate user specific parameter user_parameter = params.pop("user_specific", {}) username, _ = get_username_role(request) if username: params = {**params, **user_parameter.get(username, {})} data["version"] = params.get("version") result = self.apply(name, data, params) if cache_key: cache.set(cache_key, result) return result
def test_not_call_on_missing_token_gsadsid(request): def fake_get(url, params, **kwargs): raise Exception("should not be called") request.query_params = {} request.COOKIES = {} username, role = get_username_role(request, get=fake_get) assert username is None assert role is None
def test_get_username_and_role(request, response): # pylint: disable=W0613 def fake_get(url, params, **kwargs): response.text = GSAD_FAKE_RESPONSE return response request.query_params = dict(token="TOKEN") request.COOKIES = dict(GSAD_SID="GSAD_SID") username, role = get_username_role(request, get=fake_get) assert username == "admin" assert role == "Admin"
def test_return_none_on_missing_url(request): username, role = get_username_role(request, gsad_url=None) assert username is None assert role is None