From b0fe55cd593faa7d9207b8684ecd1dc2852f82b3 Mon Sep 17 00:00:00 2001 From: Hugh Brown Date: Thu, 10 Oct 2013 21:56:35 -0400 Subject: [PATCH] pep8 fixes in test and utils directories --- jenkinsapi/custom_exceptions.py | 1 + jenkinsapi/mutable_jenkins_thing.py | 1 + jenkinsapi/plugin.py | 1 + jenkinsapi/result.py | 1 + jenkinsapi_tests/systests/__init__.py | 8 ++-- jenkinsapi_tests/systests/test_invocation.py | 2 +- jenkinsapi_tests/systests/test_jenkins.py | 3 +- .../systests/test_jenkins_artifacts.py | 4 +- jenkinsapi_tests/systests/test_jenkins_matrix.py | 2 +- jenkinsapi_tests/systests/test_nodes.py | 12 +++--- jenkinsapi_tests/systests/test_queue.py | 4 +- jenkinsapi_tests/systests/test_scm.py | 1 - jenkinsapi_tests/test_utils/random_strings.py | 3 +- jenkinsapi_tests/unittests/test_build_scm_git.py | 4 +- jenkinsapi_tests/unittests/test_jenkins.py | 18 ++++----- jenkinsapi_tests/unittests/test_jenkinsbase.py | 8 ++-- jenkinsapi_tests/unittests/test_job.py | 4 +- .../unittests/test_job_get_all_builds.py | 5 +-- jenkinsapi_tests/unittests/test_nodes.py | 6 +-- jenkinsapi_tests/unittests/test_plugins.py | 42 ++++++++++---------- jenkinsapi_tests/unittests/test_queue.py | 12 +++--- jenkinsapi_tests/unittests/test_requester.py | 46 +++++++++++----------- jenkinsapi_tests/unittests/test_result_set.py | 1 + jenkinsapi_tests/unittests/test_view.py | 2 +- jenkinsapi_tests/unittests/test_views.py | 8 ++-- jenkinsapi_utils/jenkins_launcher.py | 8 ++-- jenkinsapi_utils/simple_post_logger.py | 5 ++- 27 files changed, 109 insertions(+), 103 deletions(-) diff --git a/jenkinsapi/custom_exceptions.py b/jenkinsapi/custom_exceptions.py index bb88d56..2dde269 100644 --- a/jenkinsapi/custom_exceptions.py +++ b/jenkinsapi/custom_exceptions.py @@ -9,6 +9,7 @@ class JenkinsAPIException(Exception): """ pass + class NotFound(JenkinsAPIException): """ Resource cannot be found diff --git a/jenkinsapi/mutable_jenkins_thing.py b/jenkinsapi/mutable_jenkins_thing.py index 2a8a3f6..ace4880 100644 --- a/jenkinsapi/mutable_jenkins_thing.py +++ b/jenkinsapi/mutable_jenkins_thing.py @@ -2,6 +2,7 @@ Module for MutableJenkinsThing """ + class MutableJenkinsThing(object): """ A mixin for certain mutable objects which can be renamed and deleted. diff --git a/jenkinsapi/plugin.py b/jenkinsapi/plugin.py index 44d542b..72a5f04 100644 --- a/jenkinsapi/plugin.py +++ b/jenkinsapi/plugin.py @@ -2,6 +2,7 @@ Module for jenkinsapi Plugin """ + class Plugin(object): """ Plugin class diff --git a/jenkinsapi/result.py b/jenkinsapi/result.py index f93e738..d53f3bc 100644 --- a/jenkinsapi/result.py +++ b/jenkinsapi/result.py @@ -2,6 +2,7 @@ Module for jenkinsapi Result """ + class Result(object): """ Result class diff --git a/jenkinsapi_tests/systests/__init__.py b/jenkinsapi_tests/systests/__init__.py index 81b87ed..ce742b5 100644 --- a/jenkinsapi_tests/systests/__init__.py +++ b/jenkinsapi_tests/systests/__init__.py @@ -1,18 +1,20 @@ import os from jenkinsapi_utils.jenkins_launcher import JenkinsLancher -state={} +state = {} # Extra plugins required by the systests PLUGIN_DEPENDENCIES = ["http://updates.jenkins-ci.org/latest/git.hpi", "http://updates.jenkins-ci.org/latest/git-client.hpi", "https://updates.jenkins-ci.org/latest/nested-view.hpi"] - + + def setUpPackage(): systests_dir, _ = os.path.split(__file__) - war_path = os.path.join(systests_dir, 'jenkins.war' ) + war_path = os.path.join(systests_dir, 'jenkins.war') state['launcher'] = JenkinsLancher(war_path, PLUGIN_DEPENDENCIES) state['launcher'].start() + def tearDownPackage(): state['launcher'].stop() diff --git a/jenkinsapi_tests/systests/test_invocation.py b/jenkinsapi_tests/systests/test_invocation.py index b4b12cd..d80b597 100644 --- a/jenkinsapi_tests/systests/test_invocation.py +++ b/jenkinsapi_tests/systests/test_invocation.py @@ -66,7 +66,7 @@ class TestInvocation(BaseSystemTest): ii = job.invoke() ii.block(until='completed') build_number = ii.get_build_number() - self.assertEquals(build_number, invocation+1) + self.assertEquals(build_number, invocation +1) if __name__ == '__main__': diff --git a/jenkinsapi_tests/systests/test_jenkins.py b/jenkinsapi_tests/systests/test_jenkins.py index 2f04621..7933b70 100644 --- a/jenkinsapi_tests/systests/test_jenkins.py +++ b/jenkinsapi_tests/systests/test_jenkins.py @@ -9,7 +9,6 @@ from jenkinsapi_tests.systests.job_configs import EMPTY_JOB from jenkinsapi_tests.test_utils.random_strings import random_string - class JobTests(BaseSystemTest): def test_create_job(self): @@ -23,7 +22,7 @@ class JobTests(BaseSystemTest): self.assertJobIsPresent(job_name) j = self.jenkins[job_name] - j.invoke(block=True) # run this at least once + j.invoke(block=True) # run this at least once j.disable() self.assertEquals(j.is_enabled(), False, 'A disabled job is reporting incorrectly') diff --git a/jenkinsapi_tests/systests/test_jenkins_artifacts.py b/jenkinsapi_tests/systests/test_jenkins_artifacts.py index 1cf155e..2e5e680 100644 --- a/jenkinsapi_tests/systests/test_jenkins_artifacts.py +++ b/jenkinsapi_tests/systests/test_jenkins_artifacts.py @@ -45,9 +45,9 @@ class TestPingerJob(BaseSystemTest): # Verify that we can hande binary artifacts binary_artifact.save_to_dir(tempDir) readBackText = gzip.open(os.path.join( - tempDir, + tempDir, binary_artifact.filename, - ), 'rb' ).read().strip() + ), 'rb').read().strip() self.assertTrue(re.match(r'^PING \S+ \(127.0.0.1\)', readBackText)) self.assertTrue(readBackText.endswith('ms')) finally: diff --git a/jenkinsapi_tests/systests/test_jenkins_matrix.py b/jenkinsapi_tests/systests/test_jenkins_matrix.py index 3219909..0239c9a 100644 --- a/jenkinsapi_tests/systests/test_jenkins_matrix.py +++ b/jenkinsapi_tests/systests/test_jenkins_matrix.py @@ -33,7 +33,7 @@ class TestPingerJob(BaseSystemTest): m = re.search(u'\xbb (.*) #\\d+$', r.name) self.assertIsNotNone(m) s.add(m.group(1)) - self.assertEqual(s, {'one','two','three'}) + self.assertEqual(s, {'one', 'two', 'three'}) if __name__ == '__main__': unittest.main() diff --git a/jenkinsapi_tests/systests/test_nodes.py b/jenkinsapi_tests/systests/test_nodes.py index 26e5edb..b125589 100644 --- a/jenkinsapi_tests/systests/test_nodes.py +++ b/jenkinsapi_tests/systests/test_nodes.py @@ -27,18 +27,18 @@ class TestNodes(BaseSystemTest): Can we flip the online / offline state of the master node. """ # Master node name should be case insensitive - #mn0 = self.jenkins.get_node('MaStEr') + # mn0 = self.jenkins.get_node('MaStEr') mn = self.jenkins.get_node('master') - #self.assertEquals(mn, mn0) + # self.assertEquals(mn, mn0) - mn.set_online() # It should already be online, hence no-op + mn.set_online() # It should already be online, hence no-op self.assertTrue(mn.is_online()) - mn.set_offline() # We switch that suckah off - mn.set_offline() # This should be a no-op + mn.set_offline() # We switch that suckah off + mn.set_offline() # This should be a no-op self.assertFalse(mn.is_online()) - mn.set_online() # Switch it back on + mn.set_online() # Switch it back on self.assertTrue(mn.is_online()) diff --git a/jenkinsapi_tests/systests/test_queue.py b/jenkinsapi_tests/systests/test_queue.py index 5e92664..e4c408e 100644 --- a/jenkinsapi_tests/systests/test_queue.py +++ b/jenkinsapi_tests/systests/test_queue.py @@ -11,11 +11,12 @@ from jenkinsapi_tests.systests.job_configs import LONG_RUNNING_JOB log = logging.getLogger(__name__) + class TestQueue(BaseSystemTest): """ All kinds of testing on Jenkins Queues """ - #TODO: Test timeout behavior + # TODO: Test timeout behavior def test_get_queue(self): qq = self.jenkins.get_queue() @@ -43,7 +44,6 @@ class TestQueue(BaseSystemTest): self.assertEquals(len(queue), 0) - def test_start_and_stop_long_running_job(self): job_name = random_string() j = self.jenkins.create_job(job_name, LONG_RUNNING_JOB) diff --git a/jenkinsapi_tests/systests/test_scm.py b/jenkinsapi_tests/systests/test_scm.py index b12ef1f..dd79836 100644 --- a/jenkinsapi_tests/systests/test_scm.py +++ b/jenkinsapi_tests/systests/test_scm.py @@ -21,4 +21,3 @@ # if __name__ == '__main__': # unittest.main() - diff --git a/jenkinsapi_tests/test_utils/random_strings.py b/jenkinsapi_tests/test_utils/random_strings.py index 703e6fd..ffcbf57 100644 --- a/jenkinsapi_tests/test_utils/random_strings.py +++ b/jenkinsapi_tests/test_utils/random_strings.py @@ -1,8 +1,9 @@ import random import string + def random_string(length=10): - return ''.join( random.choice(string.ascii_lowercase) for i in range(length) ) + return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) if __name__ == '__main__': print random_string() diff --git a/jenkinsapi_tests/unittests/test_build_scm_git.py b/jenkinsapi_tests/unittests/test_build_scm_git.py index b7f8db6..b7e108d 100644 --- a/jenkinsapi_tests/unittests/test_build_scm_git.py +++ b/jenkinsapi_tests/unittests/test_build_scm_git.py @@ -2,6 +2,7 @@ import mock import unittest from jenkinsapi.build import Build + class test_build(unittest.TestCase): DATA = {'actions': [{'causes': [{'shortDescription': 'Started by an SCM change'}]}, @@ -54,7 +55,6 @@ class test_build(unittest.TestCase): 'timestamp': 1372553675652, 'url': 'http://localhost:8080/job/git_yssrtigfds/3/'} - @mock.patch.object(Build, '_poll') def setUp(self, _poll): _poll.return_value = self.DATA @@ -71,4 +71,4 @@ class test_build(unittest.TestCase): self.assertEquals(self.b.get_revision(), '7def9ed6e92580f37d00e4980c36c4d36e68f702') if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/jenkinsapi_tests/unittests/test_jenkins.py b/jenkinsapi_tests/unittests/test_jenkins.py index a8719bb..3282182 100644 --- a/jenkinsapi_tests/unittests/test_jenkins.py +++ b/jenkinsapi_tests/unittests/test_jenkins.py @@ -208,8 +208,8 @@ class TestJenkins(unittest.TestCase): username='foouser', password='foopassword') job = J.create_job('job_one', None) self.assertTrue(isinstance(job, Job)) - self.assertTrue(job.baseurl=='http://localhost:8080/job_one') - self.assertTrue(job.name=='job_one') + self.assertTrue(job.baseurl == 'http://localhost:8080/job_one') + self.assertTrue(job.name == 'job_one') # Here we're going to test function, which is going to modify # Jenkins internal data. It calls for data once to check @@ -257,8 +257,8 @@ class TestJenkins(unittest.TestCase): job = J.create_job('job_new', None) self.assertTrue(isinstance(job, Job)) - self.assertTrue(job.baseurl=='http://localhost:8080/job_new') - self.assertTrue(job.name=='job_new') + self.assertTrue(job.baseurl == 'http://localhost:8080/job_new') + self.assertTrue(job.name == 'job_new') @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -361,12 +361,12 @@ class TestJenkinsURLs(unittest.TestCase): def test_has_plugin(self, _p_poll, _poll): _poll.return_value = {} _p_poll.return_value = {'plugins': [ - {'deleted': False, 'hasUpdate': True, 'downgradable': False, - 'dependencies': [{}, {}, {}, {}], - 'longName': 'Jenkins Subversion Plug-in', 'active': True, - 'shortName': 'subversion', 'backupVersion': None, + {'deleted': False, 'hasUpdate': True, 'downgradable': False, + 'dependencies': [{}, {}, {}, {}], + 'longName': 'Jenkins Subversion Plug-in', 'active': True, + 'shortName': 'subversion', 'backupVersion': None, 'url': 'http://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin', - 'enabled': True, 'pinned': False, 'version': '1.45', + 'enabled': True, 'pinned': False, 'version': '1.45', 'supportsDynamicLoad': 'MAYBE', 'bundled': True}]} J = Jenkins('http://localhost:8080/', diff --git a/jenkinsapi_tests/unittests/test_jenkinsbase.py b/jenkinsapi_tests/unittests/test_jenkinsbase.py index 323e2c6..268d457 100644 --- a/jenkinsapi_tests/unittests/test_jenkinsbase.py +++ b/jenkinsapi_tests/unittests/test_jenkinsbase.py @@ -1,5 +1,5 @@ class TestJenkinsBaseMixin(object): - """ - Tests which apply to all or most Jenkins objects - """ - pass \ No newline at end of file + """ + Tests which apply to all or most Jenkins objects + """ + pass diff --git a/jenkinsapi_tests/unittests/test_job.py b/jenkinsapi_tests/unittests/test_job.py index e01d1c2..da8cec0 100644 --- a/jenkinsapi_tests/unittests/test_job.py +++ b/jenkinsapi_tests/unittests/test_job.py @@ -24,7 +24,7 @@ class TestJob(unittest.TestCase): "iconUrl": "health-80plus.png", "score": 100}], "inQueue": False, "keepDependencies": False, - "lastBuild": {"number": 4, "url": "http://halob:8080/job/foo/4/"}, # build running + "lastBuild": {"number": 4, "url": "http://halob:8080/job/foo/4/"}, # build running "lastCompletedBuild": {"number": 3, "url": "http://halob:8080/job/foo/3/"}, "lastFailedBuild": None, "lastStableBuild": {"number": 3, "url": "http://halob:8080/job/foo/3/"}, @@ -39,7 +39,7 @@ class TestJob(unittest.TestCase): "scm": {}, "upstreamProjects": []} - URL_DATA = {'http://halob:8080/job/foo/%s' % config.JENKINS_API:JOB_DATA} + URL_DATA = {'http://halob:8080/job/foo/%s' % config.JENKINS_API: JOB_DATA} def fakeGetData(self, url, *args): try: diff --git a/jenkinsapi_tests/unittests/test_job_get_all_builds.py b/jenkinsapi_tests/unittests/test_job_get_all_builds.py index 27b6a55..68c2bab 100644 --- a/jenkinsapi_tests/unittests/test_job_get_all_builds.py +++ b/jenkinsapi_tests/unittests/test_job_get_all_builds.py @@ -24,7 +24,7 @@ class TestJobGetAllBuilds(unittest.TestCase): "iconUrl": "health-80plus.png", "score": 100}], "inQueue": False, "keepDependencies": False, - "lastBuild": {"number": 4, "url": "http://halob:8080/job/foo/4/"}, # build running + "lastBuild": {"number": 4, "url": "http://halob:8080/job/foo/4/"}, # build running "lastCompletedBuild": {"number": 3, "url": "http://halob:8080/job/foo/3/"}, "lastFailedBuild": None, "lastStableBuild": {"number": 3, "url": "http://halob:8080/job/foo/3/"}, @@ -92,7 +92,7 @@ class TestJobGetAllBuilds(unittest.TestCase): "iconUrl": "health-80plus.png", "score": 100}], "inQueue": False, "keepDependencies": False, - "lastBuild": {"number": 4, "url": "http://halob:8080/job/fullfoo/4/"}, # build running + "lastBuild": {"number": 4, "url": "http://halob:8080/job/fullfoo/4/"}, # build running "lastCompletedBuild": {"number": 3, "url": "http://halob:8080/job/fullfoo/3/"}, "lastFailedBuild": None, "lastStableBuild": {"number": 3, "url": "http://halob:8080/job/fullfoo/3/"}, @@ -122,7 +122,6 @@ class TestJobGetAllBuilds(unittest.TestCase): (JOB3_API_URL, str({'tree': 'allBuilds[number,url]'})): JOB3_ALL_BUILDS_DATA, } - def fakeGetData(self, url, params=None): TestJobGetAllBuilds.__get_data_call_count += 1 if params is None: diff --git a/jenkinsapi_tests/unittests/test_nodes.py b/jenkinsapi_tests/unittests/test_nodes.py index a892aad..9e4eae2 100644 --- a/jenkinsapi_tests/unittests/test_nodes.py +++ b/jenkinsapi_tests/unittests/test_nodes.py @@ -26,7 +26,6 @@ class TestNode(unittest.TestCase): 'views': [{'name': 'All', 'url': 'http://halob:8080/'}, {'name': 'FodFanFo', 'url': 'http://halob:8080/view/FodFanFo/'}]} - DATA1 = {'busyExecutors': 0, 'computer': [{'actions': [], 'displayName': 'master', @@ -127,7 +126,7 @@ class TestNode(unittest.TestCase): 'oneOffExecutors': [], 'temporarilyOffline': False} - DATA3= { 'actions': [], + DATA3 = {'actions': [], 'displayName': 'halob', 'executors': [{}], 'icon': 'computer-x.png', @@ -148,7 +147,6 @@ class TestNode(unittest.TestCase): 'oneOffExecutors': [], 'temporarilyOffline': False} - @mock.patch.object(Jenkins, '_poll') @mock.patch.object(Nodes, '_poll') def setUp(self, _poll_nodes, _poll_jenkins): @@ -159,7 +157,7 @@ class TestNode(unittest.TestCase): self.J = Jenkins('http://localhost:8080') self.ns = self.J.get_nodes() - #self.ns = Nodes('http://localhost:8080/computer', 'bobnit', self.J) + # self.ns = Nodes('http://localhost:8080/computer', 'bobnit', self.J) def testRepr(self): # Can we produce a repr string for this object diff --git a/jenkinsapi_tests/unittests/test_plugins.py b/jenkinsapi_tests/unittests/test_plugins.py index 8089a6d..3194be0 100644 --- a/jenkinsapi_tests/unittests/test_plugins.py +++ b/jenkinsapi_tests/unittests/test_plugins.py @@ -8,18 +8,18 @@ from jenkinsapi.plugin import Plugin class TestPlugins(unittest.TestCase): DATA = {'plugins': [ - {'deleted': False, 'hasUpdate': True, 'downgradable': False, - 'dependencies': [{}, {}, {}, {}], - 'longName': 'Jenkins Subversion Plug-in', 'active': True, - 'shortName': 'subversion', 'backupVersion': None, + {'deleted': False, 'hasUpdate': True, 'downgradable': False, + 'dependencies': [{}, {}, {}, {}], + 'longName': 'Jenkins Subversion Plug-in', 'active': True, + 'shortName': 'subversion', 'backupVersion': None, 'url': 'http://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin', - 'enabled': True, 'pinned': False, 'version': '1.45', - 'supportsDynamicLoad': 'MAYBE', 'bundled': True}, - {'deleted': False, 'hasUpdate': True, 'downgradable': False, - 'dependencies': [{}, {}], 'longName': 'Maven Integration plugin', - 'active': True, 'shortName': 'maven-plugin', 'backupVersion': None, - 'url': 'http://wiki.jenkins-ci.org/display/JENKINS/Maven+Project+Plugin', - 'enabled': True, 'pinned': False, 'version': '1.521', + 'enabled': True, 'pinned': False, 'version': '1.45', + 'supportsDynamicLoad': 'MAYBE', 'bundled': True}, + {'deleted': False, 'hasUpdate': True, 'downgradable': False, + 'dependencies': [{}, {}], 'longName': 'Maven Integration plugin', + 'active': True, 'shortName': 'maven-plugin', 'backupVersion': None, + 'url': 'http://wiki.jenkins-ci.org/display/JENKINS/Maven+Project+Plugin', + 'enabled': True, 'pinned': False, 'version': '1.521', 'supportsDynamicLoad': 'MAYBE', 'bundled': True} ]} @@ -69,12 +69,12 @@ class TestPlugins(unittest.TestCase): def test_plugins_values(self, _poll_plugins): _poll_plugins.return_value = self.DATA - p = Plugin({'deleted': False, 'hasUpdate': True, 'downgradable': False, - 'dependencies': [{}, {}, {}, {}], - 'longName': 'Jenkins Subversion Plug-in', 'active': True, - 'shortName': 'subversion', 'backupVersion': None, + p = Plugin({'deleted': False, 'hasUpdate': True, 'downgradable': False, + 'dependencies': [{}, {}, {}, {}], + 'longName': 'Jenkins Subversion Plug-in', 'active': True, + 'shortName': 'subversion', 'backupVersion': None, 'url': 'http://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin', - 'enabled': True, 'pinned': False, 'version': '1.45', + 'enabled': True, 'pinned': False, 'version': '1.45', 'supportsDynamicLoad': 'MAYBE', 'bundled': True}) plugins = self.J.get_plugins().values() @@ -99,12 +99,12 @@ class TestPlugins(unittest.TestCase): def test_plugin_get_by_name(self, _poll_plugins): _poll_plugins.return_value = self.DATA - p = Plugin({'deleted': False, 'hasUpdate': True, 'downgradable': False, - 'dependencies': [{}, {}, {}, {}], - 'longName': 'Jenkins Subversion Plug-in', 'active': True, - 'shortName': 'subversion', 'backupVersion': None, + p = Plugin({'deleted': False, 'hasUpdate': True, 'downgradable': False, + 'dependencies': [{}, {}, {}, {}], + 'longName': 'Jenkins Subversion Plug-in', 'active': True, + 'shortName': 'subversion', 'backupVersion': None, 'url': 'http://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin', - 'enabled': True, 'pinned': False, 'version': '1.45', + 'enabled': True, 'pinned': False, 'version': '1.45', 'supportsDynamicLoad': 'MAYBE', 'bundled': True}) plugin = self.J.get_plugins()['subversion'] diff --git a/jenkinsapi_tests/unittests/test_queue.py b/jenkinsapi_tests/unittests/test_queue.py index aa048b3..4a0a465 100644 --- a/jenkinsapi_tests/unittests/test_queue.py +++ b/jenkinsapi_tests/unittests/test_queue.py @@ -8,11 +8,13 @@ from jenkinsapi.queue import Queue, QueueItem from jenkinsapi.jenkinsbase import JenkinsBase from jenkinsapi.job import Job + class FourOhFourError(Exception): """ Missing fake data """ + class TestQueue(unittest.TestCase): @classmethod @@ -25,16 +27,15 @@ class TestQueue(unittest.TestCase): URL_DATA = {} URL_DATA['http://localhost:8080/%s' % config.JENKINS_API] = \ - {'jobs':[ - {'name':'utmebvpxrw', - 'url':'http://localhost/job/utmebvpxrw'} + {'jobs': [ + {'name': 'utmebvpxrw', + 'url': 'http://localhost/job/utmebvpxrw'} ] } URL_DATA['http://localhost/job/utmebvpxrw/%s' % config.JENKINS_API] = \ {} - URL_DATA['http://localhost:8080/queue/%s' % config.JENKINS_API] = \ {'items': [{'actions': [{'causes': [{'shortDescription': 'Started by user anonymous', 'userId': None, @@ -79,7 +80,6 @@ class TestQueue(unittest.TestCase): 'url': 'http://localhost:8080/job/utmebvpxrw/'}, 'why': 'Waiting for next available executor'}]} - @mock.patch.object(JenkinsBase, 'get_data', mockGetData) def setUp(self): self.J = Jenkins('http://localhost:8080') # Jenkins @@ -92,7 +92,7 @@ class TestQueue(unittest.TestCase): self.assertEquals(len(self.q), 3) def test_list_items(self): - self.assertEquals(set(self.q.keys()), set([40,41,42])) + self.assertEquals(set(self.q.keys()), set([40, 41, 42])) def test_getitem(self): item40 = self.q[40] diff --git a/jenkinsapi_tests/unittests/test_requester.py b/jenkinsapi_tests/unittests/test_requester.py index 7f69aba..82bf655 100644 --- a/jenkinsapi_tests/unittests/test_requester.py +++ b/jenkinsapi_tests/unittests/test_requester.py @@ -6,6 +6,7 @@ from collections import defaultdict from jenkinsapi.jenkins import Requester from jenkinsapi.custom_exceptions import JenkinsAPIException + class TestQueue(unittest.TestCase): def test_get_request_dict_auth(self): @@ -15,64 +16,64 @@ class TestQueue(unittest.TestCase): headers=None) self.assertTrue(isinstance(req_return, dict)) self.assertTrue(req_return.get('auth')) - self.assertTrue(req_return['auth']==('foo', 'bar')) + self.assertTrue(req_return['auth'] == ('foo', 'bar')) def test_get_request_dict_wrong_params(self): req = Requester('foo', 'bar') with self.assertRaises(AssertionError) as na: - req_return = req.get_request_dict(url='http://', params='wrong', + req_return = req.get_request_dict(url='http://', params='wrong', data=None, headers=None) self.assertTrue( - na.exception.message=="Params must be a dict, got 'wrong'") + na.exception.message == "Params must be a dict, got 'wrong'") def test_get_request_dict_correct_params(self): req = Requester('foo', 'bar') - req_return = req.get_request_dict(url='http://', + req_return = req.get_request_dict(url='http://', params={'param': 'value'}, data=None, headers=None) self.assertTrue(isinstance(req_return, dict)) self.assertTrue(req_return.get('params')) - self.assertTrue(req_return['params']=={'param': 'value'}) + self.assertTrue(req_return['params'] == {'param': 'value'}) def test_get_request_dict_wrong_headers(self): req = Requester('foo', 'bar') with self.assertRaises(AssertionError) as na: - req_return = req.get_request_dict(url='http://', params={}, + req_return = req.get_request_dict(url='http://', params={}, data=None, headers='wrong') self.assertTrue( - na.exception.message=="headers must be a dict, got 'wrong'") + na.exception.message == "headers must be a dict, got 'wrong'") def test_get_request_dict_correct_headers(self): req = Requester('foo', 'bar') - req_return = req.get_request_dict(url='http://', + req_return = req.get_request_dict(url='http://', params={'param': 'value'}, data=None, headers={'header': 'value'}) self.assertTrue(isinstance(req_return, dict)) self.assertTrue(req_return.get('headers')) - self.assertTrue(req_return['headers']=={'header': 'value'}) + self.assertTrue(req_return['headers'] == {'header': 'value'}) def test_get_request_dict_data_passed(self): req = Requester('foo', 'bar') - req_return = req.get_request_dict(url='http://', + req_return = req.get_request_dict(url='http://', params={'param': 'value'}, data='some data', headers={'header': 'value'}) self.assertTrue(isinstance(req_return, dict)) print req_return.get('data') self.assertTrue(req_return.get('data')) - self.assertTrue(req_return['data']=='some data') + self.assertTrue(req_return['data'] == 'some data') def test_get_request_dict_data_not_passed(self): req = Requester('foo', 'bar') - req_return = req.get_request_dict(url='http://', + req_return = req.get_request_dict(url='http://', params={'param': 'value'}, data=None, headers={'header': 'value'}) @@ -83,18 +84,18 @@ class TestQueue(unittest.TestCase): def test_get_url(self, _get): _get.return_value = 'SUCCESS' req = Requester('foo', 'bar') - self.assertTrue(req.get_url('http://dummy', + self.assertTrue(req.get_url('http://dummy', params={'param': 'value'}, - headers=None)=='SUCCESS') - + headers=None) == 'SUCCESS') + @mock.patch.object(requests, 'post') def test_get_url(self, _post): _post.return_value = 'SUCCESS' req = Requester('foo', 'bar') - self.assertTrue(req.post_url('http://dummy', + self.assertTrue(req.post_url('http://dummy', params={'param': 'value'}, - headers=None)=='SUCCESS') - + headers=None) == 'SUCCESS') + @mock.patch.object(requests, 'post') def test_post_xml_and_confirm_status_empty_xml(self, _post): _post.return_value = 'SUCCESS' @@ -105,7 +106,7 @@ class TestQueue(unittest.TestCase): params={'param': 'value'}, data=None) - self.assertTrue(ae.exception.message=="Unexpected type of parameter 'data': . Expected (str, dict)") + self.assertTrue(ae.exception.message == "Unexpected type of parameter 'data': . Expected (str, dict)") @mock.patch.object(requests, 'post') def test_post_xml_and_confirm_status_some_xml(self, _post): @@ -129,7 +130,7 @@ class TestQueue(unittest.TestCase): params={'param': 'value'}, data=None) - self.assertTrue(ae.exception.message=="Unexpected type of parameter 'data': . Expected (str, dict)") + self.assertTrue(ae.exception.message == "Unexpected type of parameter 'data': . Expected (str, dict)") @mock.patch.object(requests, 'post') def test_post_and_confirm_status_some_data(self, _post): @@ -157,7 +158,7 @@ class TestQueue(unittest.TestCase): data='some data') print ae.exception.message - self.assertTrue(ae.exception.message=="Operation failed. url=None, data=some data, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=500, text=") + self.assertTrue(ae.exception.message == "Operation failed. url=None, data=some data, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=500, text=") @mock.patch.object(requests, 'get') def test_get_and_confirm_status(self, _get): @@ -183,5 +184,4 @@ class TestQueue(unittest.TestCase): params={'param': 'value'}) print ae.exception.message - self.assertTrue(ae.exception.message=="Operation failed. url=None, headers=None, status=500, text=") - + self.assertTrue(ae.exception.message == "Operation failed. url=None, headers=None, status=500, text=") diff --git a/jenkinsapi_tests/unittests/test_result_set.py b/jenkinsapi_tests/unittests/test_result_set.py index 95c63e0..3bcbbbc 100644 --- a/jenkinsapi_tests/unittests/test_result_set.py +++ b/jenkinsapi_tests/unittests/test_result_set.py @@ -4,6 +4,7 @@ import unittest from jenkinsapi.result_set import ResultSet from jenkinsapi.result import Result + class TestResultSet(unittest.TestCase): DATA = {'duration': 0.0, diff --git a/jenkinsapi_tests/unittests/test_view.py b/jenkinsapi_tests/unittests/test_view.py index 24e0f0d..94bacff 100644 --- a/jenkinsapi_tests/unittests/test_view.py +++ b/jenkinsapi_tests/unittests/test_view.py @@ -6,6 +6,7 @@ from jenkinsapi.jenkins import Jenkins from jenkinsapi.view import View from jenkinsapi.job import Job + class TestView(unittest.TestCase): DATA = {'description': 'Important Shizz', @@ -120,7 +121,6 @@ class TestView(unittest.TestCase): result = v.add_job('bar') self.assertTrue(result) - class SelfPatchJenkins(object): def has_job(self, job_name): return False diff --git a/jenkinsapi_tests/unittests/test_views.py b/jenkinsapi_tests/unittests/test_views.py index b6a50c1..e04630b 100644 --- a/jenkinsapi_tests/unittests/test_views.py +++ b/jenkinsapi_tests/unittests/test_views.py @@ -6,7 +6,10 @@ from jenkinsapi.jenkins import Jenkins from jenkinsapi.jenkinsbase import JenkinsBase from jenkinsapi.utils.requester import Requester -class TestDataMissing(Exception): pass + +class TestDataMissing(Exception): + pass + class TestViews(unittest.TestCase): @mock.patch.object(Jenkins, '_poll') @@ -39,7 +42,7 @@ class TestViews(unittest.TestCase): def mockGetData(JJ, url): DATA = {} DATA['http://localhost:8080/%s' % config.JENKINS_API] = \ - {'views':[dict(name='NewView', url='http://xxxxx/yyyy')]} + {'views': [dict(name='NewView', url='http://xxxxx/yyyy')]} DATA['http://xxxxx/yyyy/%s' % config.JENKINS_API] = \ {} @@ -72,4 +75,3 @@ class TestViews(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/jenkinsapi_utils/jenkins_launcher.py b/jenkinsapi_utils/jenkins_launcher.py index 5477bcf..68470de 100644 --- a/jenkinsapi_utils/jenkins_launcher.py +++ b/jenkinsapi_utils/jenkins_launcher.py @@ -71,7 +71,7 @@ class JenkinsLancher(object): def update_config(self): config_dest = os.path.join(self.jenkins_home, 'config.xml') - config_dest_file = open(config_dest,'w') + config_dest_file = open(config_dest, 'w') config_source = pkg_resources.resource_string('jenkinsapi_tests.systests', 'config.xml') config_dest_file.write(config_source.encode('UTF-8')) @@ -83,7 +83,7 @@ class JenkinsLancher(object): plugin_dir = os.path.join(self.jenkins_home, 'plugins') if not os.path.exists(plugin_dir): os.mkdir(plugin_dir) - + log.info("Downloading %s", hpi_url) log.info("Plugins will be installed in '%s'" % plugin_dir) # FIXME: This is kinda ugly but works @@ -91,7 +91,7 @@ class JenkinsLancher(object): plugin_path = os.path.join(plugin_dir, filename) with open(plugin_path, 'wb') as h: request = requests.get(hpi_url) - h.write(request.content) + h.write(request.content) def stop(self): log.info("Shutting down jenkins.") @@ -169,7 +169,7 @@ if __name__ == '__main__': jl = JenkinsLancher( '/home/sal/workspace/jenkinsapi/src/jenkinsapi_tests/systests/jenkins.war' - ) + ) jl.start() log.info("Jenkins was launched...") diff --git a/jenkinsapi_utils/simple_post_logger.py b/jenkinsapi_utils/simple_post_logger.py index 4bb2346..87bf4f0 100644 --- a/jenkinsapi_utils/simple_post_logger.py +++ b/jenkinsapi_utils/simple_post_logger.py @@ -5,6 +5,7 @@ import cgi PORT = 8080 + class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): @@ -16,8 +17,8 @@ class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): form = cgi.FieldStorage( fp=self.rfile, headers=self.headers, - environ={'REQUEST_METHOD':'POST', - 'CONTENT_TYPE':self.headers['Content-Type'], + environ={'REQUEST_METHOD': 'POST', + 'CONTENT_TYPE': self.headers['Content-Type'], }) for item in form.list: logging.error(item) -- 2.7.4