本文整理汇总了Python中courselib.testing.Client.login_user方法的典型用法代码示例。如果您正苦于以下问题:Python Client.login_user方法的具体用法?Python Client.login_user怎么用?Python Client.login_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类courselib.testing.Client
的用法示例。
在下文中一共展示了Client.login_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pages
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [as 别名]
def test_pages(self):
offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
student = Member.objects.get(offering=offering, person__userid='0aaa0')
instr = Member.objects.get(offering=offering, person__userid='ggbaker')
c = Client()
c.login_user('ggbaker')
test_views(self, c, 'offering:discipline:', ['index', 'new', 'newgroup', 'new_nonstudent'],
{'course_slug': offering.slug})
cluster = DisciplineGroup(name='TheCluster', offering=offering)
cluster.save()
case = DisciplineCaseInstrStudent(student=student.person, owner=instr.person, offering=offering, group=cluster)
case.save()
test_views(self, c, 'offering:discipline:', ['showgroup'],
{'course_slug': offering.slug, 'group_slug': cluster.slug})
test_views(self, c, 'offering:discipline:', ['show', 'edit_related', 'edit_attach', 'new_file'],
{'course_slug': offering.slug, 'case_slug': case.slug})
# have a look at each form
for step in STEP_FORM:
test_views(self, c, 'offering:discipline:', ['edit_case_info'],
{'course_slug': offering.slug, 'case_slug': case.slug, 'field': step})
# minimally-finish the case so we can check the letter
case.letter_sent = 'MAIL'
case.letter_text = 'foo'
case.save()
test_views(self, c, 'offering:discipline:', ['view_letter'],
{'course_slug': offering.slug, 'case_slug': case.slug})
示例2: test_inaccessible_pages
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [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)
示例3: test_course_credits_admin_200_ok
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [as 别名]
def test_course_credits_admin_200_ok(self):
raise SkipTest()
client = Client()
client.login_user("teachadm")
url = reverse('planning.views.view_insts_in_unit')
response = basic_page_tests(self, client, url)
self.assertEqual(response.status_code, 200)
url = reverse('planning.views.view_teaching_credits_admin', kwargs={'userid': 'ggbaker'})
response = basic_page_tests(self, client, url)
self.assertEqual(response.status_code, 200)
url = reverse('planning.views.view_teaching_equivalent_admin', kwargs={'userid': 'ggbaker', 'equivalent_id': 1})
response = basic_page_tests(self, client, url)
self.assertEqual(response.status_code, 200)
url = reverse('planning.views.new_teaching_equivalent_admin', kwargs={'userid': 'ggbaker'})
response = basic_page_tests(self, client, url)
self.assertEqual(response.status_code, 200)
url = reverse('planning.views.edit_teaching_equivalent_admin', kwargs={'userid': 'ggbaker', 'equivalent_id': 1})
response = basic_page_tests(self, client, url)
self.assertEqual(response.status_code, 200)
url = reverse('planning.views.edit_course_offering_credits', kwargs={'userid': 'ggbaker', 'course_slug': TEST_COURSE_SLUG})
response = basic_page_tests(self, client, url)
self.assertEqual(response.status_code, 200)
示例4: test_course_page
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [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_pages
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [as 别名]
def test_pages(self):
"""
Basic page rendering
"""
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="Index")
p.save()
v = PageVersion(page=p, title="Index Page", wikitext="Original Contents", editor=memb)
v.save()
p = Page(offering=crs, label="OtherPage")
p.save()
v = PageVersion(page=p, title="Other Page", wikitext="Original Contents", editor=memb)
v.save()
c = Client()
c.login_user('ggbaker')
# test the basic rendering of the core pages
test_views(self, c, 'pages.views.', ['index_page', 'all_pages', 'new_page', 'new_file', 'import_site'],
{'course_slug': crs.slug})
test_views(self, c, 'pages.views.', ['view_page', 'page_history', 'edit_page', 'import_page'],
{'course_slug': crs.slug, 'page_label': 'OtherPage'})
示例6: test_new_nonstudent_post_failure
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [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_annual_teaching
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [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')
示例8: test_workflow
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [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)
示例9: test_new_nonstudent_post_success
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [as 别名]
def test_new_nonstudent_post_success(self):
client = Client()
client.login_user("dzhao")
response = client.post(reverse('advisornotes.views.new_nonstudent'), {'first_name': 'test123', 'last_name': 'test_new_nonstudent_post', 'start_year': 2020})
self.assertEqual(response.status_code, 302, 'Should have been redirected')
q = NonStudent.objects.filter(first_name='test123')
self.assertEqual(len(q), 1, "There should only be one result")
self.assertEqual(q[0].last_name, 'test_new_nonstudent_post')
示例10: test_planning_admin_returns_403_forbidden
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [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)
示例11: test_pages
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [as 别名]
def test_pages(self):
"Test a bunch of page views"
offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
activity = Activity.objects.get(offering=offering, slug='rep')
activity.due_date = datetime.datetime.now() + datetime.timedelta(days=1) # make sure it's submittable
activity.save()
client = Client()
# instructor views
client.login_user("ggbaker")
component1 = URL.Component(activity=activity, title='Sample URL 1', description='Please submit some URL.',
check=False, prefix='')
component1.save()
component2 = URL.Component(activity=activity, title='Sample URL 2', description='Please submit some URL.',
check=False, prefix='')
component2.save()
test_views(self, client, 'submission.views.', ['show_components', 'add_component'],
{'course_slug': offering.slug, 'activity_slug': activity.slug})
url = reverse('submission.views.edit_single', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \
+ '?id=' + unicode(component1.id)
basic_page_tests(self, client, url)
url = reverse('submission.views.add_component', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \
+ '?type=url'
basic_page_tests(self, client, url)
# student views: with none, some, and all submitted
client.login_user("0aaa0")
# test various permutations of success to make sure everything returns okay
name1 = '%i-url' % (component1.id)
name2 = '%i-url' % (component2.id)
submissions = [
({}, False),
({name1: '', name2: ''}, False),
({name1: '', name2: 'do i look like a url to you?'}, False),
({name1: 'http://www.sfu.ca/', name2: ''}, False),
({name1: 'http://www.cs.sfu.ca/', name2: 'http://example.com/'}, True),
({name1: 'http://www.sfu.ca/', name2: 'http://example.com/'}, True),
]
for submitdata, redir in submissions:
test_views(self, client, 'submission.views.', ['show_components', 'show_components_submission_history'],
{'course_slug': offering.slug, 'activity_slug': activity.slug})
url = reverse('submission.views.show_components', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug})
response = client.post(url, submitdata)
if redir:
# success: we expect a redirect
self.assertEqual(response.status_code, 302)
else:
# some problems: expect a page reporting that
self.assertEqual(response.status_code, 200)
validate_content(self, response.content, url)
示例12: test_group_submission_view
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [as 别名]
def test_group_submission_view(self):
"""
test if group submission can be viewed by group member and non group member
"""
now = datetime.datetime.now()
_, course = create_offering()
a1 = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=course, position=2, max_grade=15, due_date=now, group=True)
a1.save()
a2 = NumericActivity(name="Assignment 2", short_name="A2", status="RLS", offering=course, position=1, max_grade=15, due_date=now, group=True)
a2.save()
p = Person.objects.get(userid="ggbaker")
member = Member(person=p, offering=course, role="INST", career="NONS", added_reason="UNK")
member.save()
c1 = URL.Component(activity=a1, title="URL Link", position=8)
c1.save()
c2 = Archive.Component(activity=a1, title="Archive File", position=1, max_size=100000)
c2.save()
c3 = Code.Component(activity=a1, title="Code File", position=3, max_size=2000, allowed=".py")
c3.save()
userid1 = "0aaa0"
userid2 = "0aaa1"
userid3 = "0aaa2"
for u in [userid1, userid2,userid3]:
p = Person.objects.get(userid=u)
m = Member(person=p, offering=course, role="STUD", credits=3, career="UGRD", added_reason="UNK")
m.save()
m = Member.objects.get(person__userid=userid1, offering=course)
g = Group(name="Test Group", manager=m, courseoffering=course)
g.save()
gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
gm.save()
gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
gm.save()
m = Member.objects.get(person__userid=userid2, offering=course)
gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
gm.save()
gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
gm.save()
m = Member.objects.get(person__userid=userid3, offering=course)
gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
gm.save()
client = Client()
# login as "0aaa0", member of group : test_group for assignment1 and assgnment2
client.login_user("0aaa0")
#submission page for assignment 1
url = reverse('submission.views.show_components', kwargs={'course_slug': course.slug,'activity_slug':a1.slug})
response = basic_page_tests(self, client, url)
self.assertContains(response, "This is a group submission. You will submit on behalf of the group Test Group.")
self.assertContains(response, "You haven't made a submission for this component.")
示例13: test_staff_page
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [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)
示例14: test_upload
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [as 别名]
def test_upload(self):
_, course = create_offering()
a1 = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=course, position=2, max_grade=15, due_date=datetime.datetime.now() + datetime.timedelta(hours=1), group=False)
a1.save()
p = Person.objects.get(userid="ggbaker")
member = Member(person=p, offering=course, role="INST", career="NONS", added_reason="UNK")
member.save()
c = Code.Component(activity=a1, title="Code File", position=3, max_size=2000, allowed=".py")
c.save()
userid1 = "0aaa0"
userid2 = "0aaa1"
userid3 = "0aaa2"
for u in [userid1, userid2,userid3]:
p = Person.objects.get(userid=u)
m = Member(person=p, offering=course, role="STUD", credits=3, career="UGRD", added_reason="UNK")
m.save()
# submit as student
client = Client()
client.login_user("0aaa0")
url = reverse('submission.views.show_components', kwargs={'course_slug': course.slug,'activity_slug':a1.slug})
response = basic_page_tests(self, client, url)
# submit a file
tmpf = tempfile.NamedTemporaryFile(suffix=".py", delete=False)
codecontents = 'print "Hello World!"\n'
tmpf.write(codecontents)
tmpf.close()
try:
fh = open(tmpf.name, "r")
data = {"%i-code" % (c.id): fh}
response = client.post(url, data)
self.assertEquals(response.status_code, 302)
finally:
os.unlink(tmpf.name)
# make sure it's there and correct
subs = StudentSubmission.objects.all()
self.assertEquals(len(subs), 1)
sub = subs[0]
self.assertEquals(sub.member.person.userid, '0aaa0')
codes = SubmittedCode.objects.all()
self.assertEquals(len(codes), 1)
code = codes[0]
code.code.open()
self.assertEquals(code.code.read(), codecontents)
示例15: test_ajax
# 需要导入模块: from courselib.testing import Client [as 别名]
# 或者: from courselib.testing.Client import login_user [as 别名]
def test_ajax(self):
client = Client()
call_command('update_index', 'coredata', verbosity=0) # make sure we have the same data in DB and haystack
# test person autocomplete
client.login_user("dzhao")
p = Person.objects.get(userid='ggbaker')
url = reverse('data:student_search')
response = client.get(url, {'term': 'ggba'})
self.assertEqual(response.status_code, 200)
self.assertEqual(response['content-type'], 'application/json')
# should find this person
data = json.loads(response.content.decode('utf8'))
emplids = [str(d['value']) for d in data]
self.assertIn(str(p.emplid), emplids)