当前位置: 首页>>代码示例>>Python>>正文


Python UserApi.create_user方法代码示例

本文整理汇总了Python中tracim_backend.lib.core.user.UserApi.create_user方法的典型用法代码示例。如果您正苦于以下问题:Python UserApi.create_user方法的具体用法?Python UserApi.create_user怎么用?Python UserApi.create_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tracim_backend.lib.core.user.UserApi的用法示例。


在下文中一共展示了UserApi.create_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_unit__get_known__user__distinct_workspaces_users_by_name__exclude_workspace

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
 def test_unit__get_known__user__distinct_workspaces_users_by_name__exclude_workspace(self):
     admin = self.session.query(User) \
         .filter(User.email == '[email protected]') \
         .one()
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     u1 = api.create_user(
         email='[email protected]',
         name='name',
         do_notify=False,
         do_save=True,
     )
     u2 = api.create_user(
         email='[email protected]',
         name='name2',
         do_notify=False,
         do_save=True,
     )
     u3 = api.create_user(
         email='[email protected]',
         name='notfound',
         do_notify=False,
         do_save=True,
     )
     wapi = WorkspaceApi(
         current_user=admin,
         session=self.session,
         config=self.app_config,
     )
     workspace = wapi.create_workspace(
         'test workspace n°1',
         save_now=True)
     wapi = WorkspaceApi(
         current_user=admin,
         session=self.session,
         config=self.app_config,
     )
     workspace_2 = wapi.create_workspace(
         'test workspace n°2',
         save_now=True)
     role_api = RoleApi(
         current_user=admin,
         session=self.session,
         config=self.app_config,
     )
     role_api.create_one(u1, workspace, UserRoleInWorkspace.READER, False)
     role_api.create_one(u2, workspace_2, UserRoleInWorkspace.READER, False)
     role_api.create_one(u3, workspace, UserRoleInWorkspace.READER, False)
     role_api.create_one(u3, workspace_2, UserRoleInWorkspace.READER, False)
     api2 = UserApi(
         current_user=u3,
         session=self.session,
         config=self.app_config,
     )
     users = api2.get_known_user('name', exclude_workspace_ids=[workspace.workspace_id])
     assert len(users) == 1
     assert users[0] == u2
开发者ID:tracim,项目名称:tracim,代码行数:62,代码来源:test_user_api.py

示例2: test__unit__get_notifiable_roles__ok__do_not_show_inactive

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
    def test__unit__get_notifiable_roles__ok__do_not_show_inactive(self):
        admin = self.session.query(User) \
            .filter(User.email == '[email protected]').one()
        wapi = WorkspaceApi(
            session=self.session,
            config=self.app_config,
            current_user=admin,
        )
        workspace = wapi.create_workspace(label='workspace w',
                                          save_now=True)
        uapi = UserApi(
            session=self.session,
            current_user=admin,
            config=self.app_config
        )
        user_1 = uapi.create_user(
            email='[email protected]',
            auth_type=AuthType.INTERNAL,
            do_save=True,
            do_notify=False
        )
        user_2 = uapi.create_user(
            email='[email protected]',
            auth_type=AuthType.INTERNAL,
            do_save=True,
            do_notify = False
        )
        assert wapi.get_notifiable_roles(workspace=workspace) == []

        rapi = RoleApi(
            session=self.session,
            current_user=admin,
            config=self.app_config,
        )
        role_1 = rapi.create_one(
            user_1,
            workspace,
            UserRoleInWorkspace.READER,
            with_notif=True
        )
        role_2 = rapi.create_one(
            user_2,
            workspace,
            UserRoleInWorkspace.READER,
            with_notif=True
        )

        assert role_1 in wapi.get_notifiable_roles(workspace=workspace)
        assert role_2 in wapi.get_notifiable_roles(workspace=workspace)

        user_1.is_active = False
        assert not role_1 in wapi.get_notifiable_roles(workspace=workspace)
        assert role_2 in wapi.get_notifiable_roles(workspace=workspace)
开发者ID:tracim,项目名称:tracim,代码行数:55,代码来源:test_workspace.py

示例3: test_unit_update__err__external_auth_ldap_set_email

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
 def test_unit_update__err__external_auth_ldap_set_email(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     u = api.create_user(
         email='[email protected]',
         password=None,
         name='bob',
         auth_type=AuthType.LDAP,
         timezone='+2',
         lang='en',
         do_save=True,
         do_notify=False,
     )
     with pytest.raises(ExternalAuthUserEmailModificationDisallowed):
         api.update(
             email='[email protected]',
             user = u,
             name='bobi',
             password=None,
             auth_type=AuthType.LDAP,
             timezone='-1',
             lang='fr',
             do_save=True,
         )
开发者ID:tracim,项目名称:tracim,代码行数:29,代码来源:test_user_api.py

示例4: create_user

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
    def create_user(self, context, request: TracimRequest, hapic_data=None):
        """
        Create new user
        """
        app_config = request.registry.settings['CFG']
        uapi = UserApi(
            current_user=request.current_user,  # User
            session=request.dbsession,
            config=app_config,
        )
        gapi = GroupApi(
            current_user=request.current_user,  # User
            session=request.dbsession,
            config=app_config,
        )
        groups = [gapi.get_one_with_name(hapic_data.body.profile)]
        password = hapic_data.body.password
        if not password and hapic_data.body.email_notification:
            password = password_generator()

        user = uapi.create_user(
            auth_type=AuthType.UNKNOWN,
            email=hapic_data.body.email,
            password=password,
            timezone=hapic_data.body.timezone,
            lang=hapic_data.body.lang,
            name=hapic_data.body.public_name,
            do_notify=hapic_data.body.email_notification,
            groups=groups,
            do_save=True
        )
        return uapi.get_user_with_context(user)
开发者ID:tracim,项目名称:tracim,代码行数:34,代码来源:user_controller.py

示例5: 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 create_user [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)
开发者ID:tracim,项目名称:tracim,代码行数:28,代码来源:test_user_api.py

示例6: test_func__create_user_with_mail_notification__ok__nominal_case

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
    def test_func__create_user_with_mail_notification__ok__nominal_case(self):
        api = UserApi(
            current_user=None,
            session=self.session,
            config=self.app_config,
        )
        u = api.create_user(
            email='[email protected]',
            password='password',
            name='bob',
            timezone='+2',
            do_save=True,
            do_notify=True,
        )
        assert u is not None
        assert u.email == "[email protected]"
        assert u.validate_password('password')
        assert u.display_name == 'bob'
        assert u.timezone == '+2'

        # Send mail async from redis queue with daemon
        daemon = MailSenderDaemon(self.app_config, burst=True)
        daemon.run()
        # check mail received
        response = self.get_mailhog_mails()
        headers = response[0]['Content']['Headers']
        assert headers['From'][0] == 'Tracim Notifications <[email protected]>'  # nopep8
        assert headers['To'][0] == 'bob <[email protected]>'
        assert headers['Subject'][0] == '[TRACIM] Created account'
开发者ID:tracim,项目名称:tracim,代码行数:31,代码来源:test_daemons.py

示例7: test_unit_update__ok_external_auth_ldap

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
 def test_unit_update__ok_external_auth_ldap(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     u = api.create_user(
         email='[email protected]',
         password=None,
         name='bob',
         auth_type=AuthType.LDAP,
         timezone='+2',
         lang='en',
         do_save=True,
         do_notify=False,
     )
     api.update(
         email='[email protected]',
         user = u,
         name='bobi',
         password=None,
         auth_type=AuthType.LDAP,
         timezone='-1',
         lang='fr',
         do_save=True,
     )
     assert u.display_name == 'bobi'
开发者ID:tracim,项目名称:tracim,代码行数:29,代码来源:test_user_api.py

示例8: test_unit__disable_user___ok__nominal_case

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [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
开发者ID:tracim,项目名称:tracim,代码行数:40,代码来源:test_user_api.py

示例9: test_unit__get_known__user__admin__too_short_acp_str

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
 def test_unit__get_known__user__admin__too_short_acp_str(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     u1 = api.create_user(
         email='[email protected]',
         name='name',
         do_notify=False,
         do_save=True,
     )
     with pytest.raises(TooShortAutocompleteString):
         api.get_known_user('e')
开发者ID:tracim,项目名称:tracim,代码行数:16,代码来源:test_user_api.py

示例10: test_unit__get_known__user__admin__by_name

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
    def test_unit__get_known__user__admin__by_name(self):
        api = UserApi(
            current_user=None,
            session=self.session,
            config=self.app_config,
        )
        u1 = api.create_user(
            email='[email protected]',
            name='name',
            do_notify=False,
            do_save=True,
        )

        users = api.get_known_user('nam')
        assert len(users) == 1
        assert users[0] == u1
开发者ID:tracim,项目名称:tracim,代码行数:18,代码来源:test_user_api.py

示例11: test__unit__create_user__err__external_auth_ldap_with_password

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
 def test__unit__create_user__err__external_auth_ldap_with_password(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     with pytest.raises(ExternalAuthUserPasswordModificationDisallowed):
         u = api.create_user(
             email='[email protected]',
             password='password',
             name='bob',
             auth_type=AuthType.LDAP,
             timezone='+2',
             lang='en',
             do_save=True,
             do_notify=False,
         )
开发者ID:tracim,项目名称:tracim,代码行数:19,代码来源:test_user_api.py

示例12: 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 create_user [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()
开发者ID:tracim,项目名称:tracim,代码行数:46,代码来源:test_session.py

示例13: 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 create_user [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
开发者ID:tracim,项目名称:tracim,代码行数:43,代码来源:test_session.py

示例14: test__unit__create__user__ok_nominal_case

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
 def test__unit__create__user__ok_nominal_case(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     u = api.create_user(
         email='[email protected]',
         password='password',
         name='bob',
         timezone='+2',
         lang='en',
         do_save=True,
         do_notify=False,
     )
     assert u is not None
     assert u.email == "[email protected]"
     assert u.validate_password('password')
     assert u.display_name == 'bob'
     assert u.timezone == '+2'
     assert u.lang == 'en'
开发者ID:tracim,项目名称:tracim,代码行数:23,代码来源:test_user_api.py

示例15: test_unit__get_known__user__user__no_workspace_empty_known_user

# 需要导入模块: from tracim_backend.lib.core.user import UserApi [as 别名]
# 或者: from tracim_backend.lib.core.user.UserApi import create_user [as 别名]
 def test_unit__get_known__user__user__no_workspace_empty_known_user(self):
     admin = self.session.query(User) \
         .filter(User.email == '[email protected]') \
         .one()
     api = UserApi(
         current_user=admin,
         session=self.session,
         config=self.app_config,
     )
     u1 = api.create_user(
         email='[email protected]',
         name='name',
         do_notify=False,
         do_save=True,
     )
     api2 = UserApi(
         current_user=u1,
         session=self.session,
         config=self.app_config,
     )
     users = api2.get_known_user('email')
     assert len(users) == 0
开发者ID:tracim,项目名称:tracim,代码行数:24,代码来源:test_user_api.py


注:本文中的tracim_backend.lib.core.user.UserApi.create_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。