本文整理汇总了Python中courselib.testing.Client.get方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get方法的具体用法?Python Client.get怎么用?Python Client.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类courselib.testing.Client
的用法示例。
在下文中一共展示了Client.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_redirect
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_redirect(self):
"""
Redirecting with redirect stub
"""
crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
memb = Member.objects.get(offering=crs, person__userid="ggbaker")
p = Page(offering=crs, label="Test")
p.save()
v = PageVersion(page=p, title="Test Page", wikitext="one +two+ three +four+", editor=memb)
v.save()
c = Client()
# normal pages still viewable
url = reverse('offering:pages:view_page', kwargs={'course_slug': crs.slug, 'page_label': 'Test'})
response = c.get(url)
self.assertEqual(response.status_code, 200)
v = PageVersion(page=p, redirect='NewLocation', editor=memb)
v.save()
response = c.get(url)
self.assertEqual(response.status_code, 301)
redir_url = reverse('offering:pages:view_page', kwargs={'course_slug': crs.slug, 'page_label': 'NewLocation'})
self.assertTrue(response['location'].endswith(redir_url))
示例2: test_grad_quicksearch
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_grad_quicksearch(self):
"""
Tests grad quicksearch (index page) functionality
"""
client = Client()
test_auth(client, 'ggbaker')
response = client.get(reverse('grad.views.index'))
self.assertEqual(response.status_code, 200)
# AJAX calls for autocomplete return JSON
response = client.get(reverse('grad.views.quick_search')+'?term=grad')
self.assertEqual(response.status_code, 200)
self.assertEqual(response['content-type'], 'application/json')
# get this grad's slug from the search
autocomplete = json.loads(response.content)
grad_slug = [d['value'] for d in autocomplete if d['value'].startswith(self.gs_userid)][0]
# search submit with gradstudent slug redirects to page
response = client.get(reverse('grad.views.quick_search')+'?search='+grad_slug)
self.assertEqual(response.status_code, 302)
self.assertTrue(response['location'].endswith( reverse('grad.views.view', kwargs={'grad_slug': grad_slug}) ))
# search submit with non-slug redirects to "did you mean" page
response = client.get(reverse('grad.views.quick_search')+'?search=' + self.gs_userid[0:4])
self.assertEqual(response.status_code, 302)
self.assertTrue(response['location'].endswith( reverse('grad.views.not_found')+"?search=" + self.gs_userid[0:4] ))
response = client.get(response['location'])
gradlist = response.context['grads']
self.assertEqual(len(gradlist), 1)
self.assertEqual(gradlist[0], GradStudent.objects.get(person__userid=self.gs_userid))
示例3: test_staff_page
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_staff_page(self):
"""
Check the requires_course_staff_by_slug decorator.
"""
# a URL and some members/non-members
url = reverse('grades.views.class_list', kwargs={'course_slug': TEST_COURSE_SLUG})
instr = "ggbaker"
ta = Member.objects.filter(offering__slug=TEST_COURSE_SLUG, role='TA')[0].person.userid
student = "0aaa0"
nobody = "0bbb6"
client = Client()
# try without logging in
response = client.get(url)
self.assertEquals(response.status_code, 302)
# try as instructor
client.login_user(instr)
response = client.get(url)
self.assertEquals(response.status_code, 200)
validate_content(self, response.content, url)
# try as TA
client.login_user(ta)
response = client.get(url)
self.assertEquals(response.status_code, 200)
# try as student
client.login_user(student)
response = client.get(url)
self.assertEquals(response.status_code, 403)
# try as non-member
client.login_user(nobody)
response = client.get(url)
self.assertEquals(response.status_code, 403)
示例4: test_course_page
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_course_page(self):
"""
Check out a course front-page
"""
_, c = create_offering()
client = Client()
# not logged in: should be redirected to login page
response = client.get(c.get_absolute_url())
self.assertEqual(response.status_code, 302)
# log in as student "0aaa0"
client.login_user("0aaa0")
p = Person.objects.get(userid="0aaa0")
# not in the course: should get 403 Forbidden
response = client.get(c.get_absolute_url())
self.assertEqual(response.status_code, 403)
# add to course and try again
m = Member(person=p, offering=c, role="STUD", credits=3, career="UGRD", added_reason="UNK")
m.save()
response = client.get(c.get_absolute_url())
self.assertEqual(response.status_code, 200)
validate_content(self, response.content, c.get_absolute_url())
# dropped students should be forbidden
m.role="DROP"
m.save()
response = client.get(c.get_absolute_url())
self.assertEqual(response.status_code, 403)
示例5: test_inaccessible_pages
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [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)
示例6: test_impersonation
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_impersonation(self):
"""
Test impersonation logic
"""
client = Client()
url = reverse('offering:groups:groupmanage', kwargs={'course_slug': TEST_COURSE_SLUG})
# login as a sysadmin
client.login_user('pba7')
# not instructor, so can't really access
response = client.get(url)
self.assertEqual(response.status_code, 403)
# ...but can impersonate instructor
response = client.get(url, {"__impersonate": "ggbaker"})
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Logged in as ggbaker')
# login as student
client.login_user("0aaa0")
# can access normally
response = client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Logged in as 0aaa0')
# try to impersonate anybody: not allowed
response = client.get(url, {"__impersonate": "0aaa1"})
self.assertEqual(response.status_code, 403)
response = client.get(url, {"__impersonate": "ggbaker"})
self.assertEqual(response.status_code, 403)
# login as instructor
client.login_user("ggbaker")
# can access course page
response = client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Logged in as ggbaker')
# try to impersonate non-student: not allowed
response = client.get(url, {"__impersonate": "dzhao"})
self.assertEqual(response.status_code, 403)
# try to impersonate student: should be them
response = client.get(url, {"__impersonate": "0aaa0"})
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Logged in as 0aaa0')
# try some other course: shouldn't be able to impersonate
url = reverse('offering:groups:groupmanage', kwargs={'course_slug': '1114-cmpt-310-d100'})
response = client.get(url, {"__impersonate": "0aaa0"})
self.assertEqual(response.status_code, 403)
# try non-course URL as non-admin: shouldn't be able to impersonate
client.login_user("diana")
url = reverse('dashboard:index', kwargs={})
response = client.get(url, {"__impersonate": "0aaa0"})
self.assertEqual(response.status_code, 403)
示例7: test_grad_letters
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_grad_letters(self):
"""
Check handling of letters for grad students
"""
client = Client()
test_auth(client, 'ggbaker')
gs = GradStudent.objects.get(person__userid=self.gs_userid)
# get template text and make sure substitutions are made
lt = LetterTemplate.objects.get(label="Funding")
url = reverse('grad.views.get_letter_text', kwargs={'grad_slug': gs.slug, 'letter_template_id': lt.id})
response = client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'M Grad is making satisfactory progress')
content = unicode(response.content)
# create a letter with that content
l = Letter(student=gs, date=datetime.date.today(), to_lines="The Student\nSFU", template=lt, created_by='ggbaker', content=content)
l.save()
url = reverse('grad.views.view_letter', kwargs={'grad_slug': gs.slug, 'letter_slug': l.slug})
response = basic_page_tests(self, client, url)
self.assertEqual(response.status_code, 200)
url = reverse('grad.views.copy_letter', kwargs={'grad_slug': gs.slug, 'letter_slug': l.slug})
response = basic_page_tests(self, client, url)
self.assertEqual(response.status_code, 200)
示例8: test_pages
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_pages(self):
"""
Test basic page rendering
"""
c = Client()
c.login_user('dzhao')
test_views(self, c, 'ra:', ['search', 'new', 'accounts_index', 'new_account', 'projects_index',
'new_project', 'semester_config', 'browse'], {})
test_views(self, c, 'ra:', ['found'], {}, qs='search=grad')
ra = RAAppointment.objects.filter(unit__label='CMPT')[0]
p = ra.person
test_views(self, c, 'ra:', ['student_appointments', 'new_student'], {'userid': p.userid})
test_views(self, c, 'ra:', ['edit', 'reappoint', 'view',], {'ra_slug': ra.slug})
# No offer text yet, we should get a redirect when trying to edit the letter text:
url = reverse('ra:edit_letter', kwargs={'ra_slug': ra.slug})
response = c.get(url)
self.assertEqual(response.status_code, 302)
# Let's add some offer text and try again.
ra.offer_letter_text='Some test text here'
ra.save()
test_views(self, c, 'ra:', ['edit_letter'], {'ra_slug': ra.slug})
# Make sure we can add attachments
test_views(self, c, 'ra:', ['new_attachment'], {'ra_slug': ra.slug})
acct = Account.objects.filter(unit__label='CMPT')[0]
test_views(self, c, 'ra:', ['edit_account'], {'account_slug': acct.slug})
proj = Project.objects.filter(unit__label='CMPT')[0]
test_views(self, c, 'ra:', ['edit_project'], {'project_slug': proj.slug})
示例9: test_annual_teaching
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [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')
示例10: test_workflow
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [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)
示例11: test_that_grad_search_returns_200_ok
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_that_grad_search_returns_200_ok(self):
"""
Tests that /grad/search is available.
"""
client = Client()
test_auth(client, 'ggbaker')
response = client.get(reverse('grad.views.search'))
self.assertEqual(response.status_code, 200)
示例12: test_planning_admin_returns_403_forbidden
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_planning_admin_returns_403_forbidden(self):
"""
Tests basic page authentication for instructor
"""
raise SkipTest()
client = Client()
client.login_user("ggbaker")
response = client.get(reverse('planning.views.admin_index'))
self.assertEqual(response.status_code, 403)
示例13: test_role_access
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_role_access(self):
r = Role.objects.filter(role='SYSA')[0]
p = r.person
p.config['privacy_signed'] = True
p.config['privacy_da_signed'] = True
p.save()
client = Client()
client.login_user(r.person.userid)
url = reverse('sysadmin:new_role')
# test data role expires in the future: should allow.
resp = client.get(url)
self.assertEqual(resp.status_code, 200)
# expire the role: should now forbid.
r.expiry = date.today() - timedelta(days=2)
r.save()
resp = client.get(url)
self.assertEqual(resp.status_code, 403)
示例14: test_permissions
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_permissions(self):
"""
Make sure the basic permission things are as-expected.
"""
c = Client()
# a role reminder: users with the role, but not others
r = Reminder(reminder_type='ROLE', role='ADVS', unit=Unit.objects.get(slug='cmpt'),
date_type='SEM', week=4, weekday=0,
person=Person.objects.get(userid='ggbaker'), title='Advisor reminder', content='foo',)
r.save()
url = reverse('reminders:view', kwargs={'reminder_slug': r.slug})
c.login_user('ggbaker')
resp = c.get(url)
self.assertEqual(resp.status_code, 404)
c.login_user('dzhao')
resp = c.get(url)
self.assertEqual(resp.status_code, 200)
# a personal reminder: that person only
r = Reminder(reminder_type='PERS',
date_type='YEAR', month='5', day=31,
person=Person.objects.get(userid='ggbaker'), title='Personal reminder',
content='### Heading\n\nfoo *bar*', config={'markup': 'markdown'})
r.save()
url = reverse('reminders:view', kwargs={'reminder_slug': r.slug})
c.login_user('ggbaker')
resp = c.get(url)
self.assertEqual(resp.status_code, 200)
c.login_user('dzhao')
resp = c.get(url)
self.assertEqual(resp.status_code, 404)
# test the HTML generation while we're here
self.assertEqual(r.html_content().replace('\n', ''), '<h3>Heading</h3><p>foo <em>bar</em></p>')
示例15: test_migration_redirect
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import get [as 别名]
def test_migration_redirect(self):
"""
Redirecting after a migration
"""
c = Client()
c.login_user('0aaa0')
# sample pages
crs = self._sample_setup()
# fake the course-has-been-migrated situation
p = crs.page_set.exclude(label='Index').first()
p.config['migrated_to'] = ['2000sp-subj-000-d1', 'PageLabel']
p.can_read = 'ALL'
p.save()
url = reverse('offering:pages:view_page', kwargs={'course_slug': crs.slug, 'page_label': p.label})
# without course setting, shouldn't redirect
resp = c.get(url)
self.assertEqual(resp.status_code, 200)
# instructor said yes to redirects: make sure page redirects
crs.config['redirect_pages'] = True
crs.save()
resp = c.get(url)
self.assertEqual(resp.status_code, 301)
# instructor should see a "this will usually redirect" message
c.login_user('ggbaker')
resp = c.get(url)
self.assertEqual(resp.status_code, 200)
self.assertIn('redirect_url', resp.context)
# make sure prevent_redirect is honoured
c.login_user('0aaa0')
p.config['prevent_redirect'] = True
p.save()
resp = c.get(url)
self.assertEqual(resp.status_code, 200)