Esempio n. 1
0
 def test_add_delete_get_policy_rule(self):
     id = uuidutils.generate_uuid()
     rule_str = "p(x) :- q(x)"
     policy_name = "classification"
     comment = "None"
     db_policy_rules.add_policy_rule(id=id,
                                     policy_name=policy_name,
                                     rule=rule_str,
                                     comment=comment)
     db_policy_rules.delete_policy_rule(id)
     rule = db_policy_rules.get_policy_rule(id, policy_name)
     self.assertIsNone(rule)
Esempio n. 2
0
 def test_add_delete_get_policy_rule(self):
     id = uuidutils.generate_uuid()
     rule_str = "p(x) :- q(x)"
     policy_name = "classification"
     comment = "None"
     db_policy_rules.add_policy_rule(id=id,
                                     policy_name=policy_name,
                                     rule=rule_str,
                                     comment=comment)
     db_policy_rules.delete_policy_rule(id)
     rule = db_policy_rules.get_policy_rule(id, policy_name)
     self.assertEqual(rule, None)
Esempio n. 3
0
 def test_add_delete_get_deleted_policy_rule(self):
     id = uuidutils.generate_uuid()
     rule_str = "p(x) :- q(x)"
     policy_name = "classification"
     comment = "None"
     rule1 = db_policy_rules.add_policy_rule(id=id,
                                             policy_name=policy_name,
                                             rule=rule_str,
                                             comment=comment)
     db_policy_rules.delete_policy_rule(id)
     rule2 = db_policy_rules.get_policy_rule(id, policy_name, deleted=True)
     self.assertEqual(rule1.id, rule2.id)
     self.assertNotEqual(rule1.deleted, rule2.deleted)
Esempio n. 4
0
 def test_add_get_policy_rule(self):
     id = uuidutils.generate_uuid()
     rule_str = "p(x) :- q(x)"
     policy_name = "classification"
     comment = "None"
     db_policy_rules.add_policy_rule(id=id,
                                     policy_name=policy_name,
                                     rule=rule_str,
                                     comment=comment)
     rule = db_policy_rules.get_policy_rule(id, policy_name)
     self.assertEqual(id, rule.id)
     self.assertEqual(policy_name, rule.policy_name)
     self.assertEqual(rule_str, rule.rule)
     self.assertEqual(comment, rule.comment)
Esempio n. 5
0
    def get_item(self, id_, params, context=None):
        """Retrieve item with id id_ from model.

        Args:
            id_: The ID of the item to retrieve
            params: A dict-like object containing parameters
                    from the request query string and body.
            context: Key-values providing frame of reference of request

        Returns:
             The matching item or None if item with id_ does not exist.
        """
        policy_name = self.policy_name(context)
        rule = db_policy_rules.get_policy_rule(id_, policy_name)
        if rule is None:
            return
        d = {'rule': rule.rule,
             'id': rule.id,
             'comment': rule.comment}
        return d
Esempio n. 6
0
    def get_item(self, id_, params, context=None):
        """Retrieve item with id id_ from model.

        Args:
            id_: The ID of the item to retrieve
            params: A dict-like object containing parameters
                    from the request query string and body.
            context: Key-values providing frame of reference of request

        Returns:
             The matching item or None if item with id_ does not exist.
        """
        policy_name = self.policy_name(context)
        rule = db_policy_rules.get_policy_rule(id_, policy_name)
        if rule is None:
            return
        d = {
            'rule': rule.rule,
            'id': rule.id,
            'comment': rule.comment,
            'name': rule.name
        }
        return d