本文整理汇总了Python中courselib.testing.Client.head方法的典型用法代码示例。如果您正苦于以下问题:Python Client.head方法的具体用法?Python Client.head怎么用?Python Client.head使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类courselib.testing.Client
的用法示例。
在下文中一共展示了Client.head方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: APITest
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import head [as 别名]
class APITest(TestCase):
fixtures = ['basedata', 'coredata']
def setUp(self):
self.faketime = 525942870
self.client = Client()
# create a Consumer (and associated stuff)
try:
u = User.objects.get(username='ggbaker')
except User.DoesNotExist:
u = User(username='ggbaker')
u.save()
try:
c = Consumer.objects.get(name='Test Consumer')
except Consumer.DoesNotExist:
c = Consumer(name='Test Consumer')
c.description = 'Consumer to do some tests with'
c.status = ACCEPTED
c.user = u
c.xauth_allowed = False
c.generate_random_codes()
c.save()
self.consumer = c
i = ConsumerInfo(consumer=c)
i.admin_contact = '[email protected]'
i.permissions = ['courses']
i.timestamp = self.faketime - 10 # make sure the ConsumerInfo was there "before" the Token was created
i.save()
self.consumerinfo = i
# create an access token so we can jump in to requests
try:
t = Token.objects.get(token_type=Token.ACCESS, consumer=c, user=u)
except Token.DoesNotExist:
t = Token(token_type=Token.ACCESS, consumer=c, user=u, timestamp=self.faketime)
t.is_approved = True
t.generate_random_codes()
t.verifier = VERIFIER
t.save()
self.token = t
def test_consumerinfo(self):
# replace time.time with a function that always returns ( 7:14AM, Sept 1, 1986 )
# make sure we get the right ConsumerInfo object for a token
i0 = ConsumerInfo(consumer=self.consumer, admin_contact='foo', permissions=['everything', 'nothing'])
i0.timestamp = self.faketime - 100
i0.save()
i2 = ConsumerInfo(consumer=self.consumer, admin_contact='foo', permissions=['something'])
i2.timestamp = self.faketime + 100
i2.save()
# we should retrieve the most recent before token creation: this is what the user agreed to.
perms = ConsumerInfo.allowed_permissions(self.token)
self.assertEqual(perms, ['courses'])
# if it has been deactivated, then no permissions remain
self.consumerinfo.deactivated = True
self.consumerinfo.save()
perms = ConsumerInfo.allowed_permissions(self.token)
self.assertEqual(perms, [])
def test_head_request(self):
"Make sure HEAD requests work with the cache mixin"
self.client.login_user('ggbaker')
url = reverse('api:APIRoot', kwargs={})
resp = self.client.head(url)
def test_all_endpoints(self):
client = self.client
client.login_user("ggbaker")
tester = APIEndpointTester(client, self)
tester.check_endpoint('api:APIRoot', {})
tester.check_endpoint('api:MyOfferings', {})
tester.check_endpoint('api:OfferingInfo', {'course_slug': TEST_COURSE_SLUG})
tester.check_endpoint('api:OfferingActivities', {'course_slug': TEST_COURSE_SLUG})
tester.check_endpoint('api:OfferingGrades', {'course_slug': TEST_COURSE_SLUG})
tester.check_endpoint('api:OfferingStats', {'course_slug': TEST_COURSE_SLUG})
tester.check_endpoint('api:OfferingStudents', {'course_slug': TEST_COURSE_SLUG})
tester.check_found_links()
def test_class_list_permission(self):
"""
Check that the class list API endpoint has the right permissions
"""
client = self.client
# no auth: should be forbidden
url = reverse('api:OfferingStudents', kwargs={'course_slug': TEST_COURSE_SLUG})
resp = self.client.get(url)
#.........这里部分代码省略.........