示例#1
0
    def test_extract_permission_id(self):
        """
        Test the result of org_admin_views.extract_permission_id
        """

        # extract permission ids to here
        dest = {}

        # prepare source dict with nsp namespaces
        source = {
            self.net.grainy_namespace: 0x01,
            self.ix.grainy_namespace: 0x01,
            self.fac.grainy_namespace: 0x01,
        }

        # extract ids

        org_admin.extract_permission_id(source, dest, self.net, self.org)
        org_admin.extract_permission_id(source, dest, self.ix, self.org)
        org_admin.extract_permission_id(source, dest, self.fac, self.org)

        self.assertEqual(
            {
                "net.%d" % self.net.id: 0x01,
                "ix.%d" % self.ix.id: 0x01,
                "fac.%d" % self.fac.id: 0x01,
            },
            dest,
        )

        # test with just the models

        # extract permission ids to here
        dest = {}

        # prepare source dict with nsp namespaces
        source = {
            self.net.Grainy.namespace_instance("*", org=self.net.org).strip(".*"):
            0x01,
            self.fac.Grainy.namespace_instance("*", org=self.net.org).strip(".*"):
            0x03,
            self.ix.Grainy.namespace_instance("*", org=self.net.org).strip(".*"):
            0x01,
        }

        # extract ids
        org_admin.extract_permission_id(source, dest, models.Network, self.org)
        org_admin.extract_permission_id(source, dest, models.InternetExchange,
                                        self.org)
        org_admin.extract_permission_id(source, dest, models.Facility,
                                        self.org)

        self.assertEqual({"net": 0x01, "fac": 0x03, "ix": 0x01}, dest)
示例#2
0
    def test_extract_permission_id(self):
        """
        Test the result of org_admin_views.extract_permission_id
        """

        # extract permission ids to here
        dest = {}

        # prepare source dict with nsp namespaces
        source = {
            self.net.nsp_namespace: 0x01,
            self.ix.nsp_namespace: 0x01,
            self.fac.nsp_namespace: 0x01
        }

        # extract ids

        org_admin.extract_permission_id(source, dest, self.net, self.org)
        org_admin.extract_permission_id(source, dest, self.ix, self.org)
        org_admin.extract_permission_id(source, dest, self.fac, self.org)

        self.assertEqual({
            "net.%d" % self.net.id: 0x01,
            "ix.%d" % self.ix.id: 0x01,
            "fac.%d" % self.fac.id: 0x01
        }, dest)

        # test with just the models

        # extract permission ids to here
        dest = {}

        # prepare source dict with nsp namespaces
        source = {
            self.net.nsp_namespace_from_id(self.org.id, "*").strip(".*"): 0x01,
            self.fac.nsp_namespace_from_id(self.org.id, "*").strip(".*"): 0x03,
            self.ix.nsp_namespace_from_id(self.org.id, "*").strip(".*"): 0x01,
        }

        # extract ids
        org_admin.extract_permission_id(source, dest, models.Network, self.org)
        org_admin.extract_permission_id(source, dest, models.InternetExchange,
                                        self.org)
        org_admin.extract_permission_id(source, dest, models.Facility,
                                        self.org)

        self.assertEqual({"net": 0x01, "fac": 0x03, "ix": 0x01}, dest)