def test_manage_user_delete(self): """ Test the result of org_admin_views.manager_user_delete """ self.org.admin_usergroup.user_set.add(self.user_e) self.org.usergroup.user_set.add(self.user_f) # make sure that user f is currently member and not admin self.assertEqual(self.user_f.is_org_member(self.org), True) self.assertEqual(self.user_f.is_org_admin(self.org), False) self.assertEqual(self.user_e.is_org_member(self.org), False) self.assertEqual(self.user_e.is_org_admin(self.org), True) # test #1 - remove user f (member) from org request = self.factory.post( "/org-admin/manage_user/delete", { "org_id": self.org.id, "user_id": self.user_f.id }, ) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.manage_user_delete(request) self.assertEqual(json.loads(resp.content), {"status": "ok"}) self.user_a.refresh_from_db() self.assertEqual(self.user_f.is_org_member(self.org), False) self.assertEqual(self.user_f.is_org_admin(self.org), False) # test #2 - remove user e (admin) from org request = self.factory.post( "/org-admin/manage_user/delete", { "org_id": self.org.id, "user_id": self.user_e.id }, ) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.manage_user_delete(request) self.assertEqual(json.loads(resp.content), {"status": "ok"}) self.user_a.refresh_from_db() self.assertEqual(self.user_e.is_org_member(self.org), False) self.assertEqual(self.user_e.is_org_admin(self.org), False) # test #3 - fail on user that is not currently in org request = self.factory.post( "/org-admin/manage_user/delete", { "org_id": self.org.id, "user_id": self.user_d.id }, ) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.manage_user_delete(request) self.assertEqual(resp.status_code, 403) # test #3 - fail on org that you are not an admin of request = self.factory.post( "/org-admin/manage_user/delete", { "org_id": self.org_other.id, "user_id": self.user_d.id }, ) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.manage_user_delete(request) self.assertEqual(resp.status_code, 403)
def test_manage_user_delete(self): """ Test the result of org_admin_views.manager_user_delete """ self.org.admin_usergroup.user_set.add(self.user_e) self.org.usergroup.user_set.add(self.user_f) # make sure that user f is currently member and not admin self.assertEqual(self.user_f.is_org_member(self.org), True) self.assertEqual(self.user_f.is_org_admin(self.org), False) self.assertEqual(self.user_e.is_org_member(self.org), False) self.assertEqual(self.user_e.is_org_admin(self.org), True) # test #1 - remove user f (member) from org request = self.factory.post("/org-admin/manage_user/delete", { "org_id": self.org.id, "user_id": self.user_f.id }) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.manage_user_delete(request) self.assertEqual(json.loads(resp.content), {"status": "ok"}) self.user_a.refresh_from_db() self.assertEqual(self.user_f.is_org_member(self.org), False) self.assertEqual(self.user_f.is_org_admin(self.org), False) # test #2 - remove user e (admin) from org request = self.factory.post("/org-admin/manage_user/delete", { "org_id": self.org.id, "user_id": self.user_e.id }) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.manage_user_delete(request) self.assertEqual(json.loads(resp.content), {"status": "ok"}) self.user_a.refresh_from_db() self.assertEqual(self.user_e.is_org_member(self.org), False) self.assertEqual(self.user_e.is_org_admin(self.org), False) # test #3 - fail on user that is not currently in org request = self.factory.post("/org-admin/manage_user/delete", { "org_id": self.org.id, "user_id": self.user_d.id }) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.manage_user_delete(request) self.assertEqual(resp.status_code, 403) # test #3 - fail on org that you are not an admin of request = self.factory.post("/org-admin/manage_user/delete", { "org_id": self.org_other.id, "user_id": self.user_d.id }) request._dont_enforce_csrf_checks = True request.user = self.org_admin resp = org_admin.manage_user_delete(request) self.assertEqual(resp.status_code, 403)