Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 1 | from test import support |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 2 | import unittest |
Alexandre Vassalotti | b66c67d | 2009-07-22 04:27:34 +0000 | [diff] [blame] | 3 | import sys |
R. David Murray | a21e4ca | 2009-03-31 23:16:50 +0000 | [diff] [blame] | 4 | |
| 5 | # Skip test if nis module does not exist. |
| 6 | nis = support.import_module('nis') |
Barry Warsaw | 3236b33 | 1996-12-11 01:01:38 +0000 | [diff] [blame] | 7 | |
Benjamin Peterson | e9ea19e | 2008-08-19 23:02:38 +0000 | [diff] [blame] | 8 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 9 | class NisTests(unittest.TestCase): |
| 10 | def test_maps(self): |
| 11 | try: |
| 12 | maps = nis.maps() |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 13 | except nis.error as msg: |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 14 | # NIS is probably not active, so this test isn't useful |
Zachary Ware | 9fe6d86 | 2013-12-08 00:20:35 -0600 | [diff] [blame^] | 15 | self.skipTest(str(msg)) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 16 | try: |
| 17 | # On some systems, this map is only accessible to the |
| 18 | # super user |
| 19 | maps.remove("passwd.adjunct.byname") |
| 20 | except ValueError: |
| 21 | pass |
Barry Warsaw | 4c4d5ce | 1997-05-15 18:27:49 +0000 | [diff] [blame] | 22 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 23 | done = 0 |
| 24 | for nismap in maps: |
| 25 | mapping = nis.cat(nismap) |
| 26 | for k, v in mapping.items(): |
| 27 | if not k: |
| 28 | continue |
| 29 | if nis.match(k, nismap) != v: |
| 30 | self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap)) |
| 31 | else: |
| 32 | # just test the one key, otherwise this test could take a |
| 33 | # very long time |
| 34 | done = 1 |
| 35 | break |
| 36 | if done: |
| 37 | break |
| 38 | |
| 39 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 40 | support.run_unittest(NisTests) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 41 | |
| 42 | if __name__ == '__main__': |
| 43 | test_main() |