本文整理汇总了Python中devilry.devilry_rest.testclient.RestClient.rest_put方法的典型用法代码示例。如果您正苦于以下问题:Python RestClient.rest_put方法的具体用法?Python RestClient.rest_put怎么用?Python RestClient.rest_put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类devilry.devilry_rest.testclient.RestClient
的用法示例。
在下文中一共展示了RestClient.rest_put方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestLanguageSelect
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_put [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: TestRestInstancePeriodRest
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_put [as 别名]
#.........这里部分代码省略.........
content, response = self.client.rest_get(self._geturl(self.testhelper.sub_p1.id))
self.assertEquals(response.status_code, 200)
th = self.testhelper
self.assertEquals(content['breadcrumb'],
[{u'id': th.sub_p1.id, u'text': u'sub.p1', u'type': u'Period'}])
def test_get_breadcrumb_subjectadmin(self):
self.testhelper.add(nodes='uni',
subjects=['sub:admin(subadm)'],
periods=['p1'])
self.client.login(username='subadm', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.sub_p1.id))
self.assertEquals(response.status_code, 200)
th = self.testhelper
self.assertEquals(content['breadcrumb'],
[{u'id': th.sub.id, u'text': u'sub', u'type': u'Subject'},
{u'id': th.sub_p1.id, u'text': u'p1', u'type': u'Period'}])
def test_get_breadcrumb_nodeadmin(self):
self.testhelper.add(nodes='uni:admin(uniadmin).inf',
subjects=['sub'],
periods=['p1'])
self.client.login(username='uniadmin', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.sub_p1.id))
self.assertEquals(response.status_code, 200)
th = self.testhelper
self.assertEquals(content['breadcrumb'],
[{u'id': th.uni.id, u'text': u'uni', u'type': u'Node'},
{u'id': th.uni_inf.id, u'text': u'inf', u'type': u'Node'},
{u'id': th.sub.id, u'text': u'sub', u'type': u'Subject'},
{u'id': th.sub_p1.id, u'text': u'p1', u'type': u'Period'}])
def test_get_breadcrumb_superuser(self):
self.testhelper.add(nodes='uni.inf',
subjects=['sub'],
periods=['p1'])
self.testhelper.create_superuser('super')
self.client.login(username='super', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.sub_p1.id))
self.assertEquals(response.status_code, 200)
th = self.testhelper
self.assertEquals(content['breadcrumb'],
[{u'id': th.uni.id, u'text': u'uni', u'type': u'Node'},
{u'id': th.uni_inf.id, u'text': u'inf', u'type': u'Node'},
{u'id': th.sub.id, u'text': u'sub', u'type': u'Subject'},
{u'id': th.sub_p1.id, u'text': u'p1', u'type': u'Period'}])
def test_get_can_not_delete(self):
self.client.login(username='oneadmin', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000_periodone.id))
self.assertFalse(content['can_delete'])
def test_put(self):
self.client.login(username='oneadmin', password='test')
data = {'short_name': 'duck2000',
'long_name': 'Updated',
'admins': [],
'start_time': isoformat_relativetime(days=-2),
'end_time': isoformat_relativetime(days=2),
'parentnode': 1}
content, response = self.client.rest_put(self._geturl(self.testhelper.duck2000_periodone.id),
data=data)
self.assertEquals(response.status_code, 200)
self.assertEquals(content['id'], self.testhelper.duck2000_periodone.id)
self.assertEquals(content['short_name'], self.testhelper.duck2000.short_name)
self.assertEquals(content['long_name'], 'Updated')
self.assertEquals(content['parentnode'], 1)
self.assertEquals(set(content.keys()),
set(['short_name', 'long_name', 'admins', 'etag',
'can_delete', 'parentnode', 'id', 'inherited_admins',
'start_time', 'end_time', 'breadcrumb',
'number_of_relatedstudents', 'number_of_relatedexaminers']))
updated = Period.objects.get(id=self.testhelper.duck2000_periodone.id)
self.assertEquals(updated.long_name, 'Updated')
def test_put_admins(self):
self.client.login(username='oneadmin', password='test')
self.testhelper.create_user('user1')
self.testhelper.create_user('user2')
self.testhelper.create_user('user3')
data = {'short_name': 'duck2000',
'long_name': 'Updated',
'admins': [{'username': 'user1',
'email': 'ignored',
'full_name': 'ignored!'},
{'username': 'user2'},
{'id': self.testhelper.user3.id}],
'start_time': isoformat_relativetime(days=-2),
'end_time': isoformat_relativetime(days=2),
'parentnode': 1}
content, response = self.client.rest_put(self._geturl(self.testhelper.duck2000_periodone.id),
data=data)
self.assertEquals(response.status_code, 200)
admins = content['admins']
self.assertEquals(len(content['admins']), 3)
admins.sort(cmp=lambda a,b: cmp(a['username'], b['username']))
self.assertEquals(admins[0]['username'], 'user1')
self.assertEquals(admins[2]['username'], 'user3')
updated = Period.objects.get(id=self.testhelper.duck2000_periodone.id)
self.assertEquals(updated.admins.all().count(), 3)
示例3: TestInstanceRelatedUserMixin
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_put [as 别名]
class TestInstanceRelatedUserMixin(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.testreluser = self.create_reluser_on_p1('testuser', tags='group1,group2')
def create_reluser_on_p1(self, username, tags):
raise NotImplementedError()
def get_url(self, periodid, reluserid):
raise NotImplementedError()
def get_valid_putdata(self):
return {'period': self.testhelper.sub_p1.id,
'tags': 'group10,group20',
'user': self.testhelper.testuser.id}
def _getas(self, username, periodid, id, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self.get_url(periodid, id), **data)
def test_get_404(self):
content, response = self._getas('p1admin', self.testhelper.sub_p1.id, 40000000)
self.assertEquals(response.status_code, 404)
def test_get_unauthorized(self):
content, response = self._getas('p2admin', self.testhelper.sub_p1.id, self.testreluser.id)
self.assertEquals(response.status_code, 403)
def test_get_superuser(self):
content, response = self._getas('superuser', self.testhelper.sub_p1.id, self.testreluser.id)
self.assertEquals(response.status_code, 200)
def _putas(self, username, periodid, id, data):
self.client.login(username=username, password='test')
return self.client.rest_put(self.get_url(periodid, id), data)
def test_put_unauthorized(self):
content, response = self._putas('p2admin', self.testhelper.sub_p1.id,
self.testreluser.id, self.get_valid_putdata())
self.assertEquals(response.status_code, 403)
def test_put_superuser(self):
content, response = self._putas('superuser', self.testhelper.sub_p1.id,
self.testreluser.id, self.get_valid_putdata())
self.assertEquals(response.status_code, 200)
def test_put(self):
content, response = self._putas('p1admin', self.testhelper.sub_p1.id,
self.testreluser.id, self.get_valid_putdata())
self.assertEquals(response.status_code, 200)
self.assertEquals(content['period'], self.testhelper.sub_p1.id)
self.assertEquals(content['tags'], 'group10,group20')
self.assertEquals(set(content['user'].keys()),
set(['email', 'full_name', 'id', 'username', 'displayname']))
self.assertEquals(content['user']['id'], self.testreluser.user.id)
self.assertEquals(content['user']['username'], 'testuser')
return content
def _deleteas(self, username, periodid, id):
self.client.login(username=username, password='test')
return self.client.rest_delete(self.get_url(periodid, id))
def test_delete(self):
reluserid = self.testreluser.id
self.assertEquals(self.modelcls.objects.filter(id=reluserid).count(), 1)
content, response = self._deleteas('p1admin',
self.testhelper.sub_p1.id,
reluserid)
self.assertEquals(response.status_code, 204)
self.assertEquals(self.modelcls.objects.filter(id=reluserid).count(), 0)
def test_delete_superuser(self):
content, response = self._deleteas('superuser',
self.testhelper.sub_p1.id,
self.testreluser.id)
self.assertEquals(response.status_code, 204)
def test_delete_unauthorized(self):
content, response = self._deleteas('p2admin',
self.testhelper.sub_p1.id,
self.testreluser.id)
self.assertEquals(response.status_code, 403)
示例4: TestRestInstanceAssignmentRest
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_put [as 别名]
#.........这里部分代码省略.........
subjects=['sub'],
periods=['p1'],
assignments=['a1'])
self.client.login(username='uniadm', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.sub_p1_a1.id))
self.assertEquals(response.status_code, 200)
th = self.testhelper
self.assertEquals(content['breadcrumb'],
[{u'id': th.uni.id, u'text': u'uni', u'type': u'Node'},
{u'id': th.uni_inf.id, u'text': u'inf', u'type': u'Node'},
{u'id': th.sub.id, u'text': u'sub', u'type': u'Subject'},
{u'id': th.sub_p1.id, u'text': u'p1', u'type': u'Period'},
{u'id': th.sub_p1_a1.id, u'text': u'a1', u'type': u'Assignment'}])
def test_get_breadcrumb_superuser(self):
self.testhelper.add(nodes='uni.inf',
subjects=['sub'],
periods=['p1'],
assignments=['a1'])
self.testhelper.create_superuser('super')
self.client.login(username='super', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.sub_p1_a1.id))
self.assertEquals(response.status_code, 200)
th = self.testhelper
self.assertEquals(content['breadcrumb'],
[{u'id': th.uni.id, u'text': u'uni', u'type': u'Node'},
{u'id': th.uni_inf.id, u'text': u'inf', u'type': u'Node'},
{u'id': th.sub.id, u'text': u'sub', u'type': u'Subject'},
{u'id': th.sub_p1.id, u'text': u'p1', u'type': u'Period'},
{u'id': th.sub_p1_a1.id, u'text': u'a1', u'type': u'Assignment'}])
def test_get_can_not_delete(self):
self.client.login(username='firstadmin', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000_someperiod_first.id))
self.assertEquals(response.status_code, 200)
self.assertFalse(content['can_delete'])
def test_put(self):
self.client.login(username='firstadmin', password='test')
data = {'short_name': 'duck2000',
'long_name': 'Updated',
'admins': [],
'publishing_time': isoformat_relativetime(days=-2),
'scale_points_percent': 80,
'deadline_handling': 0,
'delivery_types': 0,
'parentnode': 1}
content, response = self.client.rest_put(self._geturl(self.testhelper.duck2000_someperiod_first.id),
data=data)
self.assertEquals(response.status_code, 200)
self.assertEquals(content['id'], self.testhelper.duck2000_someperiod_first.id)
self.assertEquals(content['short_name'], self.testhelper.duck2000.short_name)
self.assertEquals(content['long_name'], 'Updated')
self.assertEquals(content['parentnode'], 1)
self.assertEquals(content['scale_points_percent'], 80)
self.assertEquals(content['deadline_handling'], 0)
self.assertEquals(content['delivery_types'], 0)
self.assertEquals(set(content.keys()),
set(['short_name', 'long_name', 'admins',
'can_delete', 'parentnode', 'id', 'inherited_admins',
'publishing_time', 'delivery_types',
'is_published', 'publishing_time_offset_from_now',
'scale_points_percent', 'deadline_handling',
'first_deadline', 'breadcrumb', 'anonymous',
'number_of_deliveries', 'number_of_groups',
'number_of_candidates',
'number_of_groups_where_is_examiner',
'has_valid_grading_setup', 'gradingsystemplugin_title',
'max_points', 'points_to_grade_mapper', 'grading_system_plugin_id', 'passing_grade_min_points'
]))
updated = Assignment.objects.get(id=self.testhelper.duck2000_someperiod_first.id)
self.assertEquals(updated.long_name, 'Updated')
def test_put_admins(self):
self.client.login(username='firstadmin', password='test')
self.testhelper.create_user('user1')
self.testhelper.create_user('user2')
self.testhelper.create_user('user3')
data = {'short_name': 'duck2000',
'long_name': 'Updated',
'admins': [{'username': 'user1',
'email': 'ignored',
'full_name': 'ignored!'},
{'username': 'user2'},
{'id': self.testhelper.user3.id}],
'publishing_time': isoformat_relativetime(days=-2),
'scale_points_percent': 80,
'deadline_handling': 0,
'delivery_types': 0,
'parentnode': 1}
content, response = self.client.rest_put(self._geturl(self.testhelper.duck2000_someperiod_first.id),
data=data)
self.assertEquals(response.status_code, 200)
admins = content['admins']
self.assertEquals(len(content['admins']), 3)
admins.sort(cmp=lambda a,b: cmp(a['username'], b['username']))
self.assertEquals(admins[0]['username'], 'user1')
self.assertEquals(admins[2]['username'], 'user3')
updated = Assignment.objects.get(id=self.testhelper.duck2000_someperiod_first.id)
self.assertEquals(updated.admins.all().count(), 3)
示例5: TestRestDeadlinesBulkUpdateReadOrDelete
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_put [as 别名]
class TestRestDeadlinesBulkUpdateReadOrDelete(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, deadline=None):
deadline = deadline or self.testhelper.sub_p1_a1_g1_d1
bulkdeadline_id = encode_bulkdeadline_id(deadline)
return '/devilry_subjectadmin/rest/deadlinesbulk/{0}/{1}'.format(self.testhelper.sub_p1_a1.id,
bulkdeadline_id)
def test_encode_unique_bulkdeadline_id(self):
d = Deadline(deadline=datetime(2000, 12, 24, 22, 30, 49))
self.assertEquals(encode_bulkdeadline_id(d),
'2000-12-24T22_30_49--')
d.text = 'Hello world'
self.assertEquals(encode_bulkdeadline_id(d),
'2000-12-24T22_30_49--{0}'.format(sha1hash('Hello world')))
# Ensure unicode works
d.text = u'\u00e5ello world'
self.assertEquals(encode_bulkdeadline_id(d),
'2000-12-24T22_30_49--{0}'.format(sha1hash(u'\u00e5ello world')))
def test_decode_unique_bulkdeadline_id(self):
self.assertEquals(decode_bulkdeadline_id('2000-12-24T22_30_49--'),
(datetime(2000, 12, 24, 22, 30, 49), ''))
self.assertEquals(decode_bulkdeadline_id('2000-12-24T22_30_49--{0}'.format(sha1hash('Hello world'))),
(datetime(2000, 12, 24, 22, 30, 49), sha1hash('Hello world')))
def _putas(self, username, data):
self.client.login(username=username, password='test')
return self.client.rest_put(self._geturl(), data)
def test_put(self):
self.assertEquals(self.testhelper.sub_p1_a1.publishing_time, datetime(2000, 1, 1, 22, 30, 51))
self.assertEquals(self.testhelper.sub_p1_a1_g1_d1.deadline,
datetime(2000, 1, 1, 22, 30) + timedelta(days=5))
new_deadline = datetime(2004, 12, 24, 20, 30)
content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
'text': 'Hello'})
self.assertEquals(response.status_code, 200)
self.assertEquals(decode_bulkdeadline_id(content['bulkdeadline_id'])[0],
new_deadline)
self.assertEquals(len(content['groups']), 3)
self.assertEquals(content['text'], 'Hello')
self.assertEquals(content['deadline'], format_datetime(new_deadline))
for groupnum in xrange(3):
deadline_id = getattr(self.testhelper, 'sub_p1_a1_g{0}_d1'.format(groupnum)).id
deadline = Deadline.objects.get(id=deadline_id)
self.assertEquals(deadline.deadline, new_deadline)
self.assertEquals(deadline.text, 'Hello')
def test_put_nonetext(self):
self.assertEquals(self.testhelper.sub_p1_a1.publishing_time, datetime(2000, 1, 1, 22, 30, 51))
self.assertEquals(self.testhelper.sub_p1_a1_g1_d1.deadline,
datetime(2000, 1, 1, 22, 30) + timedelta(days=5))
new_deadline = datetime(2004, 12, 24, 20, 30)
content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
'text': None})
self.assertEquals(response.status_code, 200)
for groupnum in xrange(3):
deadline_id = getattr(self.testhelper, 'sub_p1_a1_g{0}_d1'.format(groupnum)).id
deadline = Deadline.objects.get(id=deadline_id)
self.assertEquals(deadline.deadline, new_deadline)
self.assertEquals(deadline.text, '')
def test_put_before_publishingtime(self):
new_deadline = datetime(1990, 1, 1, 20, 30, 40)
content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
'text': None})
self.assertEquals(response.status_code, 400)
self.assertEquals(content['errors'], ['Deadline cannot be before publishing time.'])
def test_put_nobody(self):
self.testhelper.create_user('nobody')
content, response = self._putas('nobody', {})
self.assertEquals(response.status_code, 403)
def test_put_with_bulkdeadline_id(self):
new_deadline = datetime(2004, 12, 24, 20, 30)
content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
'bulkdeadline_id': 'ignored'})
self.assertEquals(response.status_code, 200)
def test_put_group_ids(self):
#.........这里部分代码省略.........
示例6: TestGroupRest
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_put [as 别名]
#.........这里部分代码省略.........
def test_create_as_assignmentadmin(self):
self._test_create_as('a1admin')
def test_create_as_superuser(self):
self._test_create_as('grandma')
def test_noperm(self):
self.testhelper.create_user('nobody')
data = [{'name': 'g1',
'is_open': False}]
content, response = self._postas('nobody', self.a1id, data)
self.assertEquals(response.status_code, 403)
self.assertEquals(content, {u'detail': u'Permission denied'})
def test_create_ro_fields(self):
data = [{'name': 'g1',
'is_open': False,
'id': None,
'feedback': 'should be ignored',
'num_deliveries': 'should be ignored',
'deadlines': 'should be ignored'}]
content, response = self._postas('a1admin', self.a1id, data)
self.assertEquals(response.status_code, 201)
#
#
# PUT
#
#
def _putas(self, username, assignment_id, data={}, querystringParams={}):
self.client.login(username=username, password='test')
return self.client.rest_put(self._geturl(assignment_id, querystringParams), data)
def _add_group(self, name, candidates, examiners):
self.testhelper.add_to_path('uni;sub.p1.a1.g1:candidate({candidates}):examiner({examiners})'.format(**vars()))
return getattr(self.testhelper, 'sub_p1_a1_' + name)
def test_put_minimal(self):
group = self._add_group('g1', candidates='candidate1', examiners='examiner1')
self.assertEquals(group.name, 'g1')
self.assertEquals(group.is_open, True)
data = [{'id': group.id,
'name': 'changed',
'is_open': False}]
content, response = self._putas('a1admin', self.a1id, data)
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
first = content[0]
self.assertEquals(set(first.keys()),
set(['name', 'id', 'etag', 'status', 'is_open', 'parentnode',
'feedback', 'deadlines', 'candidates', 'tags',
'examiners', 'num_deliveries']))
self.assertEquals(first['name'], 'changed')
self.assertEquals(first['is_open'], False)
self.assertEquals(first['parentnode'], self.a1id)
self.assertEquals(first['num_deliveries'], 0)
self.assertEquals(first['feedback'], None)
self.assertEquals(first['deadlines'], [])
self.assertEquals(first['candidates'], [])
self.assertEquals(first['examiners'], [])
self.assertEquals(first['tags'], [])
groups = self.testhelper.sub_p1_a1.assignmentgroups.all()
示例7: TestRestPassedInPreviousPeriod
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_put [as 别名]
class TestRestPassedInPreviousPeriod(TransactionTestCase):
def setUp(self):
self.testhelper = TestHelper()
self.testhelper.add(nodes='uni',
subjects=['sub'],
periods=['old:begins(-14):ends(6)', # 14 months ago
'cur:begins(-2)'], # 2 months ago
assignments=['a1:admin(adm):pub(0)']) # 0 days after period begins
self.client = RestClient()
self.url = '/devilry_subjectadmin/rest/passedinpreviousperiod/{0}'.format(self.testhelper.sub_cur_a1.id)
def _getas(self, username, **data):
self.client.login(username=username, password='test')
return self.client.rest_get(self.url, **data)
def _test_get_simple_as(self, username):
self.testhelper.add_to_path('uni;sub.cur.a1.g1:candidate(student1)')
content, response = self._getas(username)
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
item = content[0]
self.assertEquals(item['group']['id'], self.testhelper.sub_cur_a1_g1.id)
self.assertEquals(item['oldgroup'], None)
self.assertEquals(item['whyignored'], 'not_in_previous')
def test_get_simple_as_assignmentadmin(self):
self._test_get_simple_as('adm')
def test_get_simple_as_superuser(self):
self.testhelper.create_superuser('super')
self._test_get_simple_as('super')
def test_get_as_nobody(self):
self.testhelper.create_user('nobody')
content, response = self._getas('nobody')
self.assertEquals(response.status_code, 403)
def test_with_oldfeedback(self):
# Add a group for the student on the old period
self.testhelper.add_to_path('uni;sub.old.a1.g1:candidate(student1):examiner(examiner1).d1:ends(1)')
self.testhelper.create_feedbacks(
(self.testhelper.sub_old_a1_g1, {'grade': 'approved', 'points': 1, 'is_passing_grade': True})
)
# Add the student to the current period
self.testhelper.add_to_path('uni;sub.cur.a1.g1:candidate(student1)')
content, response = self._getas('adm')
self.assertEquals(response.status_code, 200)
self.assertEquals(len(content), 1)
item = content[0]
self.assertEquals(item['group']['id'], self.testhelper.sub_cur_a1_g1.id)
self.assertEquals(item['whyignored'], None)
self.assertNotEquals(item['oldgroup'], None)
oldgroup = item['oldgroup']
self.assertEqual(oldgroup['id'], self.testhelper.sub_old_a1_g1.id)
self.assertEqual(oldgroup['assignment']['id'], self.testhelper.sub_old_a1.id)
self.assertEqual(oldgroup['period']['id'], self.testhelper.sub_old.id)
self.assertEqual(oldgroup['grade'], 'approved')
def _putas(self, username, data):
self.client.login(username=username, password='test')
return self.client.rest_put(self.url, data)
def _test_putas(self, username):
self.testhelper.add_to_path('uni;sub.cur.a1.g1:candidate(student1).d1')
self.testhelper.add_to_path('uni;sub.cur.a1.g2:candidate(student2).d1')
self.testhelper.add_to_path('uni;sub.cur.a1.g3:candidate(student3).d1')
self.testhelper.add_to_path('uni;sub.old.a1.g3:candidate(student3):examiner(examiner1).d1')
oldg3_delivery = self.testhelper.add_delivery(self.testhelper.sub_old_a1_g3)
self.testhelper.add_feedback(oldg3_delivery,
verdict=dict(grade='C', points=40,
is_passing_grade=True))
g1 = self.testhelper.sub_cur_a1_g1
g2 = self.testhelper.sub_cur_a1_g2
g3 = self.testhelper.sub_cur_a1_g3
content, response = self._putas(username,
[{'id': g1.id,
'newfeedback_points': 10},
{'id': g3.id,
'newfeedback_points': 20}])
self.assertEquals(response.status_code, 200)
g1 = self.testhelper.reload_from_db(g1)
self.assertEquals(g1.feedback.grade, 'Passed')
self.assertEquals(g1.feedback.delivery.delivery_type, deliverytypes.ALIAS)
g2 = self.testhelper.reload_from_db(g2)
self.assertEquals(g2.feedback, None)
g3 = self.testhelper.reload_from_db(g3)
self.assertEquals(g3.feedback.grade, 'Passed')
self.assertEquals(g3.feedback.delivery.delivery_type, deliverytypes.ALIAS)
self.assertEquals(g3.feedback.delivery.alias_delivery, oldg3_delivery)
def test_put_as_assignmentadmin(self):
self._test_putas('adm')
#.........这里部分代码省略.........
示例8: TestRestInstanceSubjectRest
# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_put [as 别名]
#.........这里部分代码省略.........
set(['basenode', 'user']))
self.assertEquals(set(content['inherited_admins'][0]['basenode'].keys()),
set(['type', 'path', 'id', 'is_admin']))
self.assertEquals(set(content['inherited_admins'][0]['user'].keys()),
set(['email', 'username', 'id', 'full_name']))
inherited_adminusernames = [user['user']['username'] for user in content['inherited_admins']]
self.assertEquals(inherited_adminusernames, ['uniadmin'])
def test_get_breadcrumb_subjectadmin(self):
self.testhelper.add(nodes='uni.inf',
subjects=['sub:admin(subadm)'])
self.client.login(username='subadm', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.sub.id))
self.assertEquals(response.status_code, 200)
th = self.testhelper
self.assertEquals(content['breadcrumb'],
[{u'id': th.sub.id, u'text': u'sub', u'type': u'Subject'}])
def test_get_breadcrumb_nodeadmin(self):
self.testhelper.add(nodes='uni:admin(uniadm).inf',
subjects=['sub'])
self.client.login(username='uniadm', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.sub.id))
self.assertEquals(response.status_code, 200)
th = self.testhelper
self.assertEquals(content['breadcrumb'],
[{u'id': th.uni.id, u'text': u'uni', u'type': u'Node'},
{u'id': th.uni_inf.id, u'text': u'inf', u'type': u'Node'},
{u'id': th.sub.id, u'text': u'sub', u'type': u'Subject'}])
def test_get_breadcrumb_superuser(self):
self.testhelper.add(nodes='uni.inf',
subjects=['sub'])
self.testhelper.create_superuser('super')
self.client.login(username='super', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.sub.id))
self.assertEquals(response.status_code, 200)
th = self.testhelper
self.assertEquals(content['breadcrumb'],
[{u'id': th.uni.id, u'text': u'uni', u'type': u'Node'},
{u'id': th.uni_inf.id, u'text': u'inf', u'type': u'Node'},
{u'id': th.sub.id, u'text': u'sub', u'type': u'Subject'}])
def test_get_can_not_delete(self):
self.client.login(username='duck2000admin', password='test')
content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000.id))
self.assertFalse(content['can_delete'])
def test_put(self):
self.client.login(username='duck2000admin', password='test')
data = {'short_name': 'duck2000',
'long_name': 'Updated',
'admins': [],
'parentnode': 1}
content, response = self.client.rest_put(self._geturl(self.testhelper.duck2000.id),
data=data)
self.assertEquals(response.status_code, 200)
self.assertEquals(content['id'], self.testhelper.duck2000.id)
self.assertEquals(content['short_name'], self.testhelper.duck2000.short_name)
self.assertEquals(content['long_name'], 'Updated')
self.assertEquals(content['parentnode'], 1)
self.assertEquals(set(content.keys()),
set(['short_name', 'long_name', 'admins', 'etag',
'can_delete', 'parentnode', 'id', 'inherited_admins',
'breadcrumb']))
def test_put_admins(self):
self.client.login(username='duck2000admin', password='test')
self.testhelper.create_user('user1')
self.testhelper.create_user('user2')
self.testhelper.create_user('user3')
data = {'short_name': 'duck2000',
'long_name': 'Updated',
'admins': [{'username': 'user1',
'email': 'ignored',
'full_name': 'ignored!'},
{'username': 'user2'},
{'id': self.testhelper.user3.id}],
'parentnode': 1}
content, response = self.client.rest_put(self._geturl(self.testhelper.duck2000.id),
data=data)
self.assertEquals(response.status_code, 200)
admins = content['admins']
self.assertEquals(len(content['admins']), 3)
admins.sort(cmp=lambda a,b: cmp(a['username'], b['username']))
self.assertEquals(admins[0]['username'], 'user1')
self.assertEquals(admins[2]['username'], 'user3')
def test_put_generated_fields(self):
self.client.login(username='duck2000admin', password='test')
data = {'short_name': 'duck2000',
'long_name': 'Updated',
'admins': [],
'parentnode': 1,
'breadcrumb': [],
'can_delete': False,
'inherited_admins': []}
content, response = self.client.rest_put(self._geturl(self.testhelper.duck2000.id),
data=data)
self.assertEquals(response.status_code, 200)