本文整理汇总了Python中tracim_backend.lib.core.user.UserApi.disable方法的典型用法代码示例。如果您正苦于以下问题:Python UserApi.disable方法的具体用法?Python UserApi.disable怎么用?Python UserApi.disable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim_backend.lib.core.user.UserApi
的用法示例。
在下文中一共展示了UserApi.disable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unit__disable_user___err__user_cant_disable_itself
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import disable [as 别名]
def test_unit__disable_user___err__user_cant_disable_itself(self):
api = UserApi(
current_user=None,
session=self.session,
config=self.app_config,
)
gapi = GroupApi(
current_user=None,
session=self.session,
config=self.app_config,
)
groups = [gapi.get_one_with_name('users')]
user = api.create_user(
email='[email protected]',
password='password',
name='bob',
groups=groups,
timezone='Europe/Paris',
do_save=True,
do_notify=False,
)
api2 = UserApi(current_user=user,session=self.session, config=self.app_config)
from tracim_backend.exceptions import UserCantDisableHimself
with pytest.raises(UserCantDisableHimself):
api2.disable(user)
示例2: disable_user
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import disable [as 别名]
def disable_user(self, context, request: TracimRequest, hapic_data=None):
"""
disable user
"""
app_config = request.registry.settings['CFG']
uapi = UserApi(
current_user=request.current_user, # User
session=request.dbsession,
config=app_config,
)
uapi.disable(user=request.candidate_user, do_save=True)
return
示例3: test_api__try_whoami_enpoint__err_401__user_is_not_active
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import disable [as 别名]
def test_api__try_whoami_enpoint__err_401__user_is_not_active(self):
dbsession = get_tm_session(self.session_factory, transaction.manager)
admin = dbsession.query(User) \
.filter(User.email == '[email protected]') \
.one()
uapi = UserApi(
current_user=admin,
session=dbsession,
config=self.app_config,
)
gapi = GroupApi(
current_user=admin,
session=dbsession,
config=self.app_config,
)
groups = [gapi.get_one_with_name('users')]
test_user = uapi.create_user(
email='[email protected]',
password='password',
name='bob',
groups=groups,
timezone='Europe/Paris',
lang='en',
do_save=True,
do_notify=False,
)
uapi.save(test_user)
uapi.disable(test_user)
transaction.commit()
self.testapp.authorization = (
'Basic',
(
'[email protected]',
'password'
)
)
res = self.testapp.get('/api/v2/auth/whoami', status=401)
assert isinstance(res.json, dict)
assert 'code' in res.json.keys()
# INFO - G.M - 2018-09-10 - Handled by marshmallow_schema
assert res.json_body['code'] is None
assert 'message' in res.json.keys()
assert 'details' in res.json.keys()
示例4: test_api__try_login_enpoint__err_401__user_not_activated
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import disable [as 别名]
def test_api__try_login_enpoint__err_401__user_not_activated(self):
dbsession = get_tm_session(self.session_factory, transaction.manager)
admin = dbsession.query(User) \
.filter(User.email == '[email protected]') \
.one()
uapi = UserApi(
current_user=admin,
session=dbsession,
config=self.app_config,
)
gapi = GroupApi(
current_user=admin,
session=dbsession,
config=self.app_config,
)
groups = [gapi.get_one_with_name('users')]
test_user = uapi.create_user(
email='[email protected]',
password='password',
name='bob',
groups=groups,
timezone='Europe/Paris',
do_save=True,
do_notify=False,
)
uapi.save(test_user)
uapi.disable(test_user)
transaction.commit()
params = {
'email': '[email protected]',
'password': '[email protected]',
}
res = self.testapp.post_json(
'/api/v2/auth/login',
params=params,
status=403,
)
assert res.json_body
assert 'code' in res.json_body
assert res.json_body['code'] == error.AUTHENTICATION_FAILED
示例5: test_unit__disable_user___ok__nominal_case
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import disable [as 别名]
def test_unit__disable_user___ok__nominal_case(self):
api = UserApi(
current_user=None,
session=self.session,
config=self.app_config,
)
gapi = GroupApi(
current_user=None,
session=self.session,
config=self.app_config,
)
groups = [gapi.get_one_with_name('users')]
user = api.create_user(
email='[email protected]',
password='password',
name='bob',
groups=groups,
timezone='Europe/Paris',
do_save=True,
do_notify=False,
)
user2 = api.create_user(
email='[email protected]',
password='password',
name='bob2',
groups=groups,
timezone='Europe/Paris',
do_save=True,
do_notify=False,
)
api2 = UserApi(current_user=user,session=self.session, config=self.app_config)
from tracim_backend.exceptions import UserCantDisableHimself
api2.disable(user2)
updated_user2 = api.get_one(user2.user_id)
assert updated_user2.is_active == False
assert updated_user2.user_id == user2.user_id
assert updated_user2.email == user2.email
示例6: test_unit__authenticate_user___err__user_not_active
# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import disable [as 别名]
def test_unit__authenticate_user___err__user_not_active(self):
api = UserApi(
current_user=None,
session=self.session,
config=self.app_config,
)
gapi = GroupApi(
current_user=None,
session=self.session,
config=self.app_config,
)
groups = [gapi.get_one_with_name('users')]
user = api.create_user(
email='[email protected]',
password='password',
name='bob',
groups=groups,
timezone='Europe/Paris',
do_save=True,
do_notify=False,
)
api.disable(user)
with pytest.raises(AuthenticationFailed):
api.authenticate('[email protected]', '[email protected]')