本文整理汇总了Python中devilry.devilry_rest.testclient.RestClient.login方法的典型用法代码示例。如果您正苦于以下问题:Python RestClient.login方法的具体用法?Python RestClient.login怎么用?Python RestClient.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类devilry.devilry_rest.testclient.RestClient
的用法示例。
在下文中一共展示了RestClient.login方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestLanguageSelect
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_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')
示例2: TestRestAggregatedStudentInfo
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_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)
示例3: TestRestPreview
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_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.serialize()
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)
示例4: TestRestAggregatedGroupInfo
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_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']))
示例5: TestRestDetailedPeriodOverview
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_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)
示例6: TestRestSearchStudentContent
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_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)
示例7: TestRestExaminerStats
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_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)
示例8: TestRestToplevelNodeListing
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_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, [])
示例9: TestListRelatedUserOnAssignmentMixin
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import login [as 别名]
class TestListRelatedUserOnAssignmentMixin(object):
def setUp(self):
self.client = RestClient()
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['p1'],
assignments=['a1:admin(a1admin)',
'a2:admin(a2admin)'])
self.testhelper.add_to_path('uni;sub.p2')
self.testhelper.create_superuser("superuser")
self.testhelper.create_user('testuser')
def get_url(self):
"""
Get url of rest API.
"""
raise NotImplementedError()
def _listas(self, username, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self.get_url(), **data)
def _create_user(self, index):
username = "reluser{0}".format(index)
user = self.testhelper.create_user(username)
user.email = username + '@example.com'
user.devilryuserprofile.full_name = 'User {0}'.format(index)
user.save()
user.devilryuserprofile.save()
return user
def create_relateduser(self, period, index, tags=''):
"""
Create a related user of the type that we are testing.
"""
raise NotImplementedError()
def _create_relatedusers(self, count):
for index in xrange(count):
self.create_relateduser(self.testhelper.sub_p1, index)
def test_list(self):
self._create_relatedusers(2)
self.create_relateduser(self.testhelper.sub_p1, index=5, tags='group1,group2')
self.create_relateduser(self.testhelper.sub_p2, index=20, tags='') # Not on p1, so we shold not get this in the listing!
content, response = self._listas(self.testhelper.a1admin, period=self.testhelper.sub_p1.id)
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 3) # Since this is 3, we did not get the user registered on p2.
first, second, last = content
self.assertEquals(first['user']['username'], 'reluser0')
self.assertEquals(first['user']['full_name'] , 'User 0')
self.assertEquals(first['tags'], '')
self.assertEquals(second['tags'], '')
self.assertEquals(second['user']['username'], 'reluser1')
self.assertEquals(last['user']['username'], 'reluser5')
self.assertEquals(last['tags'], 'group1,group2')
return content
def test_list_none(self):
content, response = self._listas(self.testhelper.a1admin, period=self.testhelper.sub_p1.id)
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 0)
def test_list_superuser(self):
self._create_relatedusers(2)
content, response = self._listas(self.testhelper.superuser, period=self.testhelper.sub_p1.id)
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 2)
def test_list_not_admin(self):
self._create_relatedusers(2)
content, response = self._listas(self.testhelper.a2admin, period=self.testhelper.sub_p1.id)
self.assertEquals(response.status_code, 403)
示例10: TestListOrCreateRelatedUserMixin
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import login [as 别名]
class TestListOrCreateRelatedUserMixin(object):
def setUp(self):
self.client = RestClient()
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['p1:admin(p1admin)', 'p2:admin(p2admin)'])
self.testhelper.create_superuser("superuser")
self.testhelper.create_user('testuser')
def get_url(self):
"""
Get url of rest API.
"""
raise NotImplementedError()
def _listas(self, username, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self.get_url(), **data)
def _create_user(self, index):
username = "reluser{0}".format(index)
user = self.testhelper.create_user(username)
user.email = username + '@example.com'
user.devilryuserprofile.full_name = 'User {0}'.format(index)
user.save()
user.devilryuserprofile.save()
return user
def create_relateduser(self, period, index, tags=''):
"""
Create a related user of the type that we are testing.
"""
raise NotImplementedError()
def _create_relatedusers(self, count):
for index in xrange(count):
self.create_relateduser(self.testhelper.sub_p1, index)
def test_list(self):
self._create_relatedusers(2)
self.create_relateduser(self.testhelper.sub_p1, index=5, tags='group1,group2')
self.create_relateduser(self.testhelper.sub_p2, index=20, tags='') # Not on p1, so we shold not get this in the listing!
content, response = self._listas('p1admin')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 3) # Since this is 3, we did not get the user registered on p2.
first, second, last = content
self.assertEquals(first['user']['username'], 'reluser0')
self.assertEquals(first['user']['full_name'] , 'User 0')
self.assertEquals(first['tags'], '')
self.assertEquals(second['tags'], '')
self.assertEquals(second['user']['username'], 'reluser1')
self.assertEquals(last['user']['username'], 'reluser5')
self.assertEquals(last['tags'], 'group1,group2')
return content
def test_list_none(self):
content, response = self._listas('p1admin')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 0)
def test_list_superuser(self):
self._create_relatedusers(2)
content, response = self._listas('superuser')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 2)
def test_list_not_admin(self):
self._create_relatedusers(2)
content, response = self._listas('p2admin')
self.assertEquals(response.status_code, 403)
def _listqueryas(self, username, query):
self.client.login(username=username, password='test')
return self.client.rest_get(self.get_url(), **{'query': query})
def test_list_query(self):
self._create_relatedusers(2)
self.create_relateduser(self.testhelper.sub_p1, index=5, tags='group1,group2')
self.create_relateduser(self.testhelper.sub_p2, index=20, tags='') # Not on p1, so we shold not get this in the listing!
self.testhelper.reluser0.devilryuserprofile.full_name = 'Superhero'
self.testhelper.reluser0.devilryuserprofile.save()
self.testhelper.reluser1.devilryuserprofile.full_name = 'Super Not hero'
self.testhelper.reluser1.email = '[email protected]'
self.testhelper.reluser1.devilryuserprofile.save()
self.testhelper.reluser1.save()
content, response = self._listqueryas('p1admin', query='5')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
content, response = self._listqueryas('p1admin', query='HeRo')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 2)
content, response = self._listqueryas('p1admin', query='group2')
self.assertEquals(len(content), 1)
content, response = self._listqueryas('p1admin', query='[email protected]')
#.........这里部分代码省略.........
示例11: TestListGroupRest
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import login [as 别名]
class TestListGroupRest(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.client = RestClient()
def _geturl(self, assignment_id):
assignment_id = assignment_id or self.testhelper.sub_p1_a1.id
return '/devilry_subjectadmin/rest/group/{0}/'.format(assignment_id)
def _getas(self, username, assignment_id, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self._geturl(assignment_id), **data)
def _create_testassignments(self):
self.testhelper.add(nodes='uni',
subjects=['duck1010'],
periods=['firstsem'],
assignments=['a1:admin(a1admin)', 'a2'])
def _create_testdata(self):
self._create_testassignments()
for num in xrange(3):
path = 'uni;duck1010.firstsem.a1.g{num}:candidate(student{num},extrastudent):examiner(examiner1,extraexaminer).d1'
self.testhelper.add_to_path(path.format(**vars()))
group = getattr(self.testhelper, 'duck1010_firstsem_a1_g{0}'.format(num))
group.tags.create(tag="stuff")
group.tags.create(tag="lownumber")
delivery = self.testhelper.add_delivery(group)
if num != 2:
self.testhelper.add_feedback(delivery,
verdict=dict(grade='A', points=100,
is_passing_grade=True))
def test_list_permissiondenied(self):
self.testhelper.create_user('nobody')
self._create_testassignments()
a1 = self.testhelper.duck1010_firstsem_a1
content, response = self._getas('nobody', a1.id)
self.assertEquals(response.status_code, 403)
def _test_list_as(self, username):
self._create_testdata()
a1 = self.testhelper.duck1010_firstsem_a1
content, response = self._getas(username, a1.id)
#from pprint import pprint
#pprint(content)
self.assertEquals(len(content), 3)
self.assertEquals(set(content[0].keys()),
set(['name', 'feedback', 'deadlines', 'id', 'etag', 'status',
'is_open', 'parentnode', 'candidates', 'tags',
'examiners', 'num_deliveries']))
# Properties directly from group
self.assertEquals(AssignmentGroup.objects.get(id=content[0]['id']).parentnode_id,
a1.id)
self.assertEquals(content[0]['is_open'], False)
self.assertEquals(content[0]['name'], 'g0')
self.assertEquals(content[0]['num_deliveries'], 1)
self.assertEquals(content[0]['parentnode'], a1.id)
# Feedback
feedback = content[0]['feedback']
self.assertEquals(set(feedback.keys()),
set(['id', 'grade', 'is_passing_grade', 'points', 'save_timestamp',
'delivery_id']))
self.assertEquals(feedback['grade'], 'A')
self.assertEquals(feedback['is_passing_grade'], True)
self.assertEquals(feedback['points'], 100)
# NULL feedback
self.assertEquals(content[2]['feedback'], None)
# Canididates
def get_usernames(users):
return [user['user']['username'] for user in users]
self.assertEquals(len(content[0]['candidates']), 2)
self.assertEquals(set(get_usernames(content[0]['candidates'])),
set(['student0', 'extrastudent']))
self.assertEquals(set(content[0]['candidates'][0].keys()),
set(['id', 'candidate_id', 'user']))
self.assertEquals(set(content[0]['candidates'][0]['user'].keys()),
set(['email', 'full_name', 'id', 'username', 'displayname']))
# Examiners
self.assertEquals(len(content[0]['examiners']), 2)
self.assertEquals(set(get_usernames(content[0]['examiners'])),
set(['examiner1', 'extraexaminer']))
self.assertEquals(set(content[0]['examiners'][0].keys()),
set(['id', 'user']))
self.assertEquals(set(content[0]['examiners'][0]['user'].keys()),
set(['email', 'full_name', 'id', 'username', 'displayname']))
# Deadlines
self.assertEquals(len(content[0]['deadlines']), 1)
deadline = content[0]['deadlines'][0]
self.assertEquals(set(deadline.keys()),
set(['id', 'deadline']))
#.........这里部分代码省略.........
示例12: TestRestStatus
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import login [as 别名]
class TestRestStatus(TransactionTestCase):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni:admin(uniadmin)',
subjects=['sub'],
periods=[
'oldperiod:admin(periodadmin):begins(-12):ends(2)',
'p1:admin(periodadmin):begins(-3):ends(6)',
'p2:admin(periodadmin):begins(-1):ends(6)'])
self.client = RestClient()
self.url = reverse('devilry_qualifiesforexam-rest-status')
self.testhelper.create_superuser('superuser')
qualifiesforexam_plugins.add(
id = 'devilry_qualifiesforexam.test.noop-plugin',
url = '/some/noop-url',
title = 'Noop',
post_statussave=noop,
description = 'noop',
pluginsettings_summary_generator = lambda status: 'noop summary'
)
def tearDown(self):
for pluginid in ('devilry_qualifiesforexam.test.plugin', 'devilry_qualifiesforexam.test.noop-plugin'):
if pluginid in qualifiesforexam_plugins:
del qualifiesforexam_plugins.items[pluginid]
def _get_url(self, periodid=None):
if periodid:
return '{0}{1}'.format(self.url, periodid)
else:
return self.url
def _create_relatedstudent(self, username, fullname=None):
user = getattr(self.testhelper, username, None)
if not user:
user = self.testhelper.create_user(username, fullname=fullname)
relstudent = self.testhelper.sub_p1.relatedstudent_set.create(user=user)
return relstudent
def _postas(self, username, data):
self.client.login(username=username, password='test')
return self.client.rest_post(self._get_url(), data)
def _test_post_as(self, username):
self.assertEquals(Status.objects.count(), 0)
relatedStudent1 = self._create_relatedstudent('student1', 'Student One')
relatedStudent2 = self._create_relatedstudent('student2', 'Student Two')
content, response = self._postas(username, {
'period': self.testhelper.sub_p1.id,
'status': 'ready',
'message': 'This is a test',
'plugin': 'devilry_qualifiesforexam.test.noop-plugin',
'pluginsessionid': 'tst',
'passing_relatedstudentids': [relatedStudent1.id]
})
self.assertEquals(response.status_code, 201)
self.assertEquals(Status.objects.count(), 1)
status = Status.objects.all()[0]
self.assertEquals(status.period, self.testhelper.sub_p1)
self.assertEquals(status.status, 'ready')
self.assertEquals(status.message, 'This is a test')
self.assertEquals(status.plugin, 'devilry_qualifiesforexam.test.noop-plugin')
self.assertEqual(status.students.count(), 2)
qualifies1 = status.students.get(relatedstudent=relatedStudent1)
qualifies2 = status.students.get(relatedstudent=relatedStudent2)
self.assertTrue(qualifies1.qualifies)
self.assertFalse(qualifies2.qualifies)
def test_post_as_periodadmin(self):
self._test_post_as(self.testhelper.periodadmin)
def test_post_as_nodeadmin(self):
self._test_post_as(self.testhelper.uniadmin)
def test_post_as_superuser(self):
self._test_post_as(self.testhelper.superuser)
def test_post_as_nobody(self):
self.testhelper.create_user('nobody')
content, response = self._postas('nobody', {
'period': self.testhelper.sub_p1.id,
'status': 'ready',
'message': 'This is a test',
'plugin': 'devilry_qualifiesforexam.test.noop-plugin',
'pluginsessionid': 'tst',
'passing_relatedstudentids': [10]
})
self.assertEqual(response.status_code, 403)
def test_post_almostready(self):
relatedStudent1 = self._create_relatedstudent('student1', 'Student One')
relatedStudent2 = self._create_relatedstudent('student2', 'Student Two')
content, response = self._postas('periodadmin', {
'period': self.testhelper.sub_p1.id,
'status': 'almostready',
'message': 'This is a test',
'plugin': 'devilry_qualifiesforexam.test.noop-plugin',
'pluginsessionid': 'tst',
#.........这里部分代码省略.........
示例13: TestRestListOrCreatePeriodRest
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import login [as 别名]
class TestRestListOrCreatePeriodRest(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni:admin(uniadmin)',
subjects=['duck2000:admin(subadmin)'],
periods=['one:admin(adminone)',
'two',
'three:admin(adminone)'])
self.client = RestClient()
self.url = '/devilry_subjectadmin/rest/period/'
self.testhelper.create_user('nobody')
def _listas(self, username, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url, **data)
def test_list(self):
content, response = self._listas('adminone')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 2)
self.assertEquals(set(content[0].keys()),
set(['id', 'parentnode', 'etag', 'short_name', 'long_name',
'start_time', 'end_time', 'url']))
def test_list_nonadmin(self):
self.testhelper.create_user('otheruser')
content, response = self._listas('otheruser')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 0)
def test_list_in_subject(self):
self.testhelper.add(nodes='uni:admin(uniadmin)',
subjects=['duck9000'],
periods=['p1', 'p2'])
content, response = self._listas('uniadmin',
parentnode=self.testhelper.duck9000.id)
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 2)
shortnames = set([p['short_name'] for p in content])
self.assertEquals(shortnames, set(['p1', 'p2']))
def _createas(self, username, data):
self.client.login(username=username, password='test')
return self.client.rest_post(self.url, data)
def test_create(self):
content, response = self._createas('subadmin',
{'short_name': 'test',
'long_name': 'Test',
'admins': [],
'start_time': isoformat_relativetime(days=-2),
'end_time': isoformat_relativetime(days=2),
'parentnode': self.testhelper.duck2000.id})
self.assertEquals(response.status_code, 201)
self.assertEquals(content['long_name'], 'Test')
self.assertEquals(content['short_name'], 'test')
self.assertEquals(content['parentnode'], self.testhelper.duck2000.id)
created = Period.objects.get(id=content['id'])
self.assertEquals(created.short_name, 'test')
self.assertEquals(created.long_name, 'Test')
self.assertEquals(created.parentnode.id, self.testhelper.duck2000.id)
admins = created.admins.all()
self.assertEquals(len(admins), 0)
def test_create_nobody(self):
content, response = self._createas('nobody',
{'short_name': 'test',
'long_name': 'Test',
'admins': [],
'start_time': isoformat_relativetime(days=-2),
'end_time': isoformat_relativetime(days=2),
'parentnode': self.testhelper.duck2000.id})
self.assertEquals(response.status_code, 403)
self.assertEquals(content['detail'], 'Permission denied')
def test_create_admins(self):
self.testhelper.create_user('testadmin')
content, response = self._createas('uniadmin',
{'short_name': 'test',
'long_name': 'Test',
'admins': [{'id': self.testhelper.testadmin.id}],
'start_time': isoformat_relativetime(days=-2),
'end_time': isoformat_relativetime(days=2),
'parentnode': self.testhelper.duck2000.id})
self.assertEquals(response.status_code, 201)
created = Period.objects.get(id=content['id'])
admins = created.admins.all()
self.assertEquals(len(admins), 1)
self.assertEquals(admins[0].username, 'testadmin')
示例14: TestRestCreateNewAssignmentIntegration
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import login [as 别名]
class TestRestCreateNewAssignmentIntegration(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['p1:admin(p1admin)', 'p2'])
self.client = RestClient()
self.url = '/devilry_subjectadmin/rest/createnewassignment/'
def _login_p1admin(self):
self.client.login(username='p1admin', password='test')
def _get_testdata(self):
publishing_time = self.testhelper.sub_p1.start_time + timedelta(days=1)
first_deadline = self.testhelper.sub_p1.start_time + timedelta(days=2)
return dict(period_id=self.testhelper.sub_p1.id,
short_name='a', long_name='Aa',
first_deadline=isoformat_datetime(first_deadline),
publishing_time=isoformat_datetime(publishing_time),
delivery_types=ELECTRONIC, anonymous=False,
setupstudents_mode='do_not_setup',
setupexaminers_mode='do_not_setup')
def test_create(self):
self._login_p1admin()
publishing_time = self.testhelper.sub_p1.start_time + timedelta(days=1)
first_deadline = self.testhelper.sub_p1.start_time + timedelta(days=2)
content, response = self.client.rest_post(self.url, self._get_testdata())
self.assertEquals(response.status_code, 201)
self.assertEquals(set(content.keys()),
set(['id', 'period_id', 'short_name', 'long_name', 'first_deadline', 'anonymous']))
def test_create_notfound(self):
self._login_p1admin()
data = self._get_testdata()
data['period_id'] = 200000
content, response = self.client.rest_post(self.url, data)
self.assertEquals(response.status_code, 403)
def test_create_permissiondenied(self):
self.testhelper.create_user('nopermsuser')
self.client.login(username='nopermsuser', password='test')
data = self._get_testdata()
content, response = self.client.rest_post(self.url, data)
self.assertEquals(response.status_code, 403)
def test_create_validation(self):
self._login_p1admin()
content, response = self.client.rest_post(self.url, {})
self.assertEquals(response.status_code, 400)
self.assertEquals(content.keys(), ['field_errors'])
for fieldname in ['delivery_types', 'long_name', 'publishing_time', 'short_name']:
self.assertEquals(content['field_errors'][fieldname], [u'This field is required.'])
def test_create_first_deadline_none(self):
self._login_p1admin()
data = self._get_testdata()
data['first_deadline'] = None
data['setupstudents_mode'] = 'allrelated'
content, response = self.client.rest_post(self.url, data)
self.assertEquals(response.status_code, 400)
self.assertTrue(content['field_errors']['first_deadline'][0].startswith('Required when adding'))
示例15: TestRestDeadlinesBulkCreate
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import login [as 别名]
class TestRestDeadlinesBulkCreate(TestCase):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['p1:begins(-2)']) # 2 months ago
self.testhelper.sub_p1.start_time = datetime(2000, 1, 1, 22, 30, 49)
self.testhelper.sub_p1.save()
self.testhelper.add_to_path('uni;sub.p1.a1:admin(adm):pub(0)') # 0 days after period begins + 2 sec
self.client = RestClient()
for groupnum in xrange(3):
# deadline 5 days after assignment starts
self.testhelper.add_to_path('uni;sub.p1.a1.g{0}:candidate(cand1):examiner(exam1).d1:ends(5)'.format(groupnum))
def _geturl(self):
return '/devilry_subjectadmin/rest/deadlinesbulk/{0}/'.format(self.testhelper.sub_p1_a1.id)
def _postas(self, username, data):
self.client.login(username=username, password='test')
return self.client.rest_post(self._geturl(), data)
def _itergroups(self):
for groupnum in xrange(3):
group_id = getattr(self.testhelper, 'sub_p1_a1_g{0}'.format(groupnum)).id
group = AssignmentGroup.objects.get(id=group_id)
yield group
def test_post_no_matching_groups(self):
for group in self._itergroups():
deadlines = group.deadlines.all().order_by('-deadline')
self.assertEquals(group.feedback, None)
new_deadline = datetime(2004, 12, 24, 20, 30)
content, response = self._postas('adm', {'deadline': format_datetime(new_deadline),
'text': 'Created',
'createmode': 'failed'})
self.assertEquals(response.status_code, 400)
self.assertEquals(content['field_errors']['createmode'], ['The given option did not match any groups.'])
def test_post_createmode_failed(self):
self.testhelper.add_delivery('sub.p1.a1.g1', {'bad.py': ['print ', 'bah']})
self.testhelper.add_feedback('sub.p1.a1.g1', verdict={'grade': 'F', 'points': 30, 'is_passing_grade': False})
g1 = AssignmentGroup.objects.get(id=self.testhelper.sub_p1_a1_g1.id)
self.assertFalse(g1.is_open)
new_deadline = datetime(2004, 12, 24, 20, 30)
self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 0)
content, response = self._postas('adm', {'deadline': format_datetime(new_deadline),
'text': 'Created',
'createmode': 'failed'})
# Check response
self.assertEquals(response.status_code, 201)
self.assertEquals(decode_bulkdeadline_id(content['bulkdeadline_id'])[0],
new_deadline)
self.assertEquals(len(content['groups']), 1)
self.assertEquals(content['text'], 'Created')
self.assertEquals(content['deadline'], format_datetime(new_deadline))
# Check actual data
self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 1)
g1 = AssignmentGroup.objects.get(id=self.testhelper.sub_p1_a1_g1.id)
deadlines = g1.deadlines.all().order_by('-deadline')
self.assertEquals(len(deadlines), 2)
self.assertEquals(deadlines[0].deadline, new_deadline)
self.assertEquals(deadlines[0].text, 'Created')
self.assertTrue(g1.is_open) # Group was automatically opened in devilry.apps.core.models.Deadline.save()
def test_post_createmode_failed_or_no_feedback(self):
# Fail g0
self.testhelper.add_delivery('sub.p1.a1.g0', {'bad.py': ['print ', 'bah']})
self.testhelper.add_feedback('sub.p1.a1.g0', verdict={'grade': 'F', 'points': 30, 'is_passing_grade': False})
# Pass g1
self.testhelper.add_delivery('sub.p1.a1.g1', {'good.py': ['print ', 'bah']})
self.testhelper.add_feedback('sub.p1.a1.g1', verdict={'grade': 'A', 'points': 100, 'is_passing_grade': True})
# g2 has no feedback
self.assertEquals(self.testhelper.sub_p1_a1_g2.feedback, None)
new_deadline = datetime(2004, 12, 24, 20, 30)
self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 0)
content, response = self._postas('adm', {'deadline': format_datetime(new_deadline),
'text': 'Created',
'createmode': 'failed-or-no-feedback'})
# Check response
self.assertEquals(response.status_code, 201)
self.assertEquals(len(content['groups']), 2)
# Check actual data
self.assertEquals(Deadline.objects.filter(deadline=new_deadline).count(), 2)
g0 = self.testhelper.sub_p1_a1_g0
g2 = self.testhelper.sub_p1_a1_g2
for group in (g0, g2):
deadlines = group.deadlines.all().order_by('-deadline')
self.assertEquals(len(deadlines), 2)
self.assertEquals(deadlines[0].deadline, new_deadline)
self.assertEquals(deadlines[0].text, 'Created')
g1 = self.testhelper.sub_p1_a1_g1
#.........这里部分代码省略.........