Make unittest compatible with python <= 2.6

pull/7444/head
Toshio Kuratomi 10 years ago
parent 313f26f866
commit e00d657362

@ -294,12 +294,20 @@ class TestModuleUtilsBasicHelpers(unittest.TestCase):
ssh_output = self.module._heuristic_log_sanitize(ssh_data) ssh_output = self.module._heuristic_log_sanitize(ssh_data)
# Basic functionality: Successfully hid the password # Basic functionality: Successfully hid the password
self.assertNotIn('pas:word', url_output) try:
self.assertNotIn('pas:word', ssh_output) self.assertNotIn('pas:word', url_output)
self.assertNotIn('pas:word', ssh_output)
# Slightly more advanced, we hid all of the password despite the ":"
self.assertNotIn('pas', url_output)
self.assertNotIn('pas', ssh_output)
except AttributeError:
# python2.6 or less's unittest
self.assertFalse('pas:word' in url_output, '%s is present in %s' % ('"pas:word"', url_output))
self.assertFalse('pas:word' in ssh_output, '%s is present in %s' % ('"pas:word"', ssh_output))
# Slightly more advanced, we hid all of the password despite the ":" self.assertFalse('pas' in url_output, '%s is present in %s' % ('"pas"', url_output))
self.assertNotIn('pas', url_output) self.assertFalse('pas' in ssh_output, '%s is present in %s' % ('"pas"', ssh_output))
self.assertNotIn('pas', ssh_output)
# In this implementation we replace the password with 8 "*" which is # In this implementation we replace the password with 8 "*" which is
# also the length of our password. The url fields should be able to # also the length of our password. The url fields should be able to
@ -313,7 +321,11 @@ class TestModuleUtilsBasicHelpers(unittest.TestCase):
# the data, though: # the data, though:
self.assertTrue(ssh_output.startswith("{'")) self.assertTrue(ssh_output.startswith("{'"))
self.assertTrue(ssh_output.endswith("'}}}}")) self.assertTrue(ssh_output.endswith("'}}}}"))
self.assertIn(":********@foo.com/data',", ssh_output) try:
self.assertIn(":********@foo.com/data',", ssh_output)
except AttributeError:
# python2.6 or less's unittest
self.assertTrue(":********@foo.com/data'," in ssh_output, '%s is not present in %s' % (":********@foo.com/data',", ssh_output))
# The overzealous-ness here may lead to us changing the algorithm in # The overzealous-ness here may lead to us changing the algorithm in
# the future. We could make it consume less of the data (with the # the future. We could make it consume less of the data (with the

Loading…
Cancel
Save