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


Python user.UserApi类代码示例

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


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

示例1: test_unit__disable_user___err__user_cant_disable_itself

    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,代码行数:26,代码来源:test_user_api.py

示例2: test_api__reset_password_reset__ok_204__nominal_case

 def test_api__reset_password_reset__ok_204__nominal_case(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,
     )
     reset_password_token = uapi.reset_password_notification(admin, do_save=True)  # nopep8
     transaction.commit()
     params = {
         'email': '[email protected]',
         'reset_password_token': reset_password_token,
         'new_password': 'mynewpassword',
         'new_password2': 'mynewpassword',
     }
     self.testapp.post_json(
         '/api/v2/auth/password/reset/modify',
         status=204,
         params=params,
     )
     # check if password is correctly setted
     self.testapp.authorization = (
         'Basic',
         (
             '[email protected]',
             'mynewpassword'
         )
     )
     self.testapp.get(
         '/api/v2/auth/whoami',
         status=200,
     )
开发者ID:tracim,项目名称:tracim,代码行数:35,代码来源:test_reset_password.py

示例3: create_user

    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,代码行数:32,代码来源:user_controller.py

示例4: test_unit_update__ok_external_auth_ldap

 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,代码行数:27,代码来源:test_user_api.py

示例5: test_unit_update__err__external_auth_ldap_set_email

 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,代码行数:27,代码来源:test_user_api.py

示例6: test_api__reset_password_reset__err_400__expired_token

 def test_api__reset_password_reset__err_400__expired_token(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,
     )
     with freeze_time("1999-12-31 23:59:59"):
         reset_password_token = uapi.reset_password_notification(
             admin,
             do_save=True
         )
         params = {
             'email': '[email protected]',
             'reset_password_token': reset_password_token,
             'new_password': 'mynewpassword',
             'new_password2': 'mynewpassword',
         }
         transaction.commit()
     with freeze_time("2000-01-01 00:00:05"):
         res = self.testapp.post_json(
             '/api/v2/auth/password/reset/modify',
             status=400,
             params=params,
         )
         assert isinstance(res.json, dict)
         assert 'code' in res.json.keys()
         assert res.json_body['code'] == error.EXPIRED_RESET_PASSWORD_TOKEN  # nopep8
开发者ID:tracim,项目名称:tracim,代码行数:31,代码来源:test_reset_password.py

示例7: test_unit__authenticate_user___ok__new_user_ldap_auth_custom_profile

    def test_unit__authenticate_user___ok__new_user_ldap_auth_custom_profile(self):
        # TODO - G.M - 2018-12-05 - [ldap_profile]
        # support for profile attribute disabled
        # Should be reenabled later probably with a better code
        class fake_ldap_connector(object):

            def authenticate(self, email: str, password: str):
                if not email == '[email protected]' \
                        and password == 'professor':
                    return None
                return [None, {'mail': ['[email protected]'],
                               'givenName': ['Hubert'],
                               'profile': ['trusted-users'],
                               }]
        api = UserApi(
            current_user=None,
            session=self.session,
            config=self.app_config,
        )
        user = api.authenticate('[email protected]', 'professor', fake_ldap_connector())  # nopep8
        assert isinstance(user, User)
        assert user.email == '[email protected]'
        assert user.auth_type == AuthType.LDAP
        assert user.display_name == 'Hubert'
        assert user.profile.name == 'trusted-users'
开发者ID:tracim,项目名称:tracim,代码行数:25,代码来源:test_user_api.py

示例8: _authenticate_user

 def _authenticate_user(
     self,
     request: Request,
     email: typing.Optional[str],
     password: typing.Optional[str],
 ) -> typing.Optional[User]:
     """
     Helper to authenticate user in pyramid request
     from user email and password
     :param request: pyramid request
     :return: User or None
     """
     app_config = request.registry.settings['CFG']
     uapi = UserApi(None, session=request.dbsession, config=app_config)
     ldap_connector = None
     if AuthType.LDAP in app_config.AUTH_TYPES:
         ldap_connector = get_ldap_connector(request)
     try:
         user = uapi.authenticate(
             email=email,
             password=password,
             ldap_connector=ldap_connector
         )
         return user
     except AuthenticationFailed:
         return None
开发者ID:tracim,项目名称:tracim,代码行数:26,代码来源:authentification.py

示例9: test_func__create_user_with_mail_notification__ok__nominal_case

    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,代码行数:29,代码来源:test_daemons.py

示例10: test_api__reset_password_reset__err_400__password_does_not_match

 def test_api__reset_password_reset__err_400__password_does_not_match(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,
     )
     reset_password_token = uapi.reset_password_notification(admin, do_save=True)  # nopep8
     transaction.commit()
     params = {
         'email': '[email protected]min.admin',
         'reset_password_token': reset_password_token,
         'new_password': 'mynewpassword',
         'new_password2': 'anotherpassword',
     }
     res = self.testapp.post_json(
         '/api/v2/auth/password/reset/modify',
         status=400,
         params=params,
     )
     assert isinstance(res.json, dict)
     assert 'code' in res.json.keys()
     assert res.json_body['code'] == error.PASSWORD_DO_NOT_MATCH
开发者ID:tracim,项目名称:tracim,代码行数:26,代码来源:test_reset_password.py

示例11: test_func__reset_password__ok__nominal_case

 def test_func__reset_password__ok__nominal_case(self):
     uapi = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     current_user = uapi.get_one_by_email('[email protected]')
     uapi.reset_password_notification(current_user, do_save=True)
     transaction.commit()
     # Send mail async from redis queue
     redis = get_redis_connection(
         self.app_config
     )
     queue = get_rq_queue(
         redis,
         'mail_sender',
     )
     worker = SimpleWorker([queue], connection=queue.connection)
     worker.work(burst=True)
     # 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] == 'Global manager <[email protected]>'
     assert headers['Subject'][0] == '[TRACIM] A password reset has been requested'
开发者ID:tracim,项目名称:tracim,代码行数:25,代码来源:test_mail_notification.py

示例12: insert

    def insert(self):
        u = User()
        u.display_name = 'Global manager'
        u.email = '[email protected]'
        u.password = '[email protected]'
        self._session.add(u)
        uapi = UserApi(
            session=self._session,
            config=self._config,
            current_user=u)
        uapi.execute_created_user_actions(u)

        g1 = Group()
        g1.group_id = 1
        g1.group_name = 'users'
        g1.display_name = 'Users'
        g1.users.append(u)
        self._session.add(g1)

        g2 = Group()
        g2.group_id = 2
        g2.group_name = 'trusted-users'
        g2.display_name = 'Trusted Users'
        g2.users.append(u)
        self._session.add(g2)

        g3 = Group()
        g3.group_id = 3
        g3.group_name = 'administrators'
        g3.display_name = 'Administrators'
        g3.users.append(u)
        self._session.add(g3)
开发者ID:tracim,项目名称:tracim,代码行数:32,代码来源:users_and_groups.py

示例13: test_unit__authenticate_user___err__no_ldap_connector

 def test_unit__authenticate_user___err__no_ldap_connector(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     with pytest.raises(MissingLDAPConnector):
         user = api.authenticate('[email protected]', 'professor')
开发者ID:tracim,项目名称:tracim,代码行数:8,代码来源:test_user_api.py

示例14: test_unit__get_one_by_email__err__user_does_not_exist

 def test_unit__get_one_by_email__err__user_does_not_exist(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     with pytest.raises(UserDoesNotExist):
         api.get_one_by_email('unknown')
开发者ID:tracim,项目名称:tracim,代码行数:8,代码来源:test_user_api.py

示例15: test_unit__create_minimal_user__err__too_short_email

 def test_unit__create_minimal_user__err__too_short_email(self):
     api = UserApi(
         current_user=None,
         session=self.session,
         config=self.app_config,
     )
     with pytest.raises(TracimValidationFailed):
         u = api.create_minimal_user('[email protected]')
开发者ID:tracim,项目名称:tracim,代码行数:8,代码来源:test_user_api.py


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