def test_review_approved_wip_not_realtime(self, MockPullReqState): state = MockPullReqState() state.title = 'WIP work in progress' self.assertFalse( action.review_approved(state, False, 'user', 'user', 'user', '', [])) assert not state.add_comment.called, 'state.add_comment was called and should never be.'
def test_review_approved_different_usernames_blank_sha_blocked_by_closed_tree( self, MockPullReqState): state = MockPullReqState() state.blocked_by_closed_tree.return_value = 1 state.head_sha = 'sdf456' state.title = "My pull request" state.repo_label = 'label' state.status = 'pending' states = {} states[state.repo_label] = {'label': state} self.assertTrue( action.review_approved(state, True, 'user1', 'user1', 'user2', '', states)) state.add_comment.assert_has_calls([ call( ":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." ), call( ':pushpin: Commit sdf456 has been approved by `user1`\n\n<!-- @user2 r=user1 sdf456 -->' ), call( ':evergreen_tree: The tree is currently closed for pull requests below priority 1, this pull request will be tested once the tree is reopened' ) ]) state.change_labels.assert_called_once_with(LabelEvent.APPROVED)
def test_review_approved_wip_todo_realtime(self, MockPullReqState): state = MockPullReqState() state.title = 'WIP work in progress' self.assertFalse( action.review_approved(state, True, 'user', 'user', 'user', '', [])) state.add_comment.assert_called_once_with( ':clipboard: Looks like this PR is still in progress, ignoring approval' )
def test_review_approved_equal_usernames(self, MockPullReqState): state = MockPullReqState() state.head_sha = 'abcd123' state.title = "My pull request" self.assertTrue( action.review_approved(state, True, 'user', 'user', 'user', 'abcd123', [])) self.assertEqual(state.approved_by, ['user']) self.assertFalse(state.try_) state.set_status.assert_called_once_with('') state.save.assert_called_once_with()
def test_review_approved_same_usernames_sha_different_head_sha( self, MockPullReqState): state = MockPullReqState() state.head_sha = 'sdf456' state.title = "My pull request" state.repo_label = 'label' state.status = 'pending' states = {} states[state.repo_label] = {'label': state} self.assertTrue( action.review_approved(state, True, 'user', 'user', 'user', 'abcd123', states))
def test_review_approved_different_usernames_sha_equals_head_sha( self, MockPullReqState): state = MockPullReqState() state.head_sha = 'abcd123' state.title = "My pull request" state.repo_label = 'label' state.status = 'pending' states = {} states[state.repo_label] = {'label': state} self.assertTrue( action.review_approved(state, True, 'user1', 'user1', 'user2', 'abcd123', states)) self.assertEqual(state.approved_by, ['user1']) self.assertFalse(state.try_) state.set_status.assert_called_once_with('') 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." )
def test_review_approved_different_usernames_sha_different_head_sha( self, MockPullReqState): state = MockPullReqState() state.head_sha = 'sdf456' state.title = "My pull request" state.repo_label = 'label' state.status = 'pending' state.num = 1 states = {} states[state.repo_label] = {'label': state} self.assertTrue( action.review_approved(state, True, 'user1', 'user1', 'user2', 'abcd123', states)) state.add_comment.assert_has_calls([ call( ":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." ), call( ':scream_cat: `abcd123` is not a valid commit SHA. Please try again with `sdf456`.' ) ])
def test_review_approved_approver_me(self, MockPullReqState): state = MockPullReqState() self.assertFalse( action.review_approved(state, True, 'me', 'user', 'user', '', []))