本文整理汇总了Python中devilry.utils.rest_testclient.RestClient.rest_delete方法的典型用法代码示例。如果您正苦于以下问题:Python RestClient.rest_delete方法的具体用法?Python RestClient.rest_delete怎么用?Python RestClient.rest_delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类devilry.utils.rest_testclient.RestClient
的用法示例。
在下文中一共展示了RestClient.rest_delete方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestRestInstancePeriodRest
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.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',
#.........这里部分代码省略.........
示例2: TestInstanceRelatedUserMixin
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.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"]))
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)
示例3: TestRestInstanceAssignmentRest
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.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.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.uniadmin))
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']))
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']))
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}
#.........这里部分代码省略.........
示例4: TestInstanceRelatedUserMixin
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.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)
示例5: TestRestInstanceSubjectRest
# 需要导入模块: from devilry.utils.rest_testclient import RestClient [as 别名]
# 或者: from devilry.utils.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"},
],
)
#.........这里部分代码省略.........