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


Python tests.UserFactory类代码示例

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


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

示例1: test_delete_image_no_permission

 def test_delete_image_no_permission(self):
     """Can't delete an image without permission."""
     u = UserFactory(username='tagger')
     assert not u.has_perm('upload.delete_imageattachment')
     self.test_upload_image()
     im = ImageAttachment.objects.all()[0]
     self.client.login(username='tagger', password='testpass')
     r = self._make_post_request(args=[im.id])
     eq_(403, r.status_code)
     assert ImageAttachment.objects.exists()
开发者ID:akatsoulas,项目名称:kitsune,代码行数:10,代码来源:test_views.py

示例2: setUp

    def setUp(self):
        u = UserFactory()
        add_permission(u, Question, 'change_question')
        assert u.has_perm('questions.change_question')
        self.user = u

        p = ProductFactory()
        t = TopicFactory(product=p)

        q = QuestionFactory(product=p, topic=t)

        self.product = p
        self.topic = t
        self.question = q
开发者ID:Andisutra80,项目名称:kitsune,代码行数:14,代码来源:test_views.py

示例3: test_thread_is_reindexed_on_username_change

    def test_thread_is_reindexed_on_username_change(self):
        search = ThreadMappingType.search()

        u = UserFactory(username='dexter')
        ThreadFactory(creator=u, title=u'Hello')

        self.refresh()
        eq_(search.query(post_title='hello')[0]['post_author_ord'], [u'dexter'])

        # Change the username and verify the index.
        u.username = 'walter'
        u.save()
        self.refresh()
        eq_(search.query(post_title='hello')[0]['post_author_ord'], [u'walter'])
开发者ID:1234-,项目名称:kitsune,代码行数:14,代码来源:test_es.py

示例4: setUp

 def setUp(self):
     super(PasswordResetTests, self).setUp()
     self.u = UserFactory(email="[email protected]")
     self.uidb36 = int_to_base36(self.u.id)
     self.token = default_token_generator.make_token(self.u)
     self.orig_debug = settings.DEBUG
     settings.DEBUG = True
开发者ID:1234-,项目名称:kitsune,代码行数:7,代码来源:test_templates.py

示例5: test_deactivate_button

    def test_deactivate_button(self):
        """Check that the deactivate button is shown appropriately"""
        u = UserFactory()
        r = self.client.get(reverse('users.profile', args=[u.username]))
        assert 'Deactivate this user' not in r.content

        add_permission(self.u, Profile, 'deactivate_users')
        self.client.login(username=self.u.username, password='testpass')
        r = self.client.get(reverse('users.profile', args=[u.username]))
        assert 'Deactivate this user' in r.content

        u.is_active = False
        u.save()
        r = self.client.get(reverse('users.profile', args=[u.username]))
        assert 'This user has been deactivated.' in r.content

        r = self.client.get(reverse('users.profile', args=[self.u.username]))
        assert 'Deactivate this user' not in r.content
开发者ID:1234-,项目名称:kitsune,代码行数:18,代码来源:test_templates.py

示例6: test_aaq_new_question_inactive

    def test_aaq_new_question_inactive(self, get_current):
        """New question is posted through mobile."""
        get_current.return_value.domain = 'testserver'

        # Log in first.
        u = UserFactory()
        self.client.login(username=u.username, password='testpass')

        # Then become inactive.
        u.is_active = False
        u.save()

        # Set 'in-aaq' for the session. It isn't already set because this
        # test doesn't do a GET of the form first.
        s = self.client.session
        s['in-aaq'] = True
        s.save()

        response = self._new_question(post_it=True)
        eq_(200, response.status_code)
        assert template_used(response, 'questions/mobile/confirm_email.html')
开发者ID:1234-,项目名称:kitsune,代码行数:21,代码来源:test_views.py

示例7: test_questions_inactive_user

    def test_questions_inactive_user(self):
        """Verify questions from inactive users aren't counted."""
        # Two questions for an inactive user.
        # They shouldn't show up in the count.
        u = UserFactory(is_active=False)
        QuestionFactory(creator=u)
        QuestionFactory(creator=u)

        r = self._get_api_result('api.kpi.questions')
        eq_(len(r['objects']), 0)

        # Activate the user, now the questions should count.
        u.is_active = True
        u.save()
        cache.clear()  # We need to clear the cache for new results.

        url = reverse('api.kpi.questions')
        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['questions'], 2)
开发者ID:1234-,项目名称:kitsune,代码行数:21,代码来源:test_api.py

示例8: test_question_is_reindexed_on_username_change

    def test_question_is_reindexed_on_username_change(self):
        search = QuestionMappingType.search()

        u = UserFactory(username='dexter')

        QuestionFactory(creator=u, title=u'Hello')
        AnswerFactory(creator=u, content=u'I love you')
        self.refresh()
        eq_(search.query(question_title__match='hello')[0]['question_creator'],
            u'dexter')
        query = search.query(question_answer_content__match='love')
        eq_(query[0]['question_answer_creator'],
            [u'dexter'])

        # Change the username and verify the index.
        u.username = 'walter'
        u.save()
        self.refresh()
        eq_(search.query(question_title__match='hello')[0]['question_creator'],
            u'walter')
        query = search.query(question_answer_content__match='love')
        eq_(query[0]['question_answer_creator'], [u'walter'])
开发者ID:1234-,项目名称:kitsune,代码行数:22,代码来源:test_es.py

示例9: PasswordChangeTests

class PasswordChangeTests(TestCaseBase):

    def setUp(self):
        super(PasswordChangeTests, self).setUp()
        self.u = UserFactory()
        self.url = reverse('users.pw_change')
        self.new_pw = 'fjdka387fvstrongpassword!'
        self.client.login(username=self.u.username, password='testpass')

    def test_change_password(self):
        assert self.u.check_password(self.new_pw) is False

        r = self.client.post(self.url, {'old_password': 'testpass',
                                        'new_password1': self.new_pw,
                                        'new_password2': self.new_pw})
        eq_(302, r.status_code)
        eq_('http://testserver/en-US/users/pwchangecomplete', r['location'])
        self.u = User.objects.get(username=self.u.username)
        assert self.u.check_password(self.new_pw)

    def test_bad_old_password(self):
        r = self.client.post(self.url, {'old_password': 'testpqss',
                                        'new_password1': self.new_pw,
                                        'new_password2': self.new_pw})
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_('Your old password was entered incorrectly. Please enter it '
            'again.', doc('ul.errorlist').text())

    def test_new_pw_doesnt_match(self):
        r = self.client.post(self.url, {'old_password': 'testpqss',
                                        'new_password1': self.new_pw,
                                        'new_password2': self.new_pw + '1'})
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_("The two password fields didn't match. Your old password was "
            "entered incorrectly. Please enter it again.",
            doc('ul.errorlist').text())
开发者ID:1234-,项目名称:kitsune,代码行数:38,代码来源:test_templates.py

示例10: test_send_message

    def test_send_message(self):
        to = UserFactory.create_batch(2)
        sender = UserFactory()
        msg_text = "hi there!"
        send_message(to=to, text=msg_text, sender=sender)

        msgs_in = InboxMessage.objects.all()
        msgs_out = OutboxMessage.objects.all()
        eq_(1, msgs_out.count())
        msg_out = msgs_out[0]
        eq_(sender, msg_out.sender)
        eq_(msg_text, msg_out.message)
        for u in msg_out.to.all():
            assert u in to
        eq_(2, msgs_in.count())
        for message in msgs_in:
            eq_(sender, message.sender)
            assert message.to in to
            eq_(msg_text, message.message)
开发者ID:1234-,项目名称:kitsune,代码行数:19,代码来源:test_internal_api.py

示例11: setUp

 def setUp(self):
     self.user = UserFactory()
     self.client.login(username=self.user.username, password='testpass')
     super(ChangeEmailTestCase, self).setUp()
开发者ID:1234-,项目名称:kitsune,代码行数:4,代码来源:test_views.py

示例12: UserProfileTests

class UserProfileTests(TestCase):
    def setUp(self):
        self.user = UserFactory()
        self.profile = self.user.profile
        self.userrl = reverse('users.profile', args=[self.user.username], locale='en-US')
        super(UserProfileTests, self).setUp()

    def test_ProfileFactory(self):
        res = self.client.get(self.userrl)
        self.assertContains(res, self.user.username)

    def test_profile_redirect(self):
        """Ensure that old profile URL's get redirected."""
        res = self.client.get(reverse('users.profile', args=[self.user.pk],
                                      locale='en-US'))
        eq_(302, res.status_code)

    def test_profile_inactive(self):
        """Inactive users don't have a public profile."""
        self.user.is_active = False
        self.user.save()
        res = self.client.get(self.userrl)
        eq_(404, res.status_code)

    def test_profile_post(self):
        res = self.client.post(self.userrl)
        eq_(405, res.status_code)

    def test_profile_deactivate(self):
        """Test user deactivation"""
        p = UserFactory().profile

        self.client.login(username=self.user.username, password='testpass')
        res = self.client.post(reverse('users.deactivate', locale='en-US'), {'user_id': p.user.id})

        eq_(403, res.status_code)

        add_permission(self.user, Profile, 'deactivate_users')
        res = self.client.post(reverse('users.deactivate', locale='en-US'), {'user_id': p.user.id})

        eq_(302, res.status_code)

        log = Deactivation.objects.get(user_id=p.user_id)
        eq_(log.moderator_id, self.user.id)

        p = Profile.objects.get(user_id=p.user_id)
        assert not p.user.is_active

    def test_deactivate_and_flag_spam(self):
        self.client.login(username=self.user.username, password='testpass')
        add_permission(self.user, Profile, 'deactivate_users')

        # Verify content is flagged as spam when requested.
        u = UserFactory()
        AnswerFactory(creator=u)
        QuestionFactory(creator=u)
        url = reverse('users.deactivate-spam', locale='en-US')
        res = self.client.post(url, {'user_id': u.id})

        eq_(302, res.status_code)
        eq_(1, Question.objects.filter(creator=u, is_spam=True).count())
        eq_(0, Question.objects.filter(creator=u, is_spam=False).count())
        eq_(1, Answer.objects.filter(creator=u, is_spam=True).count())
        eq_(0, Answer.objects.filter(creator=u, is_spam=False).count())
开发者ID:1234-,项目名称:kitsune,代码行数:64,代码来源:test_views.py

示例13: HelperTestCase

class HelperTestCase(TestCase):
    def setUp(self):
        super(HelperTestCase, self).setUp()
        self.u = UserFactory()

    def test_profile_url(self):
        eq_(u'/user/%s' % self.u.username, profile_url(self.u))

    def test_profile_avatar_default(self):
        email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
        gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48' % (
            email_hash)
        assert profile_avatar(self.u).startswith(gravatar_url)

    def test_profile_avatar_anonymous(self):
        email_hash = '00000000000000000000000000000000'
        gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48' % (
            email_hash)
        assert profile_avatar(AnonymousUser()).startswith(gravatar_url)

    def test_profile_avatar(self):
        self.u.profile.avatar = 'images/foo.png'
        self.u.profile.save()
        email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
        gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48' % (
            email_hash)
        assert profile_avatar(self.u).startswith(gravatar_url)

    def test_profile_avatar_unicode(self):
        self.u.email = u'rá[email protected]'
        self.u.save()
        gravatar_url = 'https://secure.gravatar.com/'
        assert profile_avatar(self.u).startswith(gravatar_url)

    def test_public_email(self):
        eq_(u'<span class="email">'
            u'&#109;&#101;&#64;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;'
            u'&#111;&#109;</span>', public_email('[email protected]'))
        eq_(u'<span class="email">'
            u'&#110;&#111;&#116;&#46;&#97;&#110;&#46;&#101;&#109;&#97;&#105;'
            u'&#108;</span>', public_email('not.an.email'))

    def test_display_name(self):
        eq_(self.u.profile.name, display_name(self.u))
        self.u.profile.name = u'Test User'
        self.u.profile.save()
        eq_(u'Test User', display_name(self.u))

    def test_display_name_anonymous(self):
        eq_(u'', display_name(AnonymousUser()))

    def test_user_list(self):
        UserFactory(username='testuser2')
        UserFactory(username='testuser3')
        users = User.objects.all()
        list = user_list(users)
        assert isinstance(list, Markup)
        fragment = pq(list)
        eq_(len(users), len(fragment('a')))
        a = fragment('a')[1]
        assert a.attrib['href'].endswith(str(users[1].username))
        eq_(users[1].username, a.text)
开发者ID:1234-,项目名称:kitsune,代码行数:62,代码来源:test_templatetags.py

示例14: HelperTestCase

class HelperTestCase(TestCase):
    def setUp(self):
        super(HelperTestCase, self).setUp()
        self.u = UserFactory()

    def test_profile_url(self):
        eq_(u"/user/%s" % self.u.username, profile_url(self.u))

    def test_profile_avatar_default(self):
        email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
        gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48" % (email_hash)
        assert profile_avatar(self.u).startswith(gravatar_url)

    def test_profile_avatar_anonymous(self):
        email_hash = "00000000000000000000000000000000"
        gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48" % (email_hash)
        assert profile_avatar(AnonymousUser()).startswith(gravatar_url)

    def test_profile_avatar(self):
        self.u.profile.avatar = "images/foo.png"
        self.u.profile.save()
        email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
        gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48" % (email_hash)
        assert profile_avatar(self.u).startswith(gravatar_url)

    def test_profile_avatar_unicode(self):
        self.u.email = u"rá[email protected]"
        self.u.save()
        gravatar_url = "https://secure.gravatar.com/"
        assert profile_avatar(self.u).startswith(gravatar_url)

    def test_public_email(self):
        eq_(
            u'<span class="email">'
            u"&#109;&#101;&#64;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;"
            u"&#111;&#109;</span>",
            public_email("[email protected]"),
        )
        eq_(
            u'<span class="email">' u"&#110;&#111;&#116;&#46;&#97;&#110;&#46;&#101;&#109;&#97;&#105;" u"&#108;</span>",
            public_email("not.an.email"),
        )

    def test_display_name(self):
        eq_(self.u.profile.name, display_name(self.u))
        self.u.profile.name = u"Test User"
        self.u.profile.save()
        eq_(u"Test User", display_name(self.u))

    def test_display_name_anonymous(self):
        eq_(u"", display_name(AnonymousUser()))

    def test_user_list(self):
        UserFactory(username="testuser2")
        UserFactory(username="testuser3")
        users = User.objects.all()
        list = user_list(users)
        assert isinstance(list, Markup)
        fragment = pq(list)
        eq_(len(users), len(fragment("a")))
        a = fragment("a")[1]
        assert a.attrib["href"].endswith(str(users[1].username))
        eq_(users[1].username, a.text)
开发者ID:chupahanks,项目名称:kitsune,代码行数:63,代码来源:test_helpers.py

示例15: PasswordResetTests

class PasswordResetTests(TestCaseBase):

    def setUp(self):
        super(PasswordResetTests, self).setUp()
        self.u = UserFactory(email="[email protected]")
        self.uidb36 = int_to_base36(self.u.id)
        self.token = default_token_generator.make_token(self.u)
        self.orig_debug = settings.DEBUG
        settings.DEBUG = True

    def tearDown(self):
        super(PasswordResetTests, self).tearDown()
        settings.DEBUG = self.orig_debug

    def test_bad_email(self):
        r = self.client.post(reverse('users.pw_reset'),
                             {'email': '[email protected]'})
        eq_(302, r.status_code)
        eq_('http://testserver/en-US/users/pwresetsent', r['location'])
        eq_(0, len(mail.outbox))

    @mock.patch.object(Site.objects, 'get_current')
    def test_success(self, get_current):
        get_current.return_value.domain = 'testserver.com'
        r = self.client.post(reverse('users.pw_reset'),
                             {'email': self.u.email})
        eq_(302, r.status_code)
        eq_('http://testserver/en-US/users/pwresetsent', r['location'])
        eq_(1, len(mail.outbox))
        assert mail.outbox[0].subject.find('Password reset') == 0
        assert mail.outbox[0].body.find('pwreset/%s' % self.uidb36) > 0

    @mock.patch.object(PasswordResetForm, 'save')
    def test_smtp_error(self, pwform_save):
        def raise_smtp(*a, **kw):
            raise SMTPRecipientsRefused(recipients=[self.u.email])
        pwform_save.side_effect = raise_smtp
        r = self.client.post(reverse('users.pw_reset'),
                             {'email': self.u.email})
        self.assertContains(r, unicode(ERROR_SEND_EMAIL))

    def _get_reset_url(self):
        return reverse('users.pw_reset_confirm',
                       args=[self.uidb36, self.token])

    def test_bad_reset_url(self):
        r = self.client.get('/users/pwreset/junk/', follow=True)
        eq_(r.status_code, 404)

        r = self.client.get(reverse('users.pw_reset_confirm',
                                    args=[self.uidb36, '12-345']))
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_('Password reset unsuccessful', doc('article h1').text())

    def test_reset_fail(self):
        url = self._get_reset_url()
        r = self.client.post(url, {'new_password1': '', 'new_password2': ''})
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_(1, len(doc('ul.errorlist')))

        r = self.client.post(url, {'new_password1': 'onetwo12',
                                   'new_password2': 'twotwo22'})
        eq_(200, r.status_code)
        doc = pq(r.content)
        eq_("The two password fields didn't match.",
            doc('ul.errorlist li').text())

    def test_reset_success(self):
        url = self._get_reset_url()
        new_pw = 'fjdka387fvstrongpassword!'
        assert self.u.check_password(new_pw) is False

        r = self.client.post(url, {'new_password1': new_pw,
                                   'new_password2': new_pw})
        eq_(302, r.status_code)
        eq_('http://testserver/en-US/users/pwresetcomplete', r['location'])
        self.u = User.objects.get(username=self.u.username)
        assert self.u.check_password(new_pw)

    def test_reset_user_with_unusable_password(self):
        """Verify that user's with unusable passwords can reset them."""
        self.u.set_unusable_password()
        self.u.save()
        self.test_success()
开发者ID:1234-,项目名称:kitsune,代码行数:86,代码来源:test_templates.py


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