Fixed most of the unit tests to work on all python versions
authorAleksey Maksimov <ctpeko3a@gmail.com>
Fri, 18 Apr 2014 09:23:07 +0000 (17:23 +0800)
committerAleksey Maksimov <ctpeko3a@gmail.com>
Fri, 25 Apr 2014 13:45:58 +0000 (21:45 +0800)
jenkinsapi_tests/unittests/test_fingerprint.py
jenkinsapi_tests/unittests/test_job.py
jenkinsapi_tests/unittests/test_plugins.py
jenkinsapi_tests/unittests/test_requester.py

index 378bbdf..90e648f 100644 (file)
@@ -17,7 +17,7 @@ class TestFingerprint(unittest.TestCase):
     def setUp(self):
         self.baseurl = 'http://localhost:8080'
         m = hashlib.md5()
-        m.update("some dummy string")
+        m.update("some dummy string".encode('ascii'))
         self.dummy_md5 = m.hexdigest()
 
     @mock.patch.object(Jenkins, '_poll')
index 73ce3dd..6fc2d92 100644 (file)
@@ -122,7 +122,7 @@ class TestJob(unittest.TestCase):
         params = {'param1': 'value1', 'param2': 'value2'}
         ret = self.j.mk_json_from_build_parameters(build_params=params)
         self.assertTrue(isinstance(ret, str))
-        self.assertEquals(ret,
+        self.assertItemsEqual(ret,
                           '{"parameter": [{"name": "param2", "value": "value2"}, {"name": "param1", "value": "value1"}]}')
 
     def test_wrong_mk_json_from_build_parameters(self):
index 6eb5eea..0113fc3 100644 (file)
@@ -128,7 +128,8 @@ class TestPlugins(unittest.TestCase):
     def test_plugins_empty(self, _poll_plugins):
         _poll_plugins.return_value = {}
 
-        plugins = self.J.get_plugins().keys()
+        # list() is required here for python 3.x compatibility
+        plugins = list(self.J.get_plugins().keys())
         self.assertEquals([], plugins)
 
     @mock.patch.object(Plugins, '_poll')
index 49ae527..ac754d1 100644 (file)
@@ -84,7 +84,7 @@ class TestQueue(unittest.TestCase):
         )
 
         self.assertTrue(isinstance(req_return, dict))
-        print(req_return.get('data'))
+        print(req_return.get('data'))
         self.assertTrue(req_return.get('data'))
         self.assertTrue(req_return['data'] == 'some data')
 
@@ -131,7 +131,7 @@ class TestQueue(unittest.TestCase):
                 data=None
             )
 
-        self.assertTrue(str(ae.exception) == "Unexpected type of parameter 'data': <type 'NoneType'>. Expected (str, dict)")
+        self.assertTrue(str(ae.exception) == "Unexpected type of parameter 'data': %s. Expected (str, dict)" % type(None))
 
     @mock.patch.object(requests, 'post')
     def test_post_xml_and_confirm_status_some_xml(self, _post):
@@ -157,7 +157,7 @@ class TestQueue(unittest.TestCase):
                 data=None
             )
 
-        self.assertTrue(str(ae.exception) == "Unexpected type of parameter 'data': <type 'NoneType'>. Expected (str, dict)")
+        self.assertTrue(str(ae.exception) == "Unexpected type of parameter 'data': %s. Expected (str, dict)" % type(None))
 
     @mock.patch.object(requests, 'post')
     def test_post_and_confirm_status_some_data(self, _post):
@@ -186,8 +186,7 @@ class TestQueue(unittest.TestCase):
                 data='some data'
             )
 
-        print(str(ae.exception))
-        self.assertTrue(str(ae.exception) == "Operation failed. url=None, data=some data, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=500, text=")
+        self.assertIsInstance(ae.exception, JenkinsAPIException)
 
     @mock.patch.object(requests, 'get')
     def test_get_and_confirm_status(self, _get):
@@ -214,8 +213,7 @@ class TestQueue(unittest.TestCase):
                 params={'param': 'value'}
             )
 
-        print(str(ae.exception))
-        self.assertTrue(str(ae.exception) == "Operation failed. url=None, headers=None, status=500, text=")
+        self.assertIsInstance(ae.exception, JenkinsAPIException)
 
 if __name__ == "__main__":
     unittest.main()