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


Python LocalizingClient.login方法代码示例

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


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

示例1: SocialAccountConnectionsTests

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
class SocialAccountConnectionsTests(test_utils.TestCase):
    fixtures = ['test_users.json']

    def setUp(self):
        self.client = LocalizingClient()

    def test_account_connections_page_requires_signin(self):
        url = reverse('socialaccount_connections')
        r = self.client.get(url, follow=True)

        eq_(200, r.status_code)
        ok_(len(r.redirect_chain) > 0)
        ok_('Sign In' in r.content)

    def test_account_connections_page(self):
        u = User.objects.get(username='testuser')
        self.client.login(username=u.username, password=TESTUSER_PASSWORD)
        url = reverse('socialaccount_connections')
        r = self.client.get(url)
        test_strings = ['Disconnect', 'Connect a new account', 'Edit profile']

        eq_(200, r.status_code)
        for test_string in test_strings:
            ok_(test_string in r.content,
                msg="Expected %s in content" % test_string)
开发者ID:vrubiolo,项目名称:kuma,代码行数:27,代码来源:test_templates.py

示例2: DemoListViewsTest

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
class DemoListViewsTest(test_utils.TestCase):
    fixtures = ["test_users.json"]

    def setUp(self):
        self.user, self.admin_user, self.other_user = make_users()
        self.client = LocalizingClient()

    def test_all_demos_includes_hidden_for_staff(self):
        build_submission(self.user)
        build_hidden_submission(self.user)

        r = self.client.get(reverse("demos_all"))
        count = pq(r.content)("h2.count").text()
        eq_(count, "1 Demo")

        self.client.login(username=self.admin_user.username, password="admint_tester")
        r = self.client.get(reverse("demos_all"))
        count = pq(r.content)("h2.count").text()
        eq_(count, "2 Demos")

    @attr("bug882709")
    def test_search_view(self):
        try:
            self.client.get(reverse("demos_search"))
        except:
            self.fail("Search should not ISE.")
开发者ID:craigcook,项目名称:kuma,代码行数:28,代码来源:test_views.py

示例3: AccountEmailTests

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
class AccountEmailTests(test_utils.TestCase):
    fixtures = ['test_users.json']

    def setUp(self):
        self.client = LocalizingClient()

    def test_account_email_page_requires_signin(self):
        url = reverse('account_email')
        r = self.client.get(url, follow=True)

        eq_(200, r.status_code)
        ok_(len(r.redirect_chain) > 0)
        ok_('Sign In' in r.content)

    def test_account_email_page(self):
        u = User.objects.get(username='testuser')
        self.client.login(username=u.username, password=TESTUSER_PASSWORD)
        url = reverse('account_email')
        r = self.client.get(url)
        test_strings = ['Make Primary', 'Re-send Verification', 'Remove',
                        'Add Email', 'Edit profile']

        eq_(200, r.status_code)
        for test_string in test_strings:
            ok_(test_string in r.content)
开发者ID:vrubiolo,项目名称:kuma,代码行数:27,代码来源:test_templates.py

示例4: test_404_already_logged_in

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
    def test_404_already_logged_in(self):
        """The login buttons should not display on the 404 page when the user is logged in"""
        client = LocalizingClient()

        # View page as a logged in user
        client.login(username='testuser',
                     password='testpass')
        response = client.get('/something-doesnt-exist', follow=True)
        doc = pq(response.content)

        login_block = doc.find('.socialaccount_providers')
        eq_(len(login_block), 0)
        eq_(404, response.status_code)
        client.logout()
开发者ID:RiteshAgrawal,项目名称:kuma,代码行数:16,代码来源:test_views.py

示例5: test_ban_middleware

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
    def test_ban_middleware(self):
        """Ban middleware functions correctly."""
        client = LocalizingClient()
        client.login(username='testuser', password='testpass')

        resp = client.get('/')
        self.assertTemplateNotUsed(resp, 'users/user_banned.html')

        admin = User.objects.get(username='admin')
        testuser = User.objects.get(username='testuser')
        ban = UserBan(user=testuser, by=admin,
                      reason='Banned by unit test.',
                      is_active=True)
        ban.save()

        resp = client.get('/')
        self.assertTemplateUsed(resp, 'users/user_banned.html')
开发者ID:RiteshAgrawal,项目名称:kuma,代码行数:19,代码来源:test_middleware.py

示例6: test_ban_view

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
    def test_ban_view(self):
        testuser = User.objects.get(username='testuser')
        admin = User.objects.get(username='admin')

        client = LocalizingClient()
        client.login(username='admin', password='testpass')

        data = {'reason': 'Banned by unit test.'}
        ban_url = reverse('users.ban_user',
                          kwargs={'user_id': testuser.id})

        resp = client.post(ban_url, data)
        eq_(302, resp.status_code)
        ok_(testuser.get_absolute_url() in resp['Location'])

        testuser_banned = User.objects.get(username='testuser')
        ok_(not testuser_banned.is_active)

        bans = UserBan.objects.filter(user=testuser,
                                      by=admin,
                                      reason='Banned by unit test.')
        ok_(bans.count())
开发者ID:courvillejustin,项目名称:kuma,代码行数:24,代码来源:test_views.py

示例7: test_ban_permission

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
    def test_ban_permission(self):
        """The ban permission controls access to the ban view."""
        client = LocalizingClient()
        admin = User.objects.get(username='admin')
        testuser = User.objects.get(username='testuser')

        # testuser doesn't have ban permission, can't ban.
        client.login(username='testuser',
                     password='testpass')
        ban_url = reverse('users.ban_user',
                          kwargs={'user_id': admin.id})
        resp = client.get(ban_url)
        eq_(302, resp.status_code)
        ok_(settings.LOGIN_URL in resp['Location'])
        client.logout()

        # admin has ban permission, can ban.
        client.login(username='admin',
                     password='testpass')
        ban_url = reverse('users.ban_user',
                          kwargs={'user_id': testuser.id})
        resp = client.get(ban_url)
        eq_(200, resp.status_code)
开发者ID:courvillejustin,项目名称:kuma,代码行数:25,代码来源:test_views.py

示例8: BrowserIDTestCase

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]

#.........这里部分代码省略.........
                                            'action': 'register',
                                            'country': 'us',
                                            'format': 'html'})

        # The submission should result in a redirect to the session's redirect
        # value
        eq_(302, resp.status_code)
        redir_url = resp['Location']
        ok_('SUCCESS' in redir_url)

        # The session should look logged in, now.
        ok_('_auth_user_id' in self.client.session.keys())
        eq_('django_browserid.auth.BrowserIDBackend',
            self.client.session.get('_auth_user_backend', ''))

        # Ensure that the user was created, and with the submitted username and
        # verified email address
        try:
            user = User.objects.get(email=new_email)
            eq_(new_username, user.username)
            eq_(new_email, user.email)
        except User.DoesNotExist:
            ok_(False, "New user should have been created")

        # Ensure the user was sent a welcome email
        welcome_email = mail.outbox[0]
        expected_subject = u'Take the next step to get involved on MDN!'
        expected_to = [new_email]
        eq_(expected_subject, welcome_email.subject)
        eq_(expected_to, welcome_email.to)
        ok_(u'Hi %s' % new_username in welcome_email.body)

    @mock.patch('users.views._verify_browserid')
    def test_valid_assertion_with_existing_account_login(self,
                                                         _verify_browserid):
        """ Removed the existing user form: we don't auth the password with
        MindTouch anymore """
        new_email = '[email protected]'
        _verify_browserid.return_value = {'email': new_email}

        try:
            User.objects.get(email=new_email)
            ok_(False, "User for email should not yet exist")
        except User.DoesNotExist:
            pass

        # Sign in with a verified email, but with no existing account
        resp = self.client.post(reverse('users.browserid_verify',
                                        locale='en-US'),
                                {'assertion': 'PRETENDTHISISVALID'})
        eq_(302, resp.status_code)

        # This should be a redirect to the BrowserID registration page.
        redir_url = resp['Location']
        reg_url = reverse('users.browserid_register', locale='en-US')
        ok_(reg_url in redir_url)

        # And, as part of the redirect, the verified email address should be in
        # our session now.
        ok_(SESSION_VERIFIED_EMAIL in self.client.session.keys())
        verified_email = self.client.session[SESSION_VERIFIED_EMAIL]
        eq_(new_email, verified_email)

        # Grab the redirect, assert that there's a create_user form present
        resp = self.client.get(redir_url)
        page = pq(resp.content)
开发者ID:courvillejustin,项目名称:kuma,代码行数:70,代码来源:test_views.py

示例9: ChangeEmailTestCase

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
class ChangeEmailTestCase(TestCase):
    fixtures = ['test_users.json']

    def setUp(self):
        self.client = LocalizingClient()

    @mock.patch_object(Site.objects, 'get_current')
    def test_user_change_email(self, get_current):
        """Send email to change user's email and then change it."""
        get_current.return_value.domain = 'su.mo.com'

        self.client.login(username='testuser', password='testpass')
        # Attempt to change email.
        response = self.client.post(reverse('users.change_email'),
                                    {'email': '[email protected]'},
                                    follow=True)
        eq_(200, response.status_code)

        # Be notified to click a confirmation link.
        eq_(1, len(mail.outbox))
        assert mail.outbox[0].subject.find('Please confirm your') == 0
        ec = EmailChange.objects.all()[0]
        assert ec.activation_key in mail.outbox[0].body
        eq_('[email protected]', ec.email)

        # Visit confirmation link to change email.
        response = self.client.get(reverse('users.confirm_email',
                                           args=[ec.activation_key]))
        eq_(200, response.status_code)
        u = User.objects.get(username='testuser')
        eq_('[email protected]', u.email)

    def test_user_change_email_same(self):
        """Changing to same email shows validation error."""
        self.client.login(username='testuser', password='testpass')
        user = User.objects.get(username='testuser')
        user.email = '[email protected]'
        user.save()
        response = self.client.post(reverse('users.change_email'),
                                    {'email': user.email})
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_('This is your current email.', doc('ul.errorlist').text())

    def test_user_change_email_duplicate(self):
        """Changing to same email shows validation error."""
        self.client.login(username='testuser', password='testpass')
        email = '[email protected]'
        response = self.client.post(reverse('users.change_email'),
                                    {'email': email})
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_('A user with that email address already exists.',
            doc('ul.errorlist').text())

    @mock.patch_object(Site.objects, 'get_current')
    def test_user_confirm_email_duplicate(self, get_current):
        """If we detect a duplicate email when confirming an email change,
        don't change it and notify the user."""
        get_current.return_value.domain = 'su.mo.com'
        self.client.login(username='testuser', password='testpass')
        old_email = User.objects.get(username='testuser').email
        new_email = '[email protected]'
        response = self.client.post(reverse('users.change_email'),
                                    {'email': new_email})
        eq_(200, response.status_code)
        assert mail.outbox[0].subject.find('Please confirm your') == 0
        ec = EmailChange.objects.all()[0]

        # Before new email is confirmed, give the same email to a user
        other_user = User.objects.filter(username='testuser2')[0]
        other_user.email = new_email
        other_user.save()

        # Visit confirmation link and verify email wasn't changed.
        response = self.client.get(reverse('users.confirm_email',
                                           args=[ec.activation_key]))
        eq_(200, response.status_code)
        doc = pq(response.content)
        eq_('Unable to change email for user testuser',
            doc('article h1').text())
        u = User.objects.get(username='testuser')
        eq_(old_email, u.email)
开发者ID:courvillejustin,项目名称:kuma,代码行数:85,代码来源:test_views.py

示例10: ProfileViewsTest

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
class ProfileViewsTest(TestCase):
    fixtures = ['test_users.json']

    def setUp(self):
        self.old_debug = settings.DEBUG
        settings.DEBUG = True
        self.client = LocalizingClient()
        self.client.logout()

    def tearDown(self):
        settings.DEBUG = self.old_debug

    def _get_current_form_field_values(self, doc):
        # Scrape out the existing significant form field values.
        form = dict()
        for fn in ('email', 'fullname', 'title', 'organization', 'location',
                   'irc_nickname', 'bio', 'interests', 'country', 'format'):
            form[fn] = doc.find('#profile-edit *[name="%s"]' % fn).val()
        form['country'] = 'us'
        form['format'] = 'html'
        return form

    @attr('docs_activity')
    def test_profile_view(self):
        """A user profile can be viewed"""
        profile = UserProfile.objects.get(user__username='testuser')
        user = profile.user
        url = reverse('users.profile', args=(user.username,))
        r = self.client.get(url, follow=True)
        doc = pq(r.content)

        eq_(profile.user.username,
            doc.find('#profile-head.vcard .nickname').text())
        eq_(profile.fullname,
            doc.find('#profile-head.vcard .fn').text())
        eq_(profile.title,
            doc.find('#profile-head.vcard .title').text())
        eq_(profile.organization,
            doc.find('#profile-head.vcard .org').text())
        eq_(profile.location,
            doc.find('#profile-head.vcard .loc').text())
        eq_('IRC: ' + profile.irc_nickname,
            doc.find('#profile-head.vcard .irc').text())
        eq_(profile.bio,
            doc.find('#profile-head.vcard .bio').text())

    def test_my_profile_view(self):
        u = User.objects.get(username='testuser')
        self.client.login(username=u.username, password=TESTUSER_PASSWORD)
        resp = self.client.get('/profile/')
        eq_(302, resp.status_code)
        ok_(reverse('users.profile', args=(u.username,)) in
            resp['Location'])

    def test_bug_698971(self):
        """A non-numeric page number should not cause an error"""
        (user, profile) = create_profile()

        url = '%s?page=asdf' % reverse('users.profile', args=(user.username,))

        try:
            self.client.get(url, follow=True)
        except PageNotAnInteger:
            ok_(False, "Non-numeric page number should not cause an error")

    @mock.patch('basket.lookup_user')
    @mock.patch('basket.subscribe')
    @mock.patch('basket.unsubscribe')
    def test_profile_edit(self,
                            unsubscribe,
                            subscribe,
                            lookup_user):
        lookup_user.return_value = mock_lookup_user()
        subscribe.return_value = True
        unsubscribe.return_value = True
        profile = UserProfile.objects.get(user__username='testuser')
        user = profile.user
        url = reverse('users.profile', args=(user.username,))
        r = self.client.get(url, follow=True)
        doc = pq(r.content)
        eq_(0, doc.find('#profile-head .edit .button').length)

        self.client.login(username=user.username,
                password=TESTUSER_PASSWORD)

        url = reverse('users.profile', args=(user.username,))
        r = self.client.get(url, follow=True)
        doc = pq(r.content)

        edit_button = doc.find('#profile-head .edit #edit-profile')
        eq_(1, edit_button.length)

        url = edit_button.attr('href')
        r = self.client.get(url, follow=True)
        doc = pq(r.content)

        eq_(profile.fullname,
            doc.find('#profile-edit input[name="fullname"]').val())
        eq_(profile.title,
            doc.find('#profile-edit input[name="title"]').val())
#.........这里部分代码省略.........
开发者ID:g1angel,项目名称:kuma,代码行数:103,代码来源:test_views.py

示例11: ProfileViewsTest

# 需要导入模块: from devmo.tests import LocalizingClient [as 别名]
# 或者: from devmo.tests.LocalizingClient import login [as 别名]
class ProfileViewsTest(TestCase):
    fixtures = ["test_users.json"]

    def setUp(self):
        self.old_debug = settings.DEBUG
        settings.DEBUG = True
        self.client = LocalizingClient()
        self.client.logout()

    def tearDown(self):
        settings.DEBUG = self.old_debug

    def _get_current_form_field_values(self, doc):
        # Scrape out the existing significant form field values.
        form = dict()
        for fn in (
            "email",
            "fullname",
            "title",
            "organization",
            "location",
            "irc_nickname",
            "bio",
            "interests",
            "country",
            "format",
        ):
            form[fn] = doc.find('#profile-edit *[name="%s"]' % fn).val()
        form["country"] = "us"
        form["format"] = "html"
        return form

    @attr("docs_activity")
    def test_profile_view(self):
        """A user profile can be viewed"""
        profile = UserProfile.objects.get(user__username="testuser")
        user = profile.user
        url = reverse("devmo.views.profile_view", args=(user.username,))
        r = self.client.get(url, follow=True)
        doc = pq(r.content)

        eq_(profile.user.username, doc.find("#profile-head.vcard .nickname").text())
        eq_(profile.fullname, doc.find("#profile-head.vcard .fn").text())
        eq_(profile.title, doc.find("#profile-head.vcard .title").text())
        eq_(profile.organization, doc.find("#profile-head.vcard .org").text())
        eq_(profile.location, doc.find("#profile-head.vcard .loc").text())
        eq_("IRC: " + profile.irc_nickname, doc.find("#profile-head.vcard .irc").text())
        eq_(profile.bio, doc.find("#profile-head.vcard .bio").text())

    def test_my_profile_view(self):
        u = User.objects.get(username="testuser")
        self.client.login(username=u.username, password=TESTUSER_PASSWORD)
        resp = self.client.get("/profile/")
        eq_(302, resp.status_code)
        ok_(reverse("devmo.views.profile_view", args=(u.username,)) in resp["Location"])

    def test_bug_698971(self):
        """A non-numeric page number should not cause an error"""
        (user, profile) = create_profile()

        url = "%s?page=asdf" % reverse("devmo.views.profile_view", args=(user.username,))

        try:
            self.client.get(url, follow=True)
        except PageNotAnInteger:
            ok_(False, "Non-numeric page number should not cause an error")

    @mock.patch("basket.lookup_user")
    @mock.patch("basket.subscribe")
    @mock.patch("basket.unsubscribe")
    def test_profile_edit(self, unsubscribe, subscribe, lookup_user):
        lookup_user.return_value = mock_lookup_user()
        subscribe.return_value = True
        unsubscribe.return_value = True
        profile = UserProfile.objects.get(user__username="testuser")
        user = profile.user
        url = reverse("devmo.views.profile_view", args=(user.username,))
        r = self.client.get(url, follow=True)
        doc = pq(r.content)
        eq_(0, doc.find("#profile-head .edit .button").length)

        self.client.login(username=user.username, password=TESTUSER_PASSWORD)

        url = reverse("devmo.views.profile_view", args=(user.username,))
        r = self.client.get(url, follow=True)
        doc = pq(r.content)

        edit_button = doc.find("#profile-head .edit #edit-profile")
        eq_(1, edit_button.length)

        url = edit_button.attr("href")
        r = self.client.get(url, follow=True)
        doc = pq(r.content)

        eq_(profile.fullname, doc.find('#profile-edit input[name="fullname"]').val())
        eq_(profile.title, doc.find('#profile-edit input[name="title"]').val())
        eq_(profile.organization, doc.find('#profile-edit input[name="organization"]').val())
        eq_(profile.location, doc.find('#profile-edit input[name="location"]').val())
        eq_(profile.irc_nickname, doc.find('#profile-edit input[name="irc_nickname"]').val())

#.........这里部分代码省略.........
开发者ID:parisk,项目名称:kuma,代码行数:103,代码来源:test_views.py


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