Example #1
0
    def test_permissions(self):
        """
        Test the result of org_admin_views.permissions
        """

        # Test #1 - retrieve permissioning ids for org

        request = self.factory.get("/org-admin/permissions?org_id=%d" %
                                   self.org.id)
        request.user = self.org_admin
        resp = json.loads(org_admin.permissions(request).content)

        self.assertEqual(resp["status"], "ok")

        ids = {r["id"]: r["name"] for r in resp["permissions"]}
        self.assertEqual(len(ids), 7)
        self.assertIn("org.%d" % self.org.id, ids)
        self.assertIn("ix.%d" % self.ix.id, ids)
        self.assertIn("net.%d" % self.net.id, ids)
        self.assertIn("fac.%d" % self.fac.id, ids)

        # Test #2 - cannot retrieve ids for other org as we are not admin
        request = self.factory.get("/org-admin/permissions?org_id=%d" %
                                   self.org_other.id)
        request.user = self.org_admin
        resp = org_admin.permissions(request)
        self.assertEqual(resp.status_code, 403)
        self.assertEqual(json.loads(resp.content), {})
Example #2
0
    def test_permissions(self):
        """
        Test the result of org_admin_views.permissions
        """

        # Test #1 - retrieve permissioning ids for org

        request = self.factory.get(
            "/org-admin/permissions?org_id=%d" % self.org.id)
        request.user = self.org_admin
        resp = json.loads(org_admin.permissions(request).content)

        self.assertEqual(resp["status"], "ok")

        ids = dict([(r["id"], r["name"]) for r in resp["permissions"]])
        self.assertEqual(len(ids), 7)
        self.assertIn("org.%d" % self.org.id, ids)
        self.assertIn("ix.%d" % self.ix.id, ids)
        self.assertIn("net.%d" % self.net.id, ids)
        self.assertIn("fac.%d" % self.fac.id, ids)

        # Test #2 - cannot retrieve ids for other org as we are not admin
        request = self.factory.get(
            "/org-admin/permissions?org_id=%d" % self.org_other.id)
        request.user = self.org_admin
        resp = org_admin.permissions(request)
        self.assertEqual(resp.status_code, 403)
        self.assertEqual(json.loads(resp.content), {})