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


Python RestClient.rest_put方法代码示例

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


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

示例1: TestLanguageSelect

# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.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')
开发者ID:RobertKolner,项目名称:devilry-django,代码行数:61,代码来源:tests.py

示例2: TestInstanceGroupRest

# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import rest_put [as 别名]
class TestInstanceGroupRest(TestCase, GroupManagerTestMixin):
    def setUp(self):
        self.testhelper = TestHelper()
        self.testhelper.add(nodes='uni',
                            subjects=['sub'],
                            periods=['p1'],
                            assignments=['a1:admin(a1admin)'])
        self.client = RestClient()
        self.testhelper.create_superuser('grandma')
        self.testhelper.create_user('candidate1')
        self.testhelper.create_user('examiner1')
        self.testhelper.create_superuser('superuser')
        self.a1id = self.testhelper.sub_p1_a1.id

    def _geturl(self, assignment_id, group_id):
        return '/devilry_subjectadmin/rest/group/{0}/{1}'.format(assignment_id, group_id)

    def _putas(self, username, assignment_id, group_id, data={}):
        self.client.login(username=username, password='test')
        return self.client.rest_put(self._geturl(assignment_id, group_id), 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 = {'name': 'changed',
                'is_open': False}
        content, response = self._putas('a1admin', self.a1id, group.id, data)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(set(content.keys()),
                          set(['name', 'id', 'etag', 'is_open', 'parentnode',
                               'feedback', 'deadlines', 'candidates', 'tags',
                               'examiners', 'num_deliveries']))
        self.assertEquals(content['name'], 'changed')
        self.assertEquals(content['is_open'], False)
        self.assertEquals(content['parentnode'], self.a1id)
        self.assertEquals(content['num_deliveries'], 0)
        self.assertEquals(content['feedback'], None)
        self.assertEquals(content['deadlines'], [])
        self.assertEquals(content['candidates'], [])
        self.assertEquals(content['examiners'], [])
        self.assertEquals(content['tags'], [])

        groups = self.testhelper.sub_p1_a1.assignmentgroups.all()
        self.assertEquals(len(groups), 1)
        self.assertEquals(content['id'], groups[0].id)

    def _test_put_as(self, username):
        group = self._add_group('g1', candidates='candidate2', examiners='examiner2')
        data = {'name': 'changed',
                'is_open': False,
                'examiners': [self.create_examinerdict(username='examiner1')],
                'candidates': [self.create_candidatedict(username='candidate1')],
                'tags': [self.create_tagdict('mytag')]}
        content, response = self._putas(username, self.a1id, group.id, data)
        #from pprint import pprint
        #print 'Response content:'
        #pprint(content)
        self.assertEquals(response.status_code, 200)

        self.assertEquals(content['name'], 'changed')
        self.assertEquals(content['is_open'], False)
        self.assertEquals(content['parentnode'], self.a1id)
        self.assertEquals(content['num_deliveries'], 0)

        # Feedback
        self.assertEquals(content['feedback'], None)

        # Deadlines
        self.assertEquals(content['deadlines'], [])

        # Tags
        self.assertEquals(len(content['tags']), 1)
        tag = content['tags'][0]
        self.assertEquals(tag['tag'], 'mytag')
        self.assertEquals(set(tag.keys()), set(['id', 'tag']))

        # Examiners
        self.assertEquals(len(content['examiners']), 1)
        examiner = content['examiners'][0]
        self.assertEquals(set(examiner.keys()),
                          set(['id', 'user']))
        self.assertEquals(set(examiner['user'].keys()),
                          set(['email', 'full_name', 'id', 'username']))
        self.assertEquals(examiner['user']['id'], self.testhelper.examiner1.id)
        self.assertEquals(examiner['user']['username'], 'examiner1')

        # Candidates
        self.assertEquals(len(content['candidates']), 1)
        candidate = content['candidates'][0]
        self.assertEquals(set(candidate.keys()),
                          set(['id', 'user', 'candidate_id']))
        self.assertEquals(set(candidate['user'].keys()),
                          set(['email', 'full_name', 'id', 'username']))
        self.assertEquals(candidate['user']['id'], self.testhelper.candidate1.id)
        self.assertEquals(candidate['candidate_id'], '')
#.........这里部分代码省略.........
开发者ID:TZer0,项目名称:devilry-django,代码行数:103,代码来源:group.py

示例3: TestRestPassedInPreviousPeriod

# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.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['feedback_shortformat'], 'true')



    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_shortformat': 'true'},
                                         {'id': g3.id,
                                          'newfeedback_shortformat': 'true'}])
        self.assertEquals(response.status_code, 200)

        g1 = self.testhelper.reload_from_db(g1)
        self.assertEquals(g1.feedback.grade, 'approved')
        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, 'approved')
        self.assertEquals(g3.feedback.delivery.delivery_type, deliverytypes.ALIAS)
        self.assertEquals(g3.feedback.delivery.alias_delivery, oldg3_delivery)

#.........这里部分代码省略.........
开发者ID:RobertKolner,项目名称:devilry-django,代码行数:103,代码来源:passedinpreviousperiod.py

示例4: TestInstanceRelatedUserMixin

# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.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"]))
        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:TZer0,项目名称:devilry-django,代码行数:81,代码来源:relateduser.py

示例5: TestRestInstancePeriodRest

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

示例6: TestGroupRest

# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.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={}):
        self.client.login(username=username, password='test')
        return self.client.rest_put(self._geturl(assignment_id), 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()
开发者ID:espenak,项目名称:devilry-django,代码行数:70,代码来源:group.py

示例7: TestRestInstanceAssignmentRest

# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import rest_put [as 别名]

#.........这里部分代码省略.........
        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']))
        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(self):
        self.testhelper.add(nodes='duck.mat.inf',
                            subjects=['s1'],
                            periods=['p1'],
                            assignments=['a1:admin(a1admin)'])
        self.client.login(username='a1admin', password='test')
        content, response = self.client.rest_get(self._geturl(self.testhelper.s1_p1_a1.id))
        self.assertEquals(response.status_code, 200)
        th = self.testhelper
        self.assertEquals(content['breadcrumb'],
                          [{u'id': th.duck.id, u'short_name': u'duck', u'type': u'Node'},
                           {u'id': th.duck_mat.id, u'short_name': u'mat', u'type': u'Node'},
                           {u'id': th.duck_mat_inf.id, u'short_name': u'inf', u'type': u'Node'},
                           {u'id': th.s1.id, u'short_name': u's1', u'type': u'Subject'},
                           {u'id': th.s1_p1.id, u'short_name': u'p1', u'type': u'Period'}])

    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', 'etag',
                               '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']))
        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)
开发者ID:TZer0,项目名称:devilry-django,代码行数:104,代码来源:assignment.py

示例8: TestInstanceRelatedUserMixin

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

示例9: TestRestInstanceSubjectRest

# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.rest_testclient.RestClient import rest_put [as 别名]

#.........这里部分代码省略.........
        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)
开发者ID:espenak,项目名称:devilry-django,代码行数:104,代码来源:subject.py


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