本文整理汇总了Python中devilry.utils.rest_testclient.RestClient.login方法的典型用法代码示例。如果您正苦于以下问题:Python RestClient.login方法的具体用法?Python RestClient.login怎么用?Python RestClient.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类devilry.utils.rest_testclient.RestClient
的用法示例。
在下文中一共展示了RestClient.login方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestRestAssignmentListing
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestAssignmentListing(TestCase):
def setUp(self):
self.testhelper = TestHelper()
#self.testhelper.add(nodes='uni:admin(uniadmin)',
#subjects=['duck2000:admin(adminone,admintwo):ln(Something fancy)',
#'duck3000',
#'duck1000:admin(adminone)',
#'duck4000:admin(adminone,admintwo,singleadmin)'])
self.client = RestClient()
def _get(self, **data):
return self.client.rest_get(reverse('devilry_examiner-rest-assignmentlisting'), **data)
def _getas(self, username, **data):
self.client.login(username=username, password='test')
return self._get(**data)
def test_get(self):
self.testhelper.create_user('examiner1')
content, response = self._getas('examiner1')
self.assertEquals(response.status_code, 200)
self.assertEquals(content, ['Hello', 'world'])
def test_get_noauth(self):
content, response = self._get()
self.assertEquals(response.status_code, 401)
示例2: TestLanguageSelect
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestLanguageSelect(TestCase):
def setUp(self):
self.client = RestClient()
self.url = '/devilry_i18n/rest/languageselect'
self.testhelper = TestHelper()
self.testhelper.create_user('testuser')
def _getas(self, username):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url)
def _get_languagecode(self, username):
user = User.objects.get(username=username)
return user.devilryuserprofile.languagecode
def _set_languagecode(self, username, languagecode):
profile = User.objects.get(username=username).devilryuserprofile
profile.languagecode = languagecode
profile.save()
def test_get_languagecode_none(self):
self.assertEquals(self._get_languagecode('testuser'), None)
content, response = self._getas('testuser')
self.assertEquals(response.status_code, 200)
self.assertEquals(content['preferred'], None)
self.assertEquals(content['selected']['languagecode'],
settings.LANGUAGE_CODE)
def test_get_languagecode_set(self):
self._set_languagecode('testuser', 'nb')
content, response = self._getas('testuser')
self.assertEquals(response.status_code, 200)
self.assertEquals(content['preferred'], 'nb')
self.assertEquals(content['selected']['languagecode'], 'nb')
def _putas(self, username, data):
self.client.login(username=username, password='test')
return self.client.rest_put(self.url, data)
def test_put(self):
content, response = self._putas('testuser', {'preferred': 'nb'})
self.assertEquals(response.status_code, 200)
self.assertEquals(content['preferred'], 'nb')
self.assertEquals(self._get_languagecode('testuser'), 'nb')
def test_put_invalid(self):
content, response = self._putas('testuser', {'preferred': 'invalid-code'})
self.assertEquals(response.status_code, 400)
self.assertEquals(content['field_errors']['preferred'],
[u'Invalid languagecode: invalid-code'])
def test_put_with_extradata(self):
content, response = self._putas('testuser', {'preferred': 'nb',
'selected': {'ignored': 'data'},
'available': ['ignored']})
self.assertEquals(response.status_code, 200)
self.assertEquals(content['preferred'], 'nb')
self.assertEquals(self._get_languagecode('testuser'), 'nb')
示例3: TestRestAggregatedStudentInfo
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestAggregatedStudentInfo(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.client = RestClient()
self.testhelper.add(nodes='uni:admin(uniadmin)',
subjects=['sub'],
periods=['p1:begins(-1)'],
assignments=['a1'])
self.testhelper.add_to_path('uni;sub.p1.a1.g1:candidate(student1,student2):examiner(examiner1).d1:ends(5)')
self.group = self.testhelper.sub_p1_a1_g1
def _get(self, user_id):
return self.client.rest_get(reverse('devilry_nodeadmin-aggregatedstudentinfo', kwargs={'user_id': user_id}))
def _getas(self, username, id):
self.client.login(username=username, password='test')
return self._get(id)
def test_get(self):
content, response = self._getas('uniadmin', self.testhelper.student1.id)
self.assertEquals(response.status_code, 200)
user = {u'username': u'student1',
u'displayname': u'student1',
u'id': 2, u'full_name': None,
u'email': u'[email protected]'}
self.assertEquals(content['user'], user)
grouped_by_hierarky = content['grouped_by_hierarky'][0]
self.assertEquals(set(grouped_by_hierarky.keys()), set([u'long_name', u'id', u'short_name', u'periods']))
period = grouped_by_hierarky['periods'][0]
self.assertEquals(set(period.keys()), set([u'short_name', u'assignments',
u'is_relatedstudent', u'start_time',
u'is_active', u'qualified_forexams',
u'long_name', u'end_time', u'id']))
assignments = period['assignments'][0]
self.assertEquals(set(period.keys()), set([u'short_name', u'assignments',
u'is_relatedstudent', u'start_time',
u'is_active', u'qualified_forexams',
u'long_name', u'end_time', u'id']))
groups = assignments['groups'][0]
self.assertEquals(set(groups.keys()), set([u'status', u'active_feedback', u'id']))
def test_get_noauth(self):
content, response = self._get(self.testhelper.student1.id)
self.assertEquals(response.status_code, 401)
示例4: TestRestRecentDeliveries
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestRecentDeliveries(TestCase):
def setUp(self):
self.client = RestClient()
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['p1:begins(-1)'],
assignments=['a1'])
self.testhelper.add_to_path('uni;sub.p1.a1.g1:candidate(student1).d1')
self.group = self.testhelper.sub_p1_a1_g1
self.url = '/devilry_student/rest/recent-deliveries/'
def _getas(self, username):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url)
def test_nobody(self):
fileinfo = {'ok.py': ['print ', 'meh']}
self.testhelper.add_delivery('sub.p1.a1.g1', fileinfo)
self.testhelper.create_user('nobody')
content, response = self._getas('nobody')
self.assertEquals(response.status_code, 200)
self.assertEquals(content, [])
def test_recent_deliveries_minimal(self):
fileinfo = {'ok.py': ['print ', 'meh']}
self.testhelper.add_delivery('sub.p1.a1.g1', fileinfo)
content, response = self._getas('student1')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
self.assertEquals(set(content[0].keys()),
set(['id', 'assignment', 'period', 'subject',
'time_of_delivery', 'group', 'number']))
assignment = self.group.parentnode
period = self.group.parentnode.parentnode
subject = self.group.parentnode.parentnode.parentnode
self.assertEquals(content[0]['assignment'],
{u'id': assignment.id, u'long_name': u'A1', u'short_name': u'a1'})
self.assertEquals(content[0]['period'],
{u'id': period.id, u'long_name': u'P1', u'short_name': u'p1'})
self.assertEquals(content[0]['subject'],
{u'id': subject.id, u'long_name': u'Sub', u'short_name': u'sub'})
def test_recent_deliveries_over10(self):
fileinfo = {'ok.py': ['print ', 'meh']}
for x in xrange(8):
self.testhelper.add_delivery('sub.p1.a1.g1', fileinfo)
content, response = self._getas('student1')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 6)
示例5: TestRestFindGroups
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestFindGroups(TestCase):
def setUp(self):
self.client = RestClient()
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['p0:begins(-10):ends(2)',
'p1:begins(-1)',
'p2:begins(5)'],
assignments=['a1'])
self.testhelper.create_user('testuser')
self.url = '/devilry_student/rest/find-groups/'
def _getas(self, username, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url, **data)
def test_find_groups_empty(self):
content, response = self._getas('testuser')
self.assertEquals(response.status_code, 200)
self.assertEquals(content, [])
def test_find_groups(self):
# Add to the past period (should show up)
self.testhelper.add_to_path('uni;sub.p0.a1.gOld:candidate(student1).d1')
# Add to the active period (show show up)
self.testhelper.add_to_path('uni;sub.p1.a1.g1:candidate(student1).d1')
self.testhelper.add_to_path('uni;sub.p1.a1.g2:candidate(student1,student2).d1')
# Add to the future period (should not show up)
self.testhelper.add_to_path('uni;sub.p2.a1.gFut:candidate(student1).d1')
content, response = self._getas('student1', query='sub')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 3)
self.assertEquals(set(content[0].keys()),
set(['id', 'name', 'assignment', 'period', 'subject']))
groupnames = set([group['name'] for group in content])
self.assertEquals(groupnames, set(['g1', 'g2', 'gOld']))
content, response = self._getas('student1', query='old')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
content, response = self._getas('student1', query='p1 g2')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
self.assertEquals(content[0]['name'], 'g2')
示例6: TestRestRecentFeedbacks
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestRecentFeedbacks(TestCase):
def setUp(self):
self.client = RestClient()
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['p1:begins(-1)'],
assignments=['a1'])
self.testhelper.add_to_path('uni;sub.p1.a1.g1:candidate(student1):examiner(examiner1).d1')
self.group = self.testhelper.sub_p1_a1_g1
self.url = '/devilry_student/rest/recent-feedbacks/'
def _getas(self, username):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url)
def test_nobody(self):
fileinfo = {'ok.py': ['print ', 'meh']}
self.testhelper.add_delivery('sub.p1.a1.g1', fileinfo)
self.testhelper.create_user('nobody')
content, response = self._getas('nobody')
self.assertEquals(response.status_code, 200)
self.assertEquals(content, [])
def test_recent_feedbacks_minimal(self):
fileinfo = {'ok.py': ['print ', 'meh']}
delivery = self.testhelper.add_delivery('sub.p1.a1.g1', fileinfo)
self.testhelper.add_feedback(delivery,
verdict={'grade': 'F', 'points': 30, 'is_passing_grade': False})
content, response = self._getas('student1')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
self.assertEquals(set(content[0].keys()),
set(['id', 'assignment', 'period', 'subject',
'number', 'last_feedback', 'group']))
def test_recent_deliveries_overflow(self):
fileinfo = {'ok.py': ['print ', 'meh']}
for x in xrange(8):
delivery = self.testhelper.add_delivery('sub.p1.a1.g1', fileinfo)
self.testhelper.add_feedback(delivery,
verdict={'grade': '{0}/100'.format(x), 'points': x, 'is_passing_grade': False})
content, response = self._getas('student1')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 6)
示例7: TestRestPreview
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestPreview(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni:admin(uniadmin)',
subjects=['sub'],
periods=['p1:admin(periodadmin):begins(-3):ends(6)'])
self.client = RestClient()
self.testhelper.create_superuser('superuser')
def _get_url(self, periodid):
return reverse('devilry_qualifiesforexam-rest-preview', kwargs={'id': periodid})
def _getas(self, username, periodid, previewdata, pluginsessionid='tst'):
self.client.login(username=username, password='test')
session = self.client.session
session['qualifiesforexam-{0}'.format(pluginsessionid)] = previewdata
session.save()
return self.client.rest_get(self._get_url(periodid),
pluginsessionid=pluginsessionid)
def _test_getas(self, username):
content, response = self._getas(username, self.testhelper.sub_p1.id,
PreviewData(passing_relatedstudentids=[1, 2, 4]))
self.assertEqual(response.status_code, 200)
self.assertEqual(set(content.keys()), set(['pluginoutput', 'perioddata']))
self.assertEqual(content['pluginoutput'],
{u'passing_relatedstudentids': [1, 2, 4]})
def test_get_as_periodadmin(self):
self._test_getas('periodadmin')
def test_get_as_nodeadmin(self):
self._test_getas('uniadmin')
def test_get_as_superuser(self):
self._test_getas('superuser')
def test_getas_nobody(self):
self.testhelper.create_user('nobody')
content, response = self._getas('nobody', self.testhelper.sub_p1.id,
PreviewData(passing_relatedstudentids=[]))
self.assertEqual(response.status_code, 403)
def test_get_invalid_period(self):
periodid = 10000
self.assertFalse(Period.objects.filter(id=periodid).exists()) # Just to be sure we dont get false positives
content, response = self._getas('periodadmin', periodid, PreviewData(passing_relatedstudentids=[]))
self.assertEqual(response.status_code, 403)
示例8: TestRestAggregatedGroupInfo
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestAggregatedGroupInfo(TestCase):
def setUp(self):
self.client = RestClient()
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['p1:begins(-1)'],
assignments=['a1:admin(a1admin)'])
self.testhelper.add_to_path('uni;sub.p1.a1.g1:candidate(student1,student2):examiner(examiner1).d1:ends(5)')
self.testhelper.add_to_path('uni;sub.p1.a1.g1.d2:ends(10)')
self.group = self.testhelper.sub_p1_a1_g1
self.url = '/devilry_subjectadmin/rest/aggregated-groupinfo/{0}'.format(self.group.id)
def _getas(self, username):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url)
def test_nobody(self):
self.testhelper.create_user('nobody')
content, response = self._getas('nobody')
self.assertEquals(response.status_code, 403)
def test_groupinfo(self):
content, response = self._getas('a1admin')
self.assertEquals(response.status_code, 200)
self.assertEquals(set(content.keys()),
set(['id', 'deadlines']))
self.assertEquals(content['id'], self.group.id)
def test_groupinfo_superuser(self):
self.testhelper.create_superuser('superuser')
content, response = self._getas('superuser')
self.assertEquals(response.status_code, 200)
self.assertEquals(set(content.keys()),
set(['id', 'deadlines']))
self.assertEquals(content['id'], self.group.id)
def test_deadlines(self):
content, response = self._getas('a1admin')
deadlines = content['deadlines']
self.assertEquals(len(deadlines), 2)
self.assertEquals(set(deadlines[0].keys()),
set(['id', 'deadline', 'deliveries', 'text',
'offset_from_now', 'in_the_future']))
示例9: TestRestDetailedPeriodOverview
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestDetailedPeriodOverview(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni:admin(uniadmin)',
subjects=['sub'],
periods=['p1:admin(periodadmin):begins(-3):ends(6)'])
self.client = RestClient()
self.testhelper.create_superuser('superuser')
def _get_url(self, periodid):
return reverse('devilry-subjectadmin-rest-detailedperiodoverview', kwargs={'id': periodid})
def _getas(self, username, periodid):
self.client.login(username=username, password='test')
return self.client.rest_get(self._get_url(periodid))
def _test_get_as(self, username):
content, response = self._getas(username, self.testhelper.sub_p1.id)
self.assertEqual(response.status_code, 200)
# NOTE: This is tested in more detail in the API that generates the data (devilry.utils.groups_groupedby_relatedstudent_and_assignment)
self.assertEqual(set(content.keys()),
set([u'students_with_feedback_that_is_candidate_but_not_in_related',
u'students_with_no_feedback_that_is_candidate_but_not_in_related',
u'relatedstudents', u'assignments']))
def test_getlist_as_periodadmin(self):
self._test_get_as('periodadmin')
def test_getlist_as_nodeadmin(self):
self._test_get_as('uniadmin')
def test_getlist_as_superuser(self):
self._test_get_as('superuser')
def test_get_as_nobody(self):
self.testhelper.create_user('nobody')
content, response = self._getas('nobody', self.testhelper.sub_p1.id)
self.assertEqual(response.status_code, 403)
def test_get_invalid_id(self):
content, response = self._getas('periodadmin', 10000)
self.assertEqual(response.status_code, 403)
示例10: TestRestSearchStudentContent
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestSearchStudentContent(TestCase, AssertSearchResultMixin):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni:ln(Test Uni)',
subjects=['sub:ln(Test Sub)'],
periods=['p1:begins(-2):ln(Test P1)'],
assignments=['a1:ln(Test A1)'],
assignmentgroups=[
'TestGroup1:candidate(student1)',
'TestGroup2:candidate(student2,student1)',
'TestGroup3:candidate(student2)',
'TestGroup4:candidate(student3):examiner(student1)'
]
)
self.client = RestClient()
self.url = reverse('devilry_search_studentcontent')
def _getas(self, username, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url, **data)
def test_perms_student(self):
with HaystackTestSettings():
content, response = self._getas('student1', search='Test')
matches = content['matches']
self.assertEqual(len(matches), 2)
self.assert_has_search_result(matches, type='core_assignmentgroup',
title='Test A1', name='TestGroup1')
self.assert_has_search_result(matches, type='core_assignmentgroup',
title='Test A1', name='TestGroup2')
def test_perms_student_unpublished(self):
self.testhelper.sub_p1_a1.publishing_time = datetime.now() + timedelta(days=1)
self.testhelper.sub_p1_a1.save()
with HaystackTestSettings():
content, response = self._getas('student1', search='Test')
matches = content['matches']
self.assertEqual(len(matches), 0)
示例11: TestRestExaminerStats
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestExaminerStats(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni:admin(uniadmin)',
subjects=['sub'],
periods=['p1:begins(-3):ends(6)'],
assignments=['a1:admin(assignmentadmin)']
)
self.client = RestClient()
self.testhelper.create_superuser('superuser')
def _get_url(self, assignmentid):
return reverse('devilry-subjectadmin-rest-examinerstats', kwargs={'id': assignmentid})
def _getas(self, username, periodid):
self.client.login(username=username, password='test')
return self.client.rest_get(self._get_url(periodid))
def _test_get_as(self, username):
content, response = self._getas(username, self.testhelper.sub_p1_a1.id)
self.assertEqual(response.status_code, 200)
def test_perms_as_assignmentadmin(self):
self._test_get_as('assignmentadmin')
def test_perms_as_nodeadmin(self):
self._test_get_as('uniadmin')
def test_perms_as_superuser(self):
self._test_get_as('superuser')
def test_perms_as_nobody(self):
self.testhelper.create_user('nobody')
content, response = self._getas('nobody', self.testhelper.sub_p1_a1.id)
self.assertEqual(response.status_code, 403)
def test_perms_invalid_id(self):
content, response = self._getas('assignmentadmin', 10000)
self.assertEqual(response.status_code, 403)
示例12: TestRestToplevelNodeListing
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestToplevelNodeListing(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes="uni:admin(uniadmin).inf:admin(infadmin)")
self.testhelper.add(nodes="uni.fys:admin(fysadmin)")
self.testhelper.add(nodes="uni.fys2:admin(fysadmin)")
self.client = RestClient()
def _geturl(self):
return reverse("devilry_nodeadmin-rest_toplevel_nodes")
def test_get_as_nodeadmin(self):
self.client.login(username="infadmin", password="test")
content, response = self.client.rest_get(self._geturl())
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
self.assertEquals(content[0]["short_name"], "inf")
def test_multiget_as_nodeadmin(self):
self.client.login(username="fysadmin", password="test")
content, response = self.client.rest_get(self._geturl())
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 2)
self.assertEquals([n["short_name"] for n in content], ["fys", "fys2"])
def test_get_as_superuser(self):
self.testhelper.create_superuser("super")
self.client.login(username="super", password="test")
content, response = self.client.rest_get(self._geturl())
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
self.assertEquals(content[0]["short_name"], "uni")
def test_nodata(self):
self.testhelper.create_user("nobody")
self.client.login(username="nobody", password="test")
content, response = self.client.rest_get(self._geturl())
self.assertEquals(response.status_code, 200)
self.assertEquals(content, [])
示例13: TestRestSearchAdminContent
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestSearchAdminContent(TestCase, AssertSearchResultMixin):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni:admin(uniadmin):ln(Test Uni)',
subjects=['sub:admin(subadmin):ln(Test Sub)'],
periods=['p1:begins(-2):admin(p1admin):ln(Test P1)'],
assignments=['a1:admin(a1admin):ln(Test A1)'],
assignmentgroups=['TestGroup1:candidate(student1)']
)
self.client = RestClient()
self.url = reverse('devilry_search_admincontent')
def _getas(self, username, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url, **data)
def _test_perms_topnodeorsuper(self, username):
with HaystackTestSettings():
content, response = self._getas(username, search='Test')
matches = content['matches']
self.assertEqual(len(matches), 5)
self.assert_has_search_result(matches, type='core_node', title='Test Uni')
self.assert_has_search_result(matches, type='core_subject', title='Test Sub')
self.assert_has_search_result(matches, type='core_period', title='Test P1')
self.assert_has_search_result(matches, type='core_assignment', title='Test A1')
self.assert_has_search_result(matches, type='core_assignmentgroup',
title='Test A1', students=['student1'])
def test_perms_uniadmin(self):
self._test_perms_topnodeorsuper('uniadmin')
def test_perms_superuser(self):
self.testhelper.create_superuser('superuser')
self._test_perms_topnodeorsuper('superuser')
def test_perms_subjectadmin(self):
with HaystackTestSettings():
content, response = self._getas('subadmin', search='Test')
matches = content['matches']
self.assertEqual(len(matches), 4)
self.assert_has_search_result(matches, type='core_subject', title='Test Sub')
self.assert_has_search_result(matches, type='core_period', title='Test P1')
self.assert_has_search_result(matches, type='core_assignment', title='Test A1')
self.assert_has_search_result(matches, type='core_assignmentgroup',
title='Test A1', students=['student1'])
def test_perms_periodadmin(self):
with HaystackTestSettings():
content, response = self._getas('p1admin', search='Test')
matches = content['matches']
self.assertEqual(len(matches), 3)
self.assert_has_search_result(matches, type='core_period', title='Test P1')
self.assert_has_search_result(matches, type='core_assignment', title='Test A1')
self.assert_has_search_result(matches, type='core_assignmentgroup',
title='Test A1', students=['student1'])
def test_perms_assignmentadmin(self):
with HaystackTestSettings():
content, response = self._getas('a1admin', search='Test')
matches = content['matches']
self.assertEqual(len(matches), 2)
self.assert_has_search_result(matches, type='core_assignment', title='Test A1')
self.assert_has_search_result(matches, type='core_assignmentgroup',
title='Test A1', students=['student1'])
示例14: TestRestAllWhereIsAdmin
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestRestAllWhereIsAdmin(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.client = RestClient()
self.url = '/devilry_subjectadmin/rest/allwhereisadmin/'
def _listas(self, username, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url, **data)
def test_list_emptysubject(self):
self.testhelper.add(nodes='uni',
subjects=['duck2000:admin(adm)'])
content, response = self._listas('adm')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
self.assertEquals(content[0]['short_name'], 'duck2000')
def test_list_emptyperiod(self):
self.testhelper.add(nodes='uni',
subjects=['duck2000:admin(adm)'],
periods=['p1'])
content, response = self._listas('adm')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
self.assertEquals(content[0]['short_name'], 'duck2000')
self.assertEquals(content[0]['is_admin'], True)
self.assertEquals(len(content[0]['periods']), 1)
self.assertEquals(content[0]['periods'][0]['short_name'], 'p1')
self.assertEquals(content[0]['periods'][0]['is_admin'], False)
self.testhelper.add(nodes='uni',
subjects=['duck3000'],
periods=['p1:admin(adm)'])
content, response = self._listas('adm')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 2)
def test_list_nobody(self):
self.testhelper.create_user('nobody')
self.testhelper.add(nodes='uni',
subjects=['duck2000'])
content, response = self._listas('nobody')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 0)
def test_list(self):
self.testhelper.add(nodes='uni',
subjects=['duck2000:admin(adm)', 'duck3000', 'duck4000'])
self.testhelper.add_to_path('uni;duck2000.p2000')
self.testhelper.add_to_path('uni;duck3000.p3000:admin(adm)')
self.testhelper.add_to_path('uni;duck4000.p4000.a1:admin(adm)')
content, response = self._listas('adm')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 3)
self.assertEquals(content[0]['short_name'], 'duck2000')
self.assertEquals(content[0]['is_admin'], True)
self.assertEquals(content[0]['can_administer'], True)
self.assertEquals(len(content[0]['periods']), 1)
self.assertEquals(content[0]['periods'][0]['short_name'], 'p2000')
self.assertEquals(content[0]['periods'][0]['can_administer'], True)
self.assertEquals(content[0]['periods'][0]['is_admin'], False)
self.assertEquals(content[1]['short_name'], 'duck3000')
self.assertEquals(content[1]['is_admin'], False)
self.assertEquals(content[1]['can_administer'], False)
self.assertEquals(len(content[1]['periods']), 1)
self.assertEquals(content[1]['periods'][0]['short_name'], 'p3000')
self.assertEquals(content[1]['periods'][0]['can_administer'], True)
self.assertEquals(content[1]['periods'][0]['is_admin'], True)
self.assertEquals(content[2]['short_name'], 'duck4000')
self.assertEquals(content[2]['is_admin'], False)
self.assertEquals(content[2]['can_administer'], False)
self.assertEquals(len(content[2]['periods']), 1)
self.assertEquals(content[2]['periods'][0]['can_administer'], False)
self.assertEquals(content[2]['periods'][0]['is_admin'], False)
self.assertEquals(len(content[2]['periods'][0]['assignments']), 1)
self.assertEquals(content[2]['periods'][0]['short_name'], 'p4000')
self.assertEquals(content[2]['periods'][0]['assignments'][0]['can_administer'], True)
self.assertEquals(content[2]['periods'][0]['assignments'][0]['is_admin'], True)
def test_list_active_noassignments(self):
self.testhelper.add(nodes='uni',
subjects=['duck2000:admin(adm)'],
periods=['p1:begins(-20)', 'p2:begins(-1)', 'p3:begins(20)'])
content, response = self._listas('adm', only_active='yes')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
self.assertEquals(content[0]['short_name'], 'duck2000')
self.assertEquals(len(content[0]['periods']), 1)
self.assertEquals(content[0]['periods'][0]['short_name'], 'p2')
def test_list_active(self):
self.testhelper.add(nodes='uni',
subjects=['duck2000:admin(adm)'],
periods=['p1:begins(-20)', 'p2:begins(-1)', 'p3:begins(20)'],
assignments=['a1'])
#.........这里部分代码省略.........
示例15: TestCreateGroupRest
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import login [as 别名]
class TestCreateGroupRest(TestCase, GroupManagerTestMixin):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['p1'],
assignments=['a1:admin(a1admin)'])
self.client = RestClient()
self.testhelper.create_user('candidate1')
self.testhelper.create_user('examiner1')
self.testhelper.create_superuser('grandma')
self.a1id = self.testhelper.sub_p1_a1.id
def _geturl(self, assignment_id):
return '/devilry_subjectadmin/rest/group/{0}/'.format(assignment_id)
def _postas(self, username, assignment_id, data={}):
self.client.login(username=username, password='test')
return self.client.rest_post(self._geturl(assignment_id), data)
def test_create_minimal(self):
data = {'name': 'g1',
'is_open': False}
content, response = self._postas('a1admin', self.a1id, data)
self.assertEquals(response.status_code, 201)
self.assertEquals(set(content.keys()),
set(['name', 'id', 'etag', 'is_open', 'parentnode',
'feedback', 'deadlines', 'candidates', 'tags',
'examiners', 'num_deliveries']))
self.assertEquals(content['name'], 'g1')
self.assertEquals(content['is_open'], False)
self.assertEquals(content['parentnode'], self.a1id)
self.assertEquals(content['num_deliveries'], 0)
self.assertEquals(content['feedback'], None)
self.assertEquals(content['deadlines'], [])
self.assertEquals(content['candidates'], [])
self.assertEquals(content['examiners'], [])
self.assertEquals(content['tags'], [])
groups = self.testhelper.sub_p1_a1.assignmentgroups.all()
self.assertEquals(len(groups), 1)
self.assertEquals(content['id'], groups[0].id)
def _test_create_as(self, username):
data = {'name': 'g1',
'is_open': False,
'examiners': [self.create_examinerdict(username='examiner1')],
'candidates': [self.create_candidatedict(username='candidate1')],
'tags': [self.create_tagdict('mytag')]}
content, response = self._postas(username, self.a1id, data)
#from pprint import pprint
#print 'Response content:'
#pprint(content)
self.assertEquals(response.status_code, 201)
self.assertEquals(content['name'], 'g1')
self.assertEquals(content['is_open'], False)
self.assertEquals(content['parentnode'], self.a1id)
self.assertEquals(content['num_deliveries'], 0)
# Feedback
self.assertEquals(content['feedback'], None)
# Deadlines
self.assertEquals(content['deadlines'], [])
# Tags
self.assertEquals(len(content['tags']), 1)
tag = content['tags'][0]
self.assertEquals(tag['tag'], 'mytag')
self.assertEquals(set(tag.keys()), set(['id', 'tag']))
# Examiners
self.assertEquals(len(content['examiners']), 1)
examiner = content['examiners'][0]
self.assertEquals(set(examiner.keys()),
set(['id', 'user']))
self.assertEquals(set(examiner['user'].keys()),
set(['email', 'full_name', 'id', 'username']))
self.assertEquals(examiner['user']['id'], self.testhelper.examiner1.id)
self.assertEquals(examiner['user']['username'], 'examiner1')
# Candidates
self.assertEquals(len(content['candidates']), 1)
candidate = content['candidates'][0]
self.assertEquals(set(candidate.keys()),
set(['id', 'user', 'candidate_id']))
self.assertEquals(set(candidate['user'].keys()),
set(['email', 'full_name', 'id', 'username']))
self.assertEquals(candidate['user']['id'], self.testhelper.candidate1.id)
self.assertEquals(candidate['candidate_id'], '')
self.assertEquals(candidate['user']['username'], 'candidate1')
# It was actually created?
groups = self.testhelper.sub_p1_a1.assignmentgroups.all()
self.assertEquals(len(groups), 1)
self.assertEquals(content['id'], groups[0].id)
#.........这里部分代码省略.........