本文整理汇总了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)