コード例 #1
0
    def test_delete_policy(self):
        db_library_policies.delete_policy('policy1')

        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'
            }]
        })

        policy2 = db_library_policies.add_policy({
            'name':
            'policy2',
            '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(len(res), 2)

        db_library_policies.delete_policy('no_such_policy')

        res = db_library_policies.get_policies()
        self.assertEqual(len(res), 2)

        db_library_policies.delete_policy(policy1['id'])

        res = db_library_policies.get_policies()
        self.assertEqual(len(res), 1)

        db_library_policies.delete_policy(policy2['id'])

        res = db_library_policies.get_policies()
        self.assertEqual(len(res), 0)
コード例 #2
0
    def test_get_policy_empty(self):
        res = db_library_policies.get_policies()
        self.assertEqual(res, [])

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

        self.assertRaises(KeyError, db_library_policies.get_policy_by_name,
                          'nosuchpolicy')
コード例 #3
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')
コード例 #4
0
 def get_policies(self, include_rules=True):
     return [
         p.to_dict(include_rules)
         for p in db_library_policies.get_policies()
     ]