Skip to content

Commit

Permalink
Fix failing test and add test with auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Carles Barrobés committed Oct 4, 2012
1 parent cac9089 commit 4c91975
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion autojenkins/run.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_auth(options):
""" """
Return a tuple of (user, password) or None if no authentication Return a tuple of (user, password) or None if no authentication
""" """
if options.user: if hasattr(options, 'user'):
return (options.user, getattr(options, 'password', None)) return (options.user, getattr(options, 'password', None))
else: else:
return None return None
Expand Down
18 changes: 16 additions & 2 deletions autojenkins/tests/test_run.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@
@patch('autojenkins.run.Jenkins') @patch('autojenkins.run.Jenkins')
def test_delete_jobs(jenkins): def test_delete_jobs(jenkins):
jenkins.return_value = Mock() jenkins.return_value = Mock()
delete_jobs('http://jenkins', ['hello', 'bye']) delete_jobs('http://jenkins', ['hello', 'bye'], None)
jenkins.assert_called_with('http://jenkins') jenkins.assert_called_with('http://jenkins', auth=None)
assert_equals(2, jenkins.return_value.delete.call_count) assert_equals(2, jenkins.return_value.delete.call_count)
assert_equals( assert_equals(
[(('hello',), {}), (('bye',), {})], [(('hello',), {}), (('bye',), {})],
jenkins.return_value.delete.call_args_list) jenkins.return_value.delete.call_args_list)


@patch('autojenkins.run.Jenkins')
def test_delete_jobs_authenticated(jenkins):
jenkins.return_value = Mock()
options = Mock()
options.user = 'carles'
options.password = 'secret'
delete_jobs('http://jenkins', ['hello'], options)
jenkins.assert_called_with('http://jenkins', auth=('carles', 'secret'))
assert_equals(1, jenkins.return_value.delete.call_count)
assert_equals(
[(('hello',), {})],
jenkins.return_value.delete.call_args_list)

0 comments on commit 4c91975

Please sign in to comment.