def test_unreleased_prs_result_in_exception(self):
        label_for_current_release_prs = github.Label.Label(
            requester='',
            headers='',
            attributes={
                'name': release_constants.LABEL_FOR_CURRENT_RELEASE_PRS
            },
            completed='')
        label_for_released_prs = github.Label.Label(
            requester='',
            headers='',
            attributes={'name': release_constants.LABEL_FOR_RELEASED_PRS},
            completed='')
        pr_for_current_release_1 = github.PullRequest.PullRequest(
            requester='',
            headers='',
            attributes={
                'label': label_for_current_release_prs,
                'number': 7567
            },
            completed='')
        pr_for_current_release_2 = github.PullRequest.PullRequest(
            requester='',
            headers='',
            attributes={
                'label': label_for_current_release_prs,
                'number': 7568
            },
            completed='')
        released_pr = github.PullRequest.PullRequest(
            requester='',
            headers='',
            attributes={
                'label': label_for_released_prs,
                'number': 7568
            },
            completed='')

        def mock_get_label(unused_self, name):
            if name == release_constants.LABEL_FOR_RELEASED_PRS:
                return label_for_released_prs
            else:
                return label_for_current_release_prs

        def mock_get_issues(unused_self, state, labels):  # pylint: disable=unused-argument
            if labels[0].name == (
                    release_constants.LABEL_FOR_CURRENT_RELEASE_PRS):
                return [pr_for_current_release_1, pr_for_current_release_2]
            else:
                return [released_pr]

        get_label_swap = self.swap(github.Repository.Repository, 'get_label',
                                   mock_get_label)
        get_issues_swap = self.swap(github.Repository.Repository, 'get_issues',
                                    mock_get_issues)

        with get_label_swap, get_issues_swap:
            with self.assertRaisesRegexp(
                    Exception, 'Following PRs are not released: \\[7567\\].'):
                wrap_up_release.remove_release_labels(self.mock_repo)
    def test_label_removal_from_prs(self):
        label_for_current_release_prs = github.Label.Label(
            requester='',
            headers='',
            attributes={
                'name': release_constants.LABEL_FOR_CURRENT_RELEASE_PRS
            },
            completed='')
        label_for_released_prs = github.Label.Label(
            requester='',
            headers='',
            attributes={'name': release_constants.LABEL_FOR_RELEASED_PRS},
            completed='')
        released_pr = github.PullRequest.PullRequest(
            requester='',
            headers='',
            attributes={
                'label': label_for_released_prs,
                'number': 7567
            },
            completed='')

        check_function_calls = {'remove_from_labels_gets_called': False}
        expected_function_calls = {'remove_from_labels_gets_called': True}

        def mock_get_label(unused_self, name):
            if name == release_constants.LABEL_FOR_RELEASED_PRS:
                return label_for_released_prs
            else:
                return label_for_current_release_prs

        # pylint: disable=unused-argument
        def mock_get_issues(unused_self, state, labels):
            if state == 'closed':
                return [released_pr]
            else:
                return []

        # pylint: enable=unused-argument
        def mock_remove_from_labels(unused_self, unused_name):
            check_function_calls['remove_from_labels_gets_called'] = True

        get_label_swap = self.swap(github.Repository.Repository, 'get_label',
                                   mock_get_label)
        get_issues_swap = self.swap(github.Repository.Repository, 'get_issues',
                                    mock_get_issues)
        remove_from_labels_swap = self.swap(github.PullRequest.PullRequest,
                                            'remove_from_labels',
                                            mock_remove_from_labels)

        with get_label_swap, get_issues_swap, remove_from_labels_swap:
            wrap_up_release.remove_release_labels(self.mock_repo)
        self.assertEqual(check_function_calls, expected_function_calls)