update link to upper-constraints.txt
[optf/osdf.git] / test / local_data / test_local_policies.py
1 # -------------------------------------------------------------------------
2 #   Copyright (c) 2017-2018 AT&T Intellectual Property
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15 #
16 # -------------------------------------------------------------------------
17 #
18 import re
19 import unittest
20
21 from osdf.adapters.local_data import local_policies
22
23
24 class TestLocalPolicies(unittest.TestCase):
25
26     def __init__(self, *args, **kwargs):
27         super(self.__class__, self).__init__(*args, **kwargs)
28         self.folder = './test/policy-local-files'
29         self.valid_policies_file = self.folder + '/' + 'meta-valid-policies.txt'
30         self.invalid_policies_file = self.folder + '/' + 'meta-invalid-policies.txt'
31         self.valid_policies = local_policies.get_policy_names_from_file(self.valid_policies_file)
32         self.invalid_policies = local_policies.get_policy_names_from_file(self.invalid_policies_file)
33
34
35     def test_get_local_policies_no_policies(self):
36         with self.assertRaises(FileNotFoundError):
37              res = local_policies.get_local_policies(self.folder, self.invalid_policies)
38              assert res is None
39
40     def test_get_local_valid_policies(self):
41         res = local_policies.get_local_policies(self.folder, self.valid_policies)
42         assert len(res) == len(self.valid_policies)
43
44     def test_get_subset_valid_policies(self):
45         wanted = [ x[:-5] for x in self.valid_policies[:1] ]
46         res = local_policies.get_local_policies(self.folder, self.valid_policies, wanted)
47         assert len(res) == len(wanted)
48
49
50 if __name__ == "__main__":
51     unittest.main()
52