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


Python TestClient.login方法代码示例

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


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

示例1: RemoteAccessRequestModelTests

# 需要导入模块: from myjobs.tests.test_views import TestClient [as 别名]
# 或者: from myjobs.tests.test_views.TestClient import login [as 别名]
class RemoteAccessRequestModelTests(MyJobsBase):
    def setUp(self):
        super(RemoteAccessRequestModelTests, self).setUp()
        self.password = '[email protected]'
        self.client = TestClient()
        self.client.login(email=self.user.email, password=self.password)

        self.account_owner = UserFactory(email='[email protected]',
                                         password=self.password)
        self.impersonate_url = reverse('impersonate-start', kwargs={
            'uid': self.account_owner.pk})
        self.site = SeoSite.objects.first()

    def test_create_request_sends_messages(self):
        """
        The requesting of remote access should send both a My.jobs message
        and an email to the account owner.
        """
        msg = "User had %s messages, expected %s"
        mail.outbox = []
        spar = SecondPartyAccessRequest.objects.create(
            account_owner=self.account_owner, second_party=self.user,
            site=self.site, reason='just cuz')
        self.assertEqual(len(mail.outbox), 1)

        # We're logged in as the requesting user at this point and should
        # not have any messages.
        response = self.client.get(reverse('home'))
        self.assertEqual(len(response.context['new_messages']), 0,
                         msg=msg % (len(response.context['new_messages']), 0))

        response = self.client.get(reverse('impersonate-approve',
                                           kwargs={'access_id': spar.id}))
        self.assertEqual(response.status_code, 403,
                         msg=("Unauthorized approval of a request should not "
                              "happen but did"))

        # Log out then log in as the account owner.
        self.client.get(reverse('auth_logout'))
        self.client.login(email=self.account_owner.email,
                          password=self.password)
        response = self.client.get(reverse('home'))

        # We should now have one My.jobs message.
        messages = response.context['new_messages']
        self.assertEqual(len(messages), 1,
                         msg=msg % (len(response.context['new_messages']), 1))
        message = messages[0]
        email = mail.outbox[0]
        self.assertEqual(message.message.body, email.body,
                         msg="Message and email bodies were not identical")
        for text in ['>Allow<', '>Deny<', spar.reason,
                     self.user.get_full_name(default=self.user.email)]:
            self.assertTrue(text in email.body,
                            msg="%s not in email body" % text)
        response = self.client.get(reverse('impersonate-approve',
                                           kwargs={'access_id': spar.id}))
        spar = SecondPartyAccessRequest.objects.get(pk=spar.pk)
        self.assertEqual(spar.accepted, True,
                         msg="Acceptance status was not updated")
开发者ID:DirectEmployers,项目名称:MyJobs,代码行数:62,代码来源:test_models.py


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