1 | n/a | from test import support |
---|
2 | n/a | import unittest |
---|
3 | n/a | |
---|
4 | n/a | # Skip test if nis module does not exist. |
---|
5 | n/a | nis = support.import_module('nis') |
---|
6 | n/a | |
---|
7 | n/a | |
---|
8 | n/a | class NisTests(unittest.TestCase): |
---|
9 | n/a | def test_maps(self): |
---|
10 | n/a | try: |
---|
11 | n/a | maps = nis.maps() |
---|
12 | n/a | except nis.error as msg: |
---|
13 | n/a | # NIS is probably not active, so this test isn't useful |
---|
14 | n/a | self.skipTest(str(msg)) |
---|
15 | n/a | try: |
---|
16 | n/a | # On some systems, this map is only accessible to the |
---|
17 | n/a | # super user |
---|
18 | n/a | maps.remove("passwd.adjunct.byname") |
---|
19 | n/a | except ValueError: |
---|
20 | n/a | pass |
---|
21 | n/a | |
---|
22 | n/a | done = 0 |
---|
23 | n/a | for nismap in maps: |
---|
24 | n/a | mapping = nis.cat(nismap) |
---|
25 | n/a | for k, v in mapping.items(): |
---|
26 | n/a | if not k: |
---|
27 | n/a | continue |
---|
28 | n/a | if nis.match(k, nismap) != v: |
---|
29 | n/a | self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap)) |
---|
30 | n/a | else: |
---|
31 | n/a | # just test the one key, otherwise this test could take a |
---|
32 | n/a | # very long time |
---|
33 | n/a | done = 1 |
---|
34 | n/a | break |
---|
35 | n/a | if done: |
---|
36 | n/a | break |
---|
37 | n/a | |
---|
38 | n/a | if __name__ == '__main__': |
---|
39 | n/a | unittest.main() |
---|