本文整理汇总了Python中tracim_backend.lib.core.user.UserApi.get_current_user方法的典型用法代码示例。如果您正苦于以下问题:Python UserApi.get_current_user方法的具体用法?Python UserApi.get_current_user怎么用?Python UserApi.get_current_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim_backend.lib.core.user.UserApi
的用法示例。
在下文中一共展示了UserApi.get_current_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unit__get_current_user__err__user_not_exist
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_current_user [as 别名]
def test_unit__get_current_user__err__user_not_exist(self):
api = UserApi(
current_user=None,
session=self.session,
config=self.app_config,
)
with pytest.raises(UserDoesNotExist):
api.get_current_user()
示例2: test_unit__get_current_user_ok__nominal_case
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_current_user [as 别名]
def test_unit__get_current_user_ok__nominal_case(self):
user = User(email='[email protected]')
api = UserApi(
current_user=user,
session=self.session,
config=self.app_config,
)
new_user = api.get_current_user()
assert isinstance(new_user, User)
assert user == new_user
示例3: whoami
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import get_current_user [as 别名]
def whoami(self, context, request: TracimRequest, hapic_data=None):
"""
Return current logged-in user.
If user is not authenticated or the session has expired, a 401 is returned.
This is the recommanded way to check if the user is already authenticated
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(
request.current_user,
session=request.dbsession,
config=app_config,
)
user = uapi.get_current_user() # User
return uapi.get_user_with_context(user)