本文整理汇总了Python中courselib.testing.Client.post方法的典型用法代码示例。如果您正苦于以下问题:Python Client.post方法的具体用法?Python Client.post怎么用?Python Client.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类courselib.testing.Client
的用法示例。
在下文中一共展示了Client.post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_api
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_api(self):
crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
memb = Member.objects.get(offering=crs, person__userid="ggbaker")
person = Person.objects.get(userid='ggbaker')
p = Page(offering=crs, label="PageExists")
p.save()
v = PageVersion(page=p, title="Page Exists", wikitext="Original Contents", editor=memb, comment="original page")
v.save()
from dashboard.models import new_feed_token
token = new_feed_token()
updata = u"""{
"userid": "ggbaker",
"token": "%s",
"pages": [
{
"label": "Index",
"title": "The Coursé Page",
"can_read": "ALL",
"can_write": "INST",
"wikitext-base64": "VGhpcyBwYWdlIGlzIHNwZWNpYWwgaW4gKipzb21lKiogd2F5LiBcKHh+XjIrMSA9IFxmcmFjezF9ezJ9XCkuCgpHb29kYnllIHdvcmxkIQ==",
"comment": "page creation comment",
"use_math": true
},
{
"label": "PageExists",
"new_label": "PageChanged",
"title": "Another Page",
"can_read": "STUD",
"wikitext": "This is some **new** page\\n\\ncontent."
}
]
}""" % (token)
# make a request with no auth token in place
c = Client()
url = reverse('pages.views.api_import', kwargs={'course_slug': crs.slug})
response = c.post(url, data=updata.encode('utf8'), content_type="application/json")
self.assertEquals(response.status_code, 403)
# create token and try again
person.config['pages-token'] = token
person.save()
response = c.post(url, data=updata.encode('utf8'), content_type="application/json")
self.assertEquals(response.status_code, 200)
# make sure the data arrived
self.assertEquals(Page.objects.filter(offering=crs, label="PageExists").count(), 0)
p = Page.objects.get(offering=crs, label="PageChanged")
v = p.current_version()
self.assertEqual(v.title, "Another Page")
self.assertEqual(v.get_wikitext(), "This is some **new** page\n\ncontent.")
p = Page.objects.get(offering=crs, label="Index")
v = p.current_version()
self.assertEqual(v.title, u"The Cours\u00e9 Page")
self.assertEqual(v.get_wikitext(), 'This page is special in **some** way. \\(x~^2+1 = \\frac{1}{2}\\).\n\nGoodbye world!')
self.assert_('math' in v.config)
self.assertEqual(v.config['math'], True)
示例2: test_annual_teaching
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_annual_teaching(self):
"""
Test the annual teaching value entry field
"""
person = Person.objects.get(userid='ggbaker')
unit = Unit.objects.get(slug='cmpt')
editor = Person.objects.get(userid='dzhao')
etype = 'NORM_TEACH'
event = CareerEvent.objects.filter(unit=unit, person=person, event_type=etype)[0]
event.config['load'] = 2 # 2 courses/semester in database should be 6/year to the user
event.get_handler().save(editor)
c = Client()
c.login_user(editor.userid)
# make sure the form renders with value="6"
url = reverse('faculty:change_event', kwargs={'userid': person.userid, 'event_slug': event.slug})
resp = c.get(url)
inputs = [l for l in resp.content.split(b'\n') if b'name="load"' in l]
inputs_correct_value = [l for l in inputs if b'value="6"' in l]
self.assertEqual(len(inputs_correct_value), 1)
# POST a change and make sure the right value ends up in the DB
data = {
'start_date_0': '2000-09-01',
'end_date_0': '',
'unit': str(unit.id),
'load': '5',
'comments': '',
}
c.post(url, data)
new_ce = CareerEvent.objects.filter(unit=unit, person=person, event_type=etype)[0]
self.assertEqual(new_ce.config['load'], '5/3')
示例3: test_inaccessible_pages
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_inaccessible_pages(self):
# Presumably, our booking that starts more than 5 years ago is the one generated in the fixtures. If there are
# others that old, it should at least be the first.
unit = Unit.objects.get(slug='cmpt')
booking = BookingRecord.objects.filter(start_time__lte=self.long_start, location__unit=unit).first()
location = booking.location
roomtype = location.room_type
client = Client()
# First, without logging in:
url = reverse('space:index')
response = client.get(url)
self.assertEqual(response.status_code, 302)
# Now log in but without the correct role
client.login_user('pba7')
response = client.get(url)
self.assertEqual(response.status_code, 403)
# We darn well better not be able to delete anything without the proper role:
url = reverse('space:delete_booking', kwargs={'booking_id': booking.id})
response = client.post(url, follow=True)
self.assertEqual(response.status_code, 403)
url = reverse('space:delete_location', kwargs={'location_id': location.id})
response = client.post(url, follow=True)
self.assertEqual(response.status_code, 403)
url = reverse('space:delete_roomtype', kwargs={'roomtype_id': roomtype.id})
response = client.post(url, follow=True)
self.assertEqual(response.status_code, 403)
示例4: test_pages
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_pages(self):
# Presumably, our booking that starts more than 5 years ago is the one generated in the fixtures. If there are
# others that old, it should at least be the first.
unit = Unit.objects.get(slug='cmpt')
booking = BookingRecord.objects.filter(start_time__lte=self.long_start, location__unit=unit).first()
location = booking.location
roomtype = location.room_type
client = Client()
userid = Role.objects_fresh.filter(role='SPAC', unit=unit)[0].person.userid
client.login_user(userid)
test_views(self, client, 'space:', ['index', 'list_roomtypes', 'add_roomtype', 'manage_safety_items',
'add_safety_item'], {})
test_views(self, client, 'space:', ['view_location', 'edit_location', 'add_booking'],
{'location_slug': location.slug})
test_views(self, client, 'space:', ['view_roomtype', 'edit_roomtype'], {'roomtype_slug': roomtype.slug})
test_views(self, client, 'space:', ['view_booking', 'edit_booking', 'add_booking_attachment'],
{'booking_slug': booking.slug})
# Now, we should be able to delete stuff properly.
url = reverse('space:delete_booking', kwargs={'booking_id': booking.id})
response = client.post(url, follow=True)
self.assertEqual(response.status_code, 200)
url = reverse('space:delete_location', kwargs={'location_id': location.id})
response = client.post(url, follow=True)
self.assertEqual(response.status_code, 200)
url = reverse('space:delete_roomtype', kwargs={'roomtype_id': roomtype.id})
response = client.post(url, follow=True)
self.assertEqual(response.status_code, 200)
示例5: DISABLED_test_rest_notes_problem_already_exists
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def DISABLED_test_rest_notes_problem_already_exists(self):
raise SkipTest()
client = Client()
f = open('advisornotes/testfiles/rest_notes_problem_already_exists.json')
data = f.read()
f.close()
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
before_count = len(Problem.objects.filter(person__emplid=200000172))
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
after_count = len(Problem.objects.filter(person__emplid=200000172))
self.assertEqual(response.status_code, 200)
self.assertEqual(before_count, after_count, "Shouldn't duplicate problem")
示例6: test_new_nonstudent_post_failure
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_new_nonstudent_post_failure(self):
client = Client()
client.login_user("dzhao")
response = client.post(reverse('advisornotes.views.new_nonstudent'), {'first_name': 'test123'})
self.assertEqual(response.status_code, 200, "Should be brought back to form")
q = NonStudent.objects.filter(first_name='test123')
self.assertEqual(len(q), 0, "Nonstudent should not have been created")
示例7: test_workflow
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_workflow(self):
"""
Test the privacy policy workflow and page exclusions
"""
# clear privacy agreement from test data
p = Person.objects.get(userid='dzhao')
p.config = {}
p.save()
client = Client()
client.login_user(p.userid)
privacy_url = reverse('privacy.views.privacy')
# non-role page should still render
url = reverse('dashboard.views.index')
basic_page_tests(self, client, url)
# but role page should redirect to agreement
url = reverse('advisornotes.views.advising')
response = client.get(url)
self.assertRedirects(response, privacy_url + '?next=' + url)
# check privacy page
basic_page_tests(self, client, privacy_url)
# submit and expect recorded agreement
response = client.post(privacy_url + '?next=' + url, {'agree': 'on'})
self.assertRedirects(response, url)
p = Person.objects.get(userid='dzhao')
self.assertTrue(p.config['privacy_signed'])
# now we should be able to access
basic_page_tests(self, client, url)
示例8: test_rest_notes_invalid_UTF8
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_rest_notes_invalid_UTF8(self):
client = Client()
f = open('advisornotes/testfiles/rest_notes_bad_utf8.json')
data = f.read()
f.close()
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual(response.content, 'Bad UTF-8 encoded text')
示例9: test_rest_notes_bad_base64
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_rest_notes_bad_base64(self):
client = Client()
f = open('advisornotes/testfiles/rest_notes_bad_base64.json')
data = f.read()
f.close()
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
self.assertEqual(response.status_code, 422)
self.assertEqual(response.content, "Invalid base64 data for note file attachment")
示例10: test_rest_notes_file_data_not_string
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_rest_notes_file_data_not_string(self):
client = Client()
f = open('advisornotes/testfiles/rest_notes_file_data_not_string.json')
data = f.read()
f.close()
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
self.assertEqual(response.status_code, 422)
self.assertEqual(response.content, "Note file data must be a string")
示例11: test_rest_notes_emplid_doesnt_exist
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_rest_notes_emplid_doesnt_exist(self):
client = Client()
f = open('advisornotes/testfiles/rest_notes_emplid_doesnt_exist.json')
data = f.read()
f.close()
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
self.assertEqual(response.status_code, 422)
self.assertEqual(response.content, "Emplid '321' doesn't exist")
示例12: test_rest_notes_emplid_not_int
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_rest_notes_emplid_not_int(self):
client = Client()
f = open('advisornotes/testfiles/rest_notes_emplid_not_int.json')
data = f.read()
f.close()
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
self.assertEqual(response.status_code, 422)
self.assertEqual(response.content, "Note emplid must be an integer")
示例13: test_rest_notes_emplid_text_missing
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_rest_notes_emplid_text_missing(self):
client = Client()
f = open('advisornotes/testfiles/rest_notes_emplid_missing.json')
data = f.read()
f.close()
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
self.assertEqual(response.status_code, 422)
self.assertEqual(response.content, "Emplid or text not present in note")
示例14: test_rest_notes_empty_list
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_rest_notes_empty_list(self):
client = Client()
f = open('advisornotes/testfiles/rest_notes_empty.json')
data = f.read()
f.close()
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
self.assertEqual(response.status_code, 422)
self.assertEqual(response.content, "No advising notes present")
示例15: test_rest_notes_missing_credential
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import post [as 别名]
def test_rest_notes_missing_credential(self):
client = Client()
f = open('advisornotes/testfiles/rest_notes_missing_credential.json')
data = f.read()
f.close()
response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
self.assertEqual(response.status_code, 422)
self.assertEqual(response.content, "The key 'secret' is not present. ")