def test_uoar_deny(self): """ Test denying of a user-org-affiliation-request org_admin_views.uoar_deny """ # create a uoar for user d uoar = models.UserOrgAffiliationRequest.objects.create( user=self.user_d, asn=1, status="pending") # test that org id was properly derived from network asn self.assertEqual(uoar.org.id, self.org.id) # test deny request = self.factory.post("/org-admin/uoar/deny?org_id=%d" % self.org.id, data={"id": uoar.id}) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = json.loads(org_admin.uoar_deny(request).content) self.assertEqual( { "status": "ok", }, resp, ) # check that user is not a member of the org self.assertEqual( self.org.usergroup.user_set.filter(id=self.user_d.id).exists(), False) # check that the UOAR is there, but status is denyed uoar = models.UserOrgAffiliationRequest.objects.get(id=uoar.id) self.assertEqual(uoar.status, "denied") # test: we shouldnt be allowed to deny uoars for the org we are not # admins of request = self.factory.post("/org-admin/uoar/deny?org_id=%d" % self.org_other.id, data={"id": uoar.id}) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.uoar_approve(request) self.assertEqual(resp.status_code, 403) self.assertEqual(json.loads(resp.content), {}) # test: trying to deny an uoar that doesn't belong to the org shouldn't # be allowed uoar_b = models.UserOrgAffiliationRequest.objects.create( user=self.user_d, asn=22, status="pending") request = self.factory.post("/org-admin/uoar/deny?org_id=%d" % self.org.id, data={"id": uoar_b.id}) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.uoar_deny(request) self.assertEqual(resp.status_code, 403) self.assertEqual(json.loads(resp.content), {}) uoar_b.delete()
def test_uoar_deny(self): """ Test denying of a user-org-affiliation-request org_admin_views.uoar_deny """ # create a uoar for user d uoar = models.UserOrgAffiliationRequest.objects.create( user=self.user_d, asn=1, status="pending") # test that org id was properly derived from network asn self.assertEqual(uoar.org.id, self.org.id) # test deny request = self.factory.post( "/org-admin/uoar/deny?org_id=%d" % self.org.id, data={ "id": uoar.id }) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = json.loads(org_admin.uoar_deny(request).content) self.assertEqual({ "status": "ok", }, resp) # check that user is not a member of the org self.assertEqual( self.org.usergroup.user_set.filter(id=self.user_d.id).exists(), False) # check that the UOAR is there, but status is denyed uoar = models.UserOrgAffiliationRequest.objects.get(id=uoar.id) self.assertEqual(uoar.status, "denied") # test: we shouldnt be allowed to deny uoars for the org we are not # admins of request = self.factory.post( "/org-admin/uoar/deny?org_id=%d" % self.org_other.id, data={ "id": uoar.id }) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.uoar_approve(request) self.assertEqual(resp.status_code, 403) self.assertEqual(json.loads(resp.content), {}) # test: trying to deny an uoar that doesn't belong to the org shouldn't # be allowed uoar_b = models.UserOrgAffiliationRequest.objects.create( user=self.user_d, asn=22, status="pending") request = self.factory.post( "/org-admin/uoar/deny?org_id=%d" % self.org.id, data={ "id": uoar_b.id }) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.uoar_deny(request) self.assertEqual(resp.status_code, 403) self.assertEqual(json.loads(resp.content), {}) uoar_b.delete()