Skip to content

Commit

Permalink
Use the argument name _force instead of update.
Browse files Browse the repository at this point in the history
In create_copy(), use the argument name _force, instead of update, to
avoid collision with other template variable names. Also added a unit
test case to cover this scenario.
  • Loading branch information
bravegnu committed Oct 12, 2014
1 parent 53c2f23 commit 56671f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions autojenkins/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ def create(self, jobname, config_file, **context):
headers={'Content-Type': 'application/xml'}
)

def create_copy(self, jobname, template_job, enable=True, update=False, **context):
def create_copy(self, jobname, template_job, enable=True, _force=False, **context):
"""
Create a job from a template job.
"""
if not self.job_exists(template_job):
raise JobInexistent("Template job '%s' doesn't exists" % template_job)

if not update and self.job_exists(jobname):
if not _force and self.job_exists(jobname):
raise JobExists("Another job with the name '%s'already exists"
% jobname)

Expand All @@ -273,7 +273,7 @@ def create_copy(self, jobname, template_job, enable=True, update=False, **contex
config = config.replace('<disabled>true</disabled>',
'<disabled>false</disabled>')

if update:
if _force:
return self.set_config_xml(jobname, config)
else:
return self._build_post(NEWJOB,
Expand Down
15 changes: 15 additions & 0 deletions autojenkins/tests/test_unit_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ def test_create_copy(self, job_exists, requests):
proxies={},
verify=True)

@patch('autojenkins.jobs.Jenkins.job_exists')
def test_create_copy_forced(self, job_exists, requests):
job_exists.side_effect = side_effect_job_exists
requests.get.return_value = mock_response('create_copy.txt')
requests.post.return_value = mock_response()
self.jenkins.create_copy('name', 'template', _force=True, value='2')
CFG = "<value>2</value><disabled>false</disabled>"
requests.post.assert_called_once_with(
'http://jenkins/job/name/config.xml',
headers={'Content-Type': 'application/xml'},
data=CFG,
auth=None,
proxies={},
verify=True)

def test_transfer(self, requests):
requests.get.return_value = mock_response('transfer.txt')
requests.post.return_value = mock_response()
Expand Down

0 comments on commit 56671f9

Please sign in to comment.