Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Replace assert_called_once by assert_called_once_with
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrs committed Mar 14, 2018
1 parent 3fe9223 commit cd5b1b5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
16 changes: 12 additions & 4 deletions homu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,11 @@ def parse_commands(body, username, repo_cfg, state, my_username, db, states,
elif word == 'delegate+':
if not _reviewer_auth_verified:
continue
delegate_positive(state, realtime)
delegate_positive(state,
state.get_repo().
pull_request(state.num).
user.login,
realtime)

elif word == 'retry' and realtime:
if not _try_auth_verified():
Expand Down Expand Up @@ -589,10 +593,14 @@ def parse_commands(body, username, repo_cfg, state, my_username, db, states,
return state_changed


def get_portal_turret_dialog():
return random.choice(PORTAL_TURRET_DIALOG)


def still_here(state):
state.add_comment(
":cake: {}\n\n![]({})".format(
random.choice(PORTAL_TURRET_DIALOG), PORTAL_TURRET_IMAGE)
get_portal_turret_dialog(), PORTAL_TURRET_IMAGE)
)


Expand Down Expand Up @@ -673,8 +681,8 @@ def delegate_negative(state):
state.save()


def delegate_positive(state, realtime):
state.delegate = state.get_repo().pull_request(state.num).user.login # noqa
def delegate_positive(state, delegate, realtime):
state.delegate = delegate
state.save()

if realtime:
Expand Down
49 changes: 29 additions & 20 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def test_get_words_correct_username(self):
self.assertEqual(get_words("@user I'm a message", 'user'), ['@user', "I'm", 'a', 'message'])

@patch('homu.main.PullReqState')
def test_still_here(self, MockPullReqState):
@patch('homu.main.get_portal_turret_dialog', return_value='message')
def test_still_here(self, mock_message, MockPullReqState):
state = MockPullReqState()
still_here(state)
state.add_comment.assert_called_once()
state.add_comment.assert_called_once_with(':cake: message\n\n![](https://cloud.githubusercontent.com/assets/1617736/22222924/c07b2a1c-e16d-11e6-91b3-ac659550585c.png)')

@patch('homu.main.PullReqState')
def test_hello_or_ping(self, MockPullReqState):
Expand All @@ -34,36 +35,36 @@ def test_treeclosed_negative(self, MockPullReqState):
state = MockPullReqState()
treeclosed_negative(state)
state.change_treeclosed.assert_called_once_with(-1)
state.save.assert_called_once()
state.save.assert_called_once_with()

@patch('homu.main.PullReqState')
def test_set_treeclosed(self, MockPullReqState):
state = MockPullReqState()
set_treeclosed(state, 'treeclosed=123')
state.change_treeclosed.assert_called_once_with(123)
state.save.assert_called_once()
state.save.assert_called_once_with()

@patch('homu.main.PullReqState')
def test_rollup_positive(self, MockPullReqState):
state = MockPullReqState()
rollup(state, 'rollup')
self.assertTrue(state.rollup)
state.save.assert_called_once()
state.save.assert_called_once_with()

@patch('homu.main.PullReqState')
def test_rollup_negative(self, MockPullReqState):
state = MockPullReqState()
rollup(state, 'rollup-')
self.assertFalse(state.rollup)
state.save.assert_called_once()
state.save.assert_called_once_with()

@patch('homu.main.PullReqState')
def test_try_positive(self, MockPullReqState):
state = MockPullReqState()
_try(state, 'try')
self.assertTrue(state.try_)
state.init_build_res.assert_called_once_with([])
state.save.assert_called_once()
state.save.assert_called_once_with()
state.change_labels.assert_called_once_with(LabelEvent.TRY)

@patch('homu.main.PullReqState')
Expand All @@ -72,7 +73,7 @@ def test_try_negative(self, MockPullReqState):
_try(state, 'try-')
self.assertFalse(state.try_)
state.init_build_res.assert_called_once_with([])
state.save.assert_called_once()
state.save.assert_called_once_with()
assert not state.change_labels.called, 'change_labels was called and should never be.'

@patch('homu.main.PullReqState')
Expand All @@ -81,7 +82,7 @@ def test_clean(self, MockPullReqState):
clean(state)
self.assertEqual(state.merge_sha, '')
state.init_build_res.assert_called_once_with([])
state.save.assert_called_once()
state.save.assert_called_once_with()

@patch('homu.main.PullReqState')
def test_retry_try(self, MockPullReqState):
Expand All @@ -105,22 +106,30 @@ def test_delegate_negative(self, MockPullReqState):
state.delegate = 'delegate'
delegate_negative(state)
self.assertEqual(state.delegate, '')
state.save.assert_called_once()
state.save.assert_called_once_with()

@patch('homu.main.PullReqState')
def test_delegate_positive(self, MockPullReqState):
def test_delegate_positive_realtime(self, MockPullReqState):
state = MockPullReqState()
delegate_positive(state, True)
state.get_repo.assert_called_once()
state.add_comment.assert_called_once()
state.save.assert_called_once()
delegate_positive(state, 'delegate', True)
self.assertEqual(state.delegate, 'delegate')
state.add_comment.assert_called_once_with(':v: @delegate can now approve this pull request')
state.save.assert_called_once_with()

@patch('homu.main.PullReqState')
def test_delegate_positive_not_realtime(self, MockPullReqState):
state = MockPullReqState()
delegate_positive(state, 'delegate', False)
self.assertEqual(state.delegate, 'delegate')
state.save.assert_called_once_with()
assert not state.add_comment.called, 'state.save was called and should never be.'

@patch('homu.main.PullReqState')
def test_delegate_to(self, MockPullReqState):
state = MockPullReqState()
delegate_to(state, True, 'user')
self.assertEqual(state.delegate, 'user')
state.save.assert_called_once()
state.save.assert_called_once_with()
state.add_comment.assert_called_once_with(
':v: @user can now approve this pull request'
)
Expand All @@ -130,7 +139,7 @@ def test_set_priority_not_priority_less_than_max_priority(self, MockPullReqState
state = MockPullReqState()
set_priority(state, True, '1', {'max_priority': 3})
self.assertEqual(state.priority, 1)
state.save.assert_called_once()
state.save.assert_called_once_with()

@patch('homu.main.PullReqState')
def test_set_priority_not_priority_more_than_max_priority(self, MockPullReqState):
Expand Down Expand Up @@ -169,7 +178,7 @@ def test_review_approved_equal_usernames(self, MockPullReqState):
self.assertEqual(state.approved_by, 'user')
self.assertFalse(state.try_)
state.set_status.assert_called_once_with('')
state.save.assert_called_once()
state.save.assert_called_once_with()

@patch('homu.main.PullReqState')
def test_review_approved_different_usernames_sha_equals_head_sha(self, MockPullReqState):
Expand All @@ -184,7 +193,7 @@ def test_review_approved_different_usernames_sha_equals_head_sha(self, MockPullR
self.assertEqual(state.approved_by, 'user1')
self.assertFalse(state.try_)
state.set_status.assert_called_once_with('')
state.save.assert_called_once()
state.save.assert_called_once_with()
state.add_comment.assert_called_once_with(":bulb: This pull request was already approved, no need to approve it again.\n\n- This pull request is currently being tested. If there's no response from the continuous integration service, you may use `retry` to trigger a build again.")

@patch('homu.main.PullReqState')
Expand Down Expand Up @@ -247,7 +256,7 @@ def test_review_rejected(self, MockPullReqState):
state = MockPullReqState()
review_rejected(state, True)
self.assertEqual(state.approved_by, '')
state.save.assert_called_once()
state.save.assert_called_once_with()
state.change_labels.assert_called_once_with(LabelEvent.REJECTED)

def test_sha_or_blank_return_sha(self):
Expand Down

0 comments on commit cd5b1b5

Please sign in to comment.