def test_user_permissions(self): """ Test the result of org_admin_views.user_permissions Test org_admin_views.save_user_permissions Test org_admin_views.load_user_permissions """ # Test #1 - test user a's permission to the org request = self.factory.get("/org-admin/user_permissions?org_id=%d" % (self.org.id)) request.user = self.org_admin uid = str(self.user_a.id) # we make some temporary perms for user_a perms = {uid: {"net.%d" % self.net.id: 0x01, "fac": 0x03}} org_admin.save_user_permissions(self.org, self.user_a, perms[uid]) resp = json.loads(org_admin.user_permissions(request).content) self.assertEqual(resp["status"], "ok") self.assertEqual(resp["user_permissions"], perms) # Test #2 - clear the perms we just made for this test org_admin.save_user_permissions(self.org, self.user_a, {}) resp = json.loads(org_admin.user_permissions(request).content) self.assertEqual(resp["status"], "ok") self.assertEqual(resp["user_permissions"], {uid: {}}) # Test #5 - no permissions to org request = self.factory.get("/org-admin/user_permissions?org_id=%d" % (self.org_other.id)) request.user = self.org_admin resp = org_admin.user_permissions(request) self.assertEqual(resp.status_code, 403) self.assertEqual(json.loads(resp.content), {})
def test_user_permissions(self): """ Test the result of org_admin_views.user_permissions Test org_admin_views.save_user_permissions Test org_admin_views.load_user_permissions """ # Test #1 - test user a's permission to the org request = self.factory.get( "/org-admin/user_permissions?org_id=%d" % (self.org.id)) request.user = self.org_admin uid = str(self.user_a.id) # we make some temporary perms for user_a perms = {uid: {"net.%d" % self.net.id: 0x01, "fac": 0x03}} org_admin.save_user_permissions(self.org, self.user_a, perms[uid]) resp = json.loads(org_admin.user_permissions(request).content) self.assertEqual(resp["status"], "ok") self.assertEqual(resp["user_permissions"], perms) # Test #2 - clear the perms we just made for this test org_admin.save_user_permissions(self.org, self.user_a, {}) resp = json.loads(org_admin.user_permissions(request).content) self.assertEqual(resp["status"], "ok") self.assertEqual(resp["user_permissions"], {uid: {}}) # Test #5 - no permissions to org request = self.factory.get( "/org-admin/user_permissions?org_id=%d" % (self.org_other.id)) request.user = self.org_admin resp = org_admin.user_permissions(request) self.assertEqual(resp.status_code, 403) self.assertEqual(json.loads(resp.content), {})