From 0fcd92372bfe5054f0cb511b7090dbdf0d7cc3d8 Mon Sep 17 00:00:00 2001 From: Aleksey Maksimov Date: Fri, 18 Apr 2014 17:23:07 +0800 Subject: [PATCH] Fixed most of the unit tests to work on all python versions --- jenkinsapi_tests/unittests/test_fingerprint.py | 2 +- jenkinsapi_tests/unittests/test_job.py | 2 +- jenkinsapi_tests/unittests/test_plugins.py | 3 ++- jenkinsapi_tests/unittests/test_requester.py | 12 +++++------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/jenkinsapi_tests/unittests/test_fingerprint.py b/jenkinsapi_tests/unittests/test_fingerprint.py index 378bbdf..90e648f 100644 --- a/jenkinsapi_tests/unittests/test_fingerprint.py +++ b/jenkinsapi_tests/unittests/test_fingerprint.py @@ -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') diff --git a/jenkinsapi_tests/unittests/test_job.py b/jenkinsapi_tests/unittests/test_job.py index 73ce3dd..6fc2d92 100644 --- a/jenkinsapi_tests/unittests/test_job.py +++ b/jenkinsapi_tests/unittests/test_job.py @@ -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): diff --git a/jenkinsapi_tests/unittests/test_plugins.py b/jenkinsapi_tests/unittests/test_plugins.py index 6eb5eea..0113fc3 100644 --- a/jenkinsapi_tests/unittests/test_plugins.py +++ b/jenkinsapi_tests/unittests/test_plugins.py @@ -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') diff --git a/jenkinsapi_tests/unittests/test_requester.py b/jenkinsapi_tests/unittests/test_requester.py index 49ae527..ac754d1 100644 --- a/jenkinsapi_tests/unittests/test_requester.py +++ b/jenkinsapi_tests/unittests/test_requester.py @@ -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': . 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': . 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() -- 2.7.4