Ejemplo n.º 1
0
 def delete_policy(self, id_):
     # Note(thread-safety): blocking call
     db_object = db_library_policies.get_policy(id_)
     db_library_policies.delete_policy(id_)
     return db_object.to_dict(include_rules=True)
Ejemplo n.º 2
0
    def test_create_get_policy(self):
        policy1 = db_library_policies.add_policy({
            'name':
            'policy1',
            'abbreviation':
            'abbr',
            'kind':
            'database',
            'description':
            'descrip',
            'rules': [{
                'rule': 'p(x) :- q(x)',
                'comment': 'test comment',
                'name': 'testname'
            }]
        })

        res = db_library_policies.get_policies()
        self.assertEqual([p.to_dict(include_rules=True) for p in res], [{
            'id':
            policy1['id'],
            'abbreviation':
            'abbr',
            'kind':
            'database',
            'name':
            'policy1',
            'description':
            'descrip',
            'rules': [{
                'rule': 'p(x) :- q(x)',
                'comment': 'test comment',
                'name': 'testname'
            }]
        }])

        res = db_library_policies.get_policy(policy1['id'])
        self.assertEqual(
            res.to_dict(include_rules=True), {
                'id':
                policy1['id'],
                'abbreviation':
                'abbr',
                'kind':
                'database',
                'name':
                'policy1',
                'description':
                'descrip',
                'rules': [{
                    'rule': 'p(x) :- q(x)',
                    'comment': 'test comment',
                    'name': 'testname'
                }]
            })

        res = db_library_policies.get_policy_by_name(policy1['name'])
        self.assertEqual(
            res.to_dict(include_rules=True), {
                'id':
                policy1['id'],
                'abbreviation':
                'abbr',
                'kind':
                'database',
                'name':
                'policy1',
                'description':
                'descrip',
                'rules': [{
                    'rule': 'p(x) :- q(x)',
                    'comment': 'test comment',
                    'name': 'testname'
                }]
            })

        self.assertRaises(KeyError, db_library_policies.get_policy,
                          'no_such_policy')

        self.assertRaises(KeyError, db_library_policies.get_policy_by_name,
                          'no_such_policy')
Ejemplo n.º 3
0
 def get_policy(self, id_, include_rules=True):
     # Note(thread-safety): blocking call
     policy = db_library_policies.get_policy(id_)
     return policy.to_dict(include_rules)