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


Python Client.logout方法代码示例

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


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

示例1: test_permissions

# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import logout [as 别名]
    def test_permissions(self):
        """
        Test page access control behaviour.
        """
        crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        memb = Member.objects.filter(offering=crs, role='INST').first()
        inst = memb.person
        ta = Member.objects.filter(offering=crs, role='TA').first().person
        stud = Member.objects.filter(offering=crs, role='STUD').first().person
        non_member = Person.objects.get(userid='dixon')
        assert not Member.objects.filter(offering=crs, person=non_member)

        p = Page(offering=crs, label="Test", can_read='STAF', can_write='INST')
        p.save()
        v = PageVersion(page=p, title="Test Page", wikitext="Page contents", editor=memb)
        v.save()

        # page-viewing permissions
        c = Client()
        url = reverse('offering:pages:view_page', kwargs={'course_slug': crs.slug, 'page_label': 'Test'})

        c.logout()
        response = c.get(url)
        self.assertEqual(response.status_code, 403)

        c.login_user(inst.userid)
        response = c.get(url)
        self.assertEqual(response.status_code, 200)

        c.login_user(ta.userid)
        response = c.get(url)
        self.assertEqual(response.status_code, 200)

        c.login_user(stud.userid)
        response = c.get(url)
        self.assertEqual(response.status_code, 403)

        c.login_user(non_member.userid)
        response = c.get(url)
        self.assertEqual(response.status_code, 403)

        # ... but with a PagePermission object, non_member can access
        pp = PagePermission(person=non_member, offering=crs, role='INST')
        pp.save()
        response = c.get(url)
        self.assertEqual(response.status_code, 200)

        # page-editing permissions
        url = reverse('offering:pages:edit_page', kwargs={'course_slug': crs.slug, 'page_label': 'Test'})

        c.logout()
        response = c.get(url)
        self.assertEqual(response.status_code, 302) # redirect to log in

        c.login_user(inst.userid)
        response = c.get(url)
        self.assertEqual(response.status_code, 200)

        c.login_user(ta.userid)
        response = c.get(url)
        self.assertEqual(response.status_code, 403)

        c.login_user(stud.userid)
        response = c.get(url)
        self.assertEqual(response.status_code, 403)

        # editing with PagePermission not implemented
        c.login_user(non_member.userid)
        response = c.get(url)
        self.assertEqual(response.status_code, 403)
开发者ID:sfu-fas,项目名称:coursys,代码行数:72,代码来源:tests.py


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