当前位置: 首页>>代码示例>>Python>>正文


Python RestClient.rest_delete方法代码示例

本文整理汇总了Python中devilry.devilry_rest.testclient.RestClient.rest_delete方法的典型用法代码示例。如果您正苦于以下问题:Python RestClient.rest_delete方法的具体用法?Python RestClient.rest_delete怎么用?Python RestClient.rest_delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在devilry.devilry_rest.testclient.RestClient的用法示例。


在下文中一共展示了RestClient.rest_delete方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestRestInstancePeriodRest

# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_delete [as 别名]
class TestRestInstancePeriodRest(TestCase):
    def setUp(self):
        self.testhelper = TestHelper()
        self.testhelper.add(nodes='uni:admin(uniadmin)',
                            subjects=['duck2000:admin(duck2000admin)'],
                            periods=['periodone:admin(oneadmin)',
                                     'periodtwo',
                                     'periodthree:admin(adminone)'])
        self.client = RestClient()

    def _geturl(self, periodid):
        return '/devilry_subjectadmin/rest/period/{0}'.format(periodid)

    def test_delete_denied(self):
        self.client.login(username='nobody', password='test')
        content, response = self.client.rest_delete(self._geturl(self.testhelper.duck2000_periodone.id))
        self.assertEquals(response.status_code, 403)

    def test_delete(self):
        self.client.login(username='uniadmin', password='test')
        content, response = self.client.rest_delete(self._geturl(self.testhelper.duck2000_periodone.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(content['id'], self.testhelper.duck2000_periodone.id)
        self.assertEquals(Period.objects.filter(id=self.testhelper.duck2000_periodone.id).count(), 0)


    def test_get(self):
        period = self.testhelper.duck2000_periodone
        for username in ('student1', 'student2', 'student3', 'student4'):
            user = self.testhelper.create_user(username)
            period.relatedstudent_set.create(user=user)
        for username in ('examiner1', 'examiner2'):
            user = self.testhelper.create_user(username)
            period.relatedexaminer_set.create(user=user)

        self.client.login(username='duck2000admin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000_periodone.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(content['id'], self.testhelper.duck2000_periodone.id)
        self.assertEquals(content['short_name'], self.testhelper.duck2000_periodone.short_name)
        self.assertEquals(content['long_name'], self.testhelper.duck2000_periodone.long_name)
        self.assertEquals(content['parentnode'], self.testhelper.duck2000_periodone.parentnode_id)
        self.assertEquals(content['can_delete'], self.testhelper.duck2000_periodone.can_delete(self.testhelper.uniadmin))
        self.assertEquals(content['number_of_relatedexaminers'], 2)
        self.assertEquals(content['number_of_relatedstudents'], 4)
        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_relatedexaminers', 'number_of_relatedstudents']))

    def test_get_admins(self):
        self.client.login(username='duck2000admin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000_periodone.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(content['admins']), 1)
        self.assertEquals(content['admins'][0]['email'], '[email protected]')
        self.assertEquals(set(content['admins'][0].keys()),
                          set(['email', 'username', 'id', 'full_name']))

    def test_get_inherited_admins(self):
        self.client.login(username='duck2000admin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000_periodone.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(content['inherited_admins']), 2)
        self.assertEquals(set(content['inherited_admins'][0].keys()),
                          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.assertIn('uniadmin', inherited_adminusernames)
        self.assertIn('duck2000admin', inherited_adminusernames)

    def test_get_breadcrumb_periodadmin(self):
        self.testhelper.add(nodes='uni',
                            subjects=['sub'],
                            periods=['p1:admin(p1admin)'])
        self.client.login(username='p1admin', 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_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',
#.........这里部分代码省略.........
开发者ID:KorshakVladimir,项目名称:devilry-django,代码行数:103,代码来源:test_period.py

示例2: TestInstanceRelatedUserMixin

# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_delete [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)
开发者ID:KorshakVladimir,项目名称:devilry-django,代码行数:87,代码来源:test_relateduser.py

示例3: TestRestDeadlinesBulkUpdateReadOrDelete

# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_delete [as 别名]

#.........这里部分代码省略.........
        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):
        new_deadline = datetime(2004, 12, 24, 20, 30)
        g1 = self.testhelper.sub_p1_a1_g1
        g2 = self.testhelper.sub_p1_a1_g2
        self.assertEquals(g1.deadlines.count(), 1)

        content, response = self._putas('adm', {'deadline': format_datetime(new_deadline),
                                                'text': 'Updated',
                                                'group_ids': [g1.id, g2.id]})
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(content['groups']), 2)
        group_ids = set([g['id'] for g in content['groups']])
        self.assertEquals(group_ids, set([g1.id, g2.id]))

        for group in g1, g2:
            group = self.testhelper.reload_from_db(group)
            self.assertEquals(group.deadlines.count(), 1)
            deadline = group.deadlines.all()[0]
            self.assertEquals(deadline.deadline, new_deadline)
            self.assertEquals(deadline.text, 'Updated')



    def _getas(self, username, **data):
        self.client.login(username=username, password='test')
        return self.client.rest_get(self._geturl(), **data)

    def test_get(self):
        content, response = self._getas('adm')
        self.assertEquals(response.status_code, 200)
        self.assertEquals(decode_bulkdeadline_id(content['bulkdeadline_id'])[0],
                          self.testhelper.sub_p1_a1_g1_d1.deadline)
        self.assertEquals(content['deadline'],
                          format_datetime(self.testhelper.sub_p1_a1_g1_d1.deadline))
        self.assertEquals(content['text'], None)
        self.assertEquals(len(content['groups']), 3)

    def test_get_nobody(self):
        self.testhelper.create_user('nobody')
        content, response = self._getas('nobody')
        self.assertEquals(response.status_code, 403)

    def _deleteas(self, username, deadline=None):
        self.client.login(username=username, password='test')
        return self.client.rest_delete(self._geturl(deadline))

    def test_delete_sanity(self):
        # Test that the deadline method actually does what it is supposed to do (only deletes what it should delete)
        new_deadline = datetime(2004, 12, 24, 20, 30)
        created_deadline = None
        for groupnum in xrange(2):
            group = getattr(self.testhelper, 'sub_p1_a1_g{0}'.format(groupnum))
            self.assertEquals(1, group.deadlines.count())
            created_deadline = group.deadlines.create(deadline=new_deadline) # NOTE: Does not matter which deadline object we user, since we only need the datetime and text to generate bulkdeadline_id
            self.assertEquals(2, group.deadlines.count())
        self.testhelper.sub_p1_a1_g2.deadlines.create(deadline=datetime(2006, 12, 24, 20, 30))

        self.testhelper.create_superuser('superuser')
        content, response = self._deleteas('superuser', deadline=created_deadline)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(content['deleted_deadline_ids']), 2)
        self.assertEquals(1, self.testhelper.sub_p1_a1_g0.deadlines.count())
        self.assertEquals(1, self.testhelper.sub_p1_a1_g1.deadlines.count())
        self.assertEquals(2, self.testhelper.sub_p1_a1_g2.deadlines.count())

    def test_delete_with_content_as_superuser(self):
        self.testhelper.create_superuser('superuser')
        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})
        content, response = self._deleteas('superuser')
        self.assertEquals(response.status_code, 200)

    def test_delete_with_content_as_assignmentadm(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})
        content, response = self._deleteas('adm')
        self.assertEquals(response.status_code, 403)

    def test_delete_without_content_as_assignmentadm(self):
        content, response = self._deleteas('adm')
        self.assertEquals(response.status_code, 200)

    def test_delete_as_nobody(self):
        self.testhelper.create_user('nobody')
        content, response = self._deleteas('nobody')
        self.assertEquals(response.status_code, 403)
开发者ID:KorshakVladimir,项目名称:devilry-django,代码行数:104,代码来源:test_deadlinesbulk.py

示例4: TestRestInstanceAssignmentRest

# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_delete [as 别名]
class TestRestInstanceAssignmentRest(TestCase):
    def setUp(self):
        self.testhelper = TestHelper()
        self.testhelper.add(nodes='uni:admin(uniadmin)',
                            subjects=['duck2000:admin(duck2000admin)'],
                            periods=['someperiod:begins(-2):ends(6)'],
                            assignments=['first:admin(firstadmin)',
                                         'second:admin(secondadmin,firstadmin)',
                                         'third'])
        self.client = RestClient()

    def _geturl(self, assignmentid):
        return '/devilry_subjectadmin/rest/assignment/{0}'.format(assignmentid)

    def test_delete_denied(self):
        self.client.login(username='nobody', password='test')
        content, response = self.client.rest_delete(self._geturl(self.testhelper.duck2000_someperiod_first.id))
        self.assertEquals(response.status_code, 403)

    def test_delete(self):
        self.client.login(username='uniadmin', password='test')
        content, response = self.client.rest_delete(self._geturl(self.testhelper.duck2000_someperiod_first.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(content['id'], self.testhelper.duck2000_someperiod_first.id)
        self.assertEquals(Assignment.objects.filter(id=self.testhelper.duck2000_someperiod_first.id).count(), 0)

    def test_get(self):
        self.testhelper.add_to_path('uni;duck2000.someperiod.first.g1:candidate(student1):examiner(examiner1).d1')
        self.testhelper.add_to_path('uni;duck2000.someperiod.first.g2:candidate(student2,student3,student4,student5):examiner(examiner1).d1')
        self.testhelper.add_delivery('duck2000.someperiod.first.g1', {'bad.py': ['print ', 'bah']})
        self.testhelper.add_delivery('duck2000.someperiod.first.g1', {'good.py': ['print ', 'good']})
        self.testhelper.add_delivery('duck2000.someperiod.first.g2', {'good.py': ['print ', 'good']})

        self.client.login(username='duck2000admin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000_someperiod_first.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(content['id'], self.testhelper.duck2000_someperiod_first.id)
        self.assertEquals(content['short_name'], self.testhelper.duck2000_someperiod_first.short_name)
        self.assertEquals(content['long_name'], self.testhelper.duck2000_someperiod_first.long_name)
        self.assertEquals(content['deadline_handling'], self.testhelper.duck2000_someperiod_first.deadline_handling)
        self.assertEquals(content['parentnode'], self.testhelper.duck2000_someperiod_first.parentnode_id)
        self.assertEquals(content['can_delete'], self.testhelper.duck2000_someperiod_first.can_delete(self.testhelper.duck2000admin))
        self.assertEquals(content['can_delete'], False)
        self.assertEquals(content['number_of_groups'], 2)
        self.assertEquals(content['number_of_deliveries'], 3)
        self.assertEquals(content['number_of_candidates'], 5)
        self.assertEquals(content['has_valid_grading_setup'], True)
        self.assertEquals(content['gradingsystemplugin_title'], 'Passed/failed')
        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'
                               ]))

    def test_get_admins(self):
        self.client.login(username='duck2000admin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000_someperiod_first.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(content['admins']), 1)
        self.assertEquals(content['admins'][0]['email'], '[email protected]')
        self.assertEquals(set(content['admins'][0].keys()),
                          set(['email', 'username', 'id', 'full_name']))

    def test_get_inherited_admins(self):
        self.client.login(username='duck2000admin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000_someperiod_first.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(content['inherited_admins']), 2)
        self.assertEquals(set(content['inherited_admins'][0].keys()),
                          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.assertIn('uniadmin', inherited_adminusernames)
        self.assertIn('duck2000admin', inherited_adminusernames)

    def test_get_breadcrumb_assignmentadmin(self):
        self.testhelper.add(nodes='uni.inf',
                            subjects=['sub'],
                            periods=['p1'],
                            assignments=['a1:admin(a1admin)'])
        self.client.login(username='a1admin', 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.sub_p1_a1.id, u'text': u'sub.p1.a1', u'type': u'Assignment'}])

    def test_get_breadcrumb_periodadmin(self):
        self.testhelper.add(nodes='uni.inf',
#.........这里部分代码省略.........
开发者ID:KorshakVladimir,项目名称:devilry-django,代码行数:103,代码来源:test_assignment.py

示例5: TestRestInstanceSubjectRest

# 需要导入模块: from devilry.devilry_rest.testclient import RestClient [as 别名]
# 或者: from devilry.devilry_rest.testclient.RestClient import rest_delete [as 别名]
class TestRestInstanceSubjectRest(TestCase):
    def setUp(self):
        self.testhelper = TestHelper()
        self.testhelper.add(nodes='uni:admin(uniadmin)',
                            subjects=['duck2000:admin(duck2000admin):ln(Something fancy)'])
        self.client = RestClient()

    def _geturl(self, subjectid):
        return '/devilry_subjectadmin/rest/subject/{0}'.format(subjectid)

    def test_delete_denied(self):
        self.client.login(username='nobody', password='test')
        content, response = self.client.rest_delete(self._geturl(self.testhelper.duck2000.id))
        self.assertEquals(response.status_code, 403)

    def test_delete(self):
        self.client.login(username='uniadmin', password='test')
        content, response = self.client.rest_delete(self._geturl(self.testhelper.duck2000.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(content['id'], self.testhelper.duck2000.id)
        self.assertEquals(Subject.objects.filter(id=self.testhelper.duck2000.id).count(), 0)

    def test_delete_notempty(self):
        self.testhelper.add_to_path('uni;duck2000.p1')
        self.client.login(username='uniadmin', password='test')
        content, response = self.client.rest_delete(self._geturl(self.testhelper.duck2000.id))
        self.assertEquals(response.status_code, 403)
        self.assertIn('Only superadmins can delete non-empty items', content['detail'])

    def test_get(self):
        self.client.login(username='uniadmin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000.id))
        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'], self.testhelper.duck2000.long_name)
        self.assertEquals(content['parentnode'], self.testhelper.duck2000.parentnode_id)
        self.assertEquals(content['can_delete'], self.testhelper.duck2000.can_delete(self.testhelper.uniadmin))
        self.assertEquals(set(content.keys()),
                          set(['short_name', 'long_name', 'admins', 'etag',
                               'can_delete', 'parentnode', 'id', 'inherited_admins',
                               'breadcrumb']))

    def test_get_admins(self):
        self.client.login(username='uniadmin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(content['admins']), 1)
        self.assertEquals(content['admins'][0]['email'], '[email protected]')
        self.assertEquals(set(content['admins'][0].keys()),
                          set(['email', 'username', 'id', 'full_name']))

    def test_get_inherited_admins(self):
        self.client.login(username='uniadmin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.duck2000.id))
        self.assertEquals(response.status_code, 200)
        self.assertEquals(len(content['inherited_admins']), 1)
        self.assertEquals(set(content['inherited_admins'][0].keys()),
                          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'}])
#.........这里部分代码省略.........
开发者ID:KorshakVladimir,项目名称:devilry-django,代码行数:103,代码来源:test_subject.py


注:本文中的devilry.devilry_rest.testclient.RestClient.rest_delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。