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


Python UserFactory.disable_account方法代码示例

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


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

示例1: TestHamUserRestore

# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import disable_account [as 别名]
class TestHamUserRestore(AdminTestCase):
    def setUp(self):
        self.user = UserFactory()
        self.request = RequestFactory().post('/fake_path')
        self.view = views.HamUserRestoreView
        self.view = setup_log_view(self.view, self.request, guid=self.user._id)

        self.spam_confirmed, created = Tag.objects.get_or_create(name='spam_confirmed')
        self.ham_confirmed, created = Tag.objects.get_or_create(name='ham_confirmed')

    def test_get_object(self):
        obj = self.view().get_object()
        nt.assert_is_instance(obj, OSFUser)

    def test_get_context(self):
        res = self.view().get_context_data(object=self.user)
        nt.assert_in('guid', res)
        nt.assert_equal(res.get('guid'), self.user._id)

    def test_enable_user(self):
        self.user.disable_account()
        self.user.save()
        nt.assert_true(self.user.is_disabled)
        self.view().delete(self.request)
        self.user.reload()

        nt.assert_false(self.user.is_disabled)
        nt.assert_false(self.user.all_tags.filter(name=self.spam_confirmed.name).exists())
        nt.assert_true(self.user.all_tags.filter(name=self.ham_confirmed.name).exists())
开发者ID:geeksnglitter,项目名称:osf.io,代码行数:31,代码来源:test_views.py

示例2: test_disabled_user_csl

# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import disable_account [as 别名]
 def test_disabled_user_csl(self):
     # Tests the csl name for a disabled user
     user = UserFactory()
     project = NodeFactory(creator=user)
     user.disable_account()
     user.is_registered = False
     user.save()
     assert bool(
         user.csl_name() ==
         {
             'given': user.csl_given_name,
             'family': user.family_name,
         }
     )
开发者ID:icereval,项目名称:osf.io,代码行数:16,代码来源:test_citations.py

示例3: TestForgotPassword

# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import disable_account [as 别名]
class TestForgotPassword(OsfTestCase):

    def setUp(self):
        super(TestForgotPassword, self).setUp()
        self.user = UserFactory()
        self.auth_user = AuthUserFactory()
        self.get_url = web_url_for('forgot_password_get')
        self.post_url = web_url_for('forgot_password_post')
        self.user.verification_key_v2 = {}
        self.user.save()

    # log users out before they land on forgot password page
    def test_forgot_password_logs_out_user(self):
        # visit forgot password link while another user is logged in
        res = self.app.get(self.get_url, auth=self.auth_user.auth)
        # check redirection to CAS logout
        assert_equal(res.status_code, 302)
        location = res.headers.get('Location')
        assert_not_in('reauth', location)
        assert_in('logout?service=', location)
        assert_in('forgotpassword', location)

    # test that forgot password page is loaded correctly
    def test_get_forgot_password(self):
        res = self.app.get(self.get_url)
        assert_equal(res.status_code, 200)
        assert_in('Forgot Password', res.body)
        assert_in('forgotPasswordForm', res.forms)

    # test that existing user can receive reset password email
    @mock.patch('framework.auth.views.mails.send_mail')
    def test_can_receive_reset_password_email(self, mock_send_mail):
        # load forgot password page and submit email
        res = self.app.get(self.get_url)
        form = res.forms['forgotPasswordForm']
        form['forgot_password-email'] = self.user.username
        res = form.submit()

        # check mail was sent
        assert_true(mock_send_mail.called)
        # check http 200 response
        assert_equal(res.status_code, 200)
        # check request URL is /forgotpassword
        assert_equal(res.request.path, self.post_url)
        # check push notification
        assert_in_html('If there is an OSF account', res)
        assert_not_in_html('Please wait', res)

        # check verification_key_v2 is set
        self.user.reload()
        assert_not_equal(self.user.verification_key_v2, {})

    # test that non-existing user cannot receive reset password email
    @mock.patch('framework.auth.views.mails.send_mail')
    def test_cannot_receive_reset_password_email(self, mock_send_mail):
        # load forgot password page and submit email
        res = self.app.get(self.get_url)
        form = res.forms['forgotPasswordForm']
        form['forgot_password-email'] = 'fake' + self.user.username
        res = form.submit()

        # check mail was not sent
        assert_false(mock_send_mail.called)
        # check http 200 response
        assert_equal(res.status_code, 200)
        # check request URL is /forgotpassword
        assert_equal(res.request.path, self.post_url)
        # check push notification
        assert_in_html('If there is an OSF account', res)
        assert_not_in_html('Please wait', res)

        # check verification_key_v2 is not set
        self.user.reload()
        assert_equal(self.user.verification_key_v2, {})

    # test that non-existing user cannot receive reset password email
    @mock.patch('framework.auth.views.mails.send_mail')
    def test_not_active_user_no_reset_password_email(self, mock_send_mail):
        self.user.disable_account()
        self.user.save()

        # load forgot password page and submit email
        res = self.app.get(self.get_url)
        form = res.forms['forgotPasswordForm']
        form['forgot_password-email'] = self.user.username
        res = form.submit()

        # check mail was not sent
        assert_false(mock_send_mail.called)
        # check http 200 response
        assert_equal(res.status_code, 200)
        # check request URL is /forgotpassword
        assert_equal(res.request.path, self.post_url)
        # check push notification
        assert_in_html('If there is an OSF account', res)
        assert_not_in_html('Please wait', res)

        # check verification_key_v2 is not set
        self.user.reload()
        assert_equal(self.user.verification_key_v2, {})
#.........这里部分代码省略.........
开发者ID:erinspace,项目名称:osf.io,代码行数:103,代码来源:test_webtests.py


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