blob: 21074c68106a3fcdfaa403f7458cd51ac636c1b4 [file] [log] [blame]
Benjamin Petersonee8712c2008-05-20 21:35:26 +00001from test import support
Thomas Wouters89f507f2006-12-13 04:49:30 +00002import unittest
R. David Murraya21e4ca2009-03-31 23:16:50 +00003
4# Skip test if nis module does not exist.
5nis = support.import_module('nis')
Barry Warsaw3236b331996-12-11 01:01:38 +00006
Benjamin Petersone9ea19e2008-08-19 23:02:38 +00007
Thomas Wouters89f507f2006-12-13 04:49:30 +00008class NisTests(unittest.TestCase):
9 def test_maps(self):
10 try:
11 maps = nis.maps()
Guido van Rossumb940e112007-01-10 16:19:56 +000012 except nis.error as msg:
Thomas Wouters89f507f2006-12-13 04:49:30 +000013 # NIS is probably not active, so this test isn't useful
Zachary Ware9fe6d862013-12-08 00:20:35 -060014 self.skipTest(str(msg))
Thomas Wouters89f507f2006-12-13 04:49:30 +000015 try:
16 # On some systems, this map is only accessible to the
17 # super user
18 maps.remove("passwd.adjunct.byname")
19 except ValueError:
20 pass
Barry Warsaw4c4d5ce1997-05-15 18:27:49 +000021
Thomas Wouters89f507f2006-12-13 04:49:30 +000022 done = 0
23 for nismap in maps:
24 mapping = nis.cat(nismap)
25 for k, v in mapping.items():
26 if not k:
27 continue
28 if nis.match(k, nismap) != v:
29 self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap))
30 else:
31 # just test the one key, otherwise this test could take a
32 # very long time
33 done = 1
34 break
35 if done:
36 break
37
Thomas Wouters89f507f2006-12-13 04:49:30 +000038if __name__ == '__main__':
Zachary Ware38c707e2015-04-13 15:00:43 -050039 unittest.main()