def test_load_custom_attr_convert(user_id: UserId) -> None: with Path(userdb.custom_attr_path(user_id, "a")).open("w") as f: f.write("xyz\n") assert (userdb.load_custom_attr(user_id, "a", conv_func=lambda x: "a" if x == "xyz" else "b") == "a")
def _get_sidebar_position() -> str: assert user.id is not None sidebar_position = userdb.load_custom_attr( user.id, "ui_sidebar_position", lambda x: None if x == "None" else "left") return sidebar_position or "right"
def _get_sidebar_position() -> str: assert config.user.id is not None sidebar_position = userdb.load_custom_attr( config.user.id, 'ui_sidebar_position', lambda x: None if x == "None" else "left") return _get_sidebar_position_title(sidebar_position or "right")
def _load_serial(username: UserId) -> int: """Load the password serial of the user This serial identifies the current config state of the user account. If either the password is changed or the account gets locked the serial is increased and all cookies get invalidated. Better use the value from the "serials.mk" file, instead of loading the whole user database via load_users() for performance reasons. """ return userdb.load_custom_attr(username, 'serial', int, 0)
def load_serial(username): return userdb.load_custom_attr(username, 'serial', int, 0)
def test_load_custom_attr_from_file(user_id: UserId) -> None: with Path(userdb.custom_attr_path(user_id, "a")).open("w") as f: f.write("xyz\n") assert userdb.load_custom_attr(user_id, "a", conv_func=str) == "xyz"
def test_load_custom_attr_not_existing_with_default(user_id: UserId) -> None: assert userdb.load_custom_attr(user_id, "a", conv_func=str, default="deflt") == "deflt"
def test_load_custom_attr_not_existing(user_id: UserId) -> None: assert userdb.load_custom_attr(user_id, "a", conv_func=str) is None
def test_load_custom_attr_not_existing_with_default(user_id: UserId) -> None: assert userdb.load_custom_attr(user_id=user_id, key="a", parser=str) is None