From e00d657362497bd5fe0b4aad036d04d72999b42b Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 1 Oct 2014 11:50:45 -0400 Subject: [PATCH] Make unittest compatible with python <= 2.6 --- test/units/TestModuleUtilsBasic.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/test/units/TestModuleUtilsBasic.py b/test/units/TestModuleUtilsBasic.py index 2ffb310b95e..ceba17be4fd 100644 --- a/test/units/TestModuleUtilsBasic.py +++ b/test/units/TestModuleUtilsBasic.py @@ -294,12 +294,20 @@ class TestModuleUtilsBasicHelpers(unittest.TestCase): ssh_output = self.module._heuristic_log_sanitize(ssh_data) # Basic functionality: Successfully hid the password - self.assertNotIn('pas:word', url_output) - self.assertNotIn('pas:word', ssh_output) + try: + 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.assertNotIn('pas', url_output) - self.assertNotIn('pas', ssh_output) + self.assertFalse('pas' in url_output, '%s is present in %s' % ('"pas"', url_output)) + self.assertFalse('pas' in ssh_output, '%s is present in %s' % ('"pas"', ssh_output)) # In this implementation we replace the password with 8 "*" which is # also the length of our password. The url fields should be able to @@ -313,7 +321,11 @@ class TestModuleUtilsBasicHelpers(unittest.TestCase): # the data, though: self.assertTrue(ssh_output.startswith("{'")) 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 future. We could make it consume less of the data (with the