10a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom test import test_support 20a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport unittest 30a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 40a8c90248264a8b26970b4473770bcc3df8515fJosh Gaonis = test_support.import_module('nis') 50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 60a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass NisTests(unittest.TestCase): 70a8c90248264a8b26970b4473770bcc3df8515fJosh Gao def test_maps(self): 80a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 90a8c90248264a8b26970b4473770bcc3df8515fJosh Gao maps = nis.maps() 100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except nis.error, msg: 110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # NIS is probably not active, so this test isn't useful 120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if test_support.verbose: 130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao print "Test Skipped:", msg 140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # Can't raise SkipTest as regrtest only recognizes the exception 150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # import time. 160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao return 170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao try: 180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # On some systems, this map is only accessible to the 190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # super user 200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao maps.remove("passwd.adjunct.byname") 210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao except ValueError: 220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao pass 230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao done = 0 250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for nismap in maps: 260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao mapping = nis.cat(nismap) 270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao for k, v in mapping.items(): 280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if not k: 290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao continue 300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if nis.match(k, nismap) != v: 310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao self.fail("NIS match failed for key `%s' in map `%s'" % (k, nismap)) 320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao else: 330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # just test the one key, otherwise this test could take a 340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao # very long time 350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao done = 1 360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao break 370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao if done: 380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao break 390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 400a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef test_main(): 410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao test_support.run_unittest(NisTests) 420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao 430a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif __name__ == '__main__': 440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao test_main() 45