def test_unreturnable_variable_is_blank(self) -> None: assert (error( 200, None, # type: ignore False, )[0].json == jsonify({ "code": 200, "msg": "" }).json)
def check(self, data: Dict) -> Optional[HttpResponse]: if datetime.now() > (self.lastcall + timedelta(seconds=self.expires)): self.kill() elif self.session == data.get("session", ""): self.keepalive() return None return error( 401, render(self.shimon, "pages/login.jinja", msg="Session is no longer valid"), data["redirect"], True, )
def attempt_lock(self, pwd: str) -> Union[HttpResponse, Literal["fail"], None]: if not self.shimon.cache or self.shimon.cache.is_empty(): return error( 400, render(self.shimon, "pages/login.jinja", msg="Please re-open cache"), False, True, ) if self.shimon.cache["sha512"]: if self.shimon.security.correct_pwd(pwd): self.raw_lock(self.filepath, json.dumps(self.shimon.cache.export()), pwd) return None return "fail"
def lock(self, pwd: str) -> Optional[HttpResponse]: error_status = self.attempt_lock(pwd) if error_status == "fail": return error( 401, render( self.shimon, "pages/account.jinja", error="Cache could not be locked", version=self.shimon.VERSION, ), True, False, ) elif not error_status: return None return error_status
def test_json_is_jsonified(self) -> None: assert error(200, ["test3"], True)[0].json == jsonify(["test3"]).json
def test_custom_error_wrapper_is_same_when_called_directly(self) -> None: assert error_200("test")[0].json == error(200, "test", False)[0].json
def test_rethrow_param_causes_rethrow(self) -> None: assert error(200, "", False, True)[0].json == jsonify({ "rethrow": "" }).json