Beispiel #1
0
class DedupePerAuthorTestCase(TestCase):

    """
    TestCase class for testing the one_per_author feature
    """

    def setUp(self):
        self.job_url = 'http://*****:*****@patch('jenkins.job.JenkinsJob.stop_build', return_value=True)
    @patch('jenkins.job.JenkinsJob.update_build_desc', return_value=True)
    def test_stop_per_author_no_duplicates(self, update_desc, stop_build):
        sample_build_data = sample_data(
            [Pr('2', author='foo').dict, Pr('2', author='bar').dict], [])
        build_data = self.deduper.get_running_builds(sample_build_data)
        self.deduper.stop_duplicates(build_data)
        self.assertFalse(stop_build.called)

    @patch('jenkins.job.JenkinsJob.stop_build', return_value=True)
    @patch('jenkins.job.JenkinsJob.update_build_desc', return_value=True)
    def test_stop_per_author_no_duplicates_by_pr(self, update_desc,
                                                 stop_build):
        sample_build_data = sample_data(
            [Pr('2', author='foo').dict, Pr('3', author='foo').dict], [])
        build_data = self.deduper.get_running_builds(sample_build_data)
        self.deduper.stop_duplicates(build_data)
        self.assertFalse(stop_build.called)

    @patch('jenkins.job.JenkinsJob.stop_build', return_value=True)
    @patch('jenkins.job.JenkinsJob.update_build_desc', return_value=True)
    def test_stop_per_author_with_duplicates(self, update_desc, stop_build):
        sample_build_data = sample_data(
            [Pr('2', author='foo').dict, Pr('2', author='foo').dict], [])
        build_data = self.deduper.get_running_builds(sample_build_data)
        self.deduper.stop_duplicates(build_data)
        stop_build.assert_called_once_with(1)
Beispiel #2
0
class DeduperTestCase(TestCase):

    """
    TestCase class for testing deduper.py.
    """

    def setUp(self):
        self.job_url = 'http://*****:*****@patch('jenkins.job.JenkinsJob.stop_build', return_value=True)
    @patch('jenkins.job.JenkinsJob.update_build_desc', return_value=True)
    @patch('jenkins.deduper.GhprbOutdatedBuildAborter._aborted_description',
           return_value='new description')
    def test_stop_duplicates_with_duplicates(self, mock_desc,
                                             update_desc,
                                             stop_build):
        sample_build_data = sample_data(
            [Pr('1').dict, Pr('2').dict, Pr('2').dict, Pr('3').dict], [])
        build_data = self.deduper.get_running_builds(sample_build_data)
        self.deduper.stop_duplicates(build_data)
        stop_build.assert_called_once_with(2)
        update_desc.assert_called_once_with(2, mock_desc())

    @patch('jenkins.job.JenkinsJob.stop_build', side_effect=HTTPError())
    @patch('jenkins.job.JenkinsJob.update_build_desc', return_value=True)
    def test_stop_duplicates_failed_to_stop(self, update_desc, stop_build):
        sample_build_data = sample_data(
            [Pr('1').dict, Pr('2').dict, Pr('2').dict, Pr('3').dict], [])
        build_data = self.deduper.get_running_builds(sample_build_data)
        self.deduper.stop_duplicates(build_data)
        stop_build.assert_called_once_with(2)
        self.assertFalse(update_desc.called)

    @patch('jenkins.job.JenkinsJob.stop_build', return_value=True)
    @patch('jenkins.job.JenkinsJob.update_build_desc', return_value=True)
    def test_stop_duplicates_no_duplicates(self, update_desc, stop_build):
        sample_build_data = sample_data(
            [Pr('1').dict, Pr('2').dict, Pr('3').dict], [Pr('2').dict])
        build_data = self.deduper.get_running_builds(sample_build_data)
        self.deduper.stop_duplicates(build_data)
        self.assertFalse(stop_build.called)
        self.assertFalse(update_desc.called)

    @patch('jenkins.job.JenkinsJob.get_json', return_value=sample_data(
        [Pr('1').dict, Pr('2', author='a').dict, Pr('2', author='b').dict],
        [Pr('4').dict, Pr('5').dict, Pr('5').dict]))
    @patch('jenkins.job.JenkinsJob.stop_build', return_value=True)
    @patch('jenkins.job.JenkinsJob.update_build_desc', return_value=True)
    @patch('jenkins.deduper.GhprbOutdatedBuildAborter._aborted_description',
           return_value='new description')
    def test_main_default_per_author(
            self, mock_desc, update_desc, stop_build, get_json):
        args = [
            '-t', self.api_key,
            '-u', self.user,
            '-j', self.job_url,
            '--log-level', 'INFO',
        ]
        deduper_main(args)
        get_json.assert_called_once_with()
        stop_build.assert_called_once_with(2)
        update_desc.assert_called_once_with(2, mock_desc())

    @patch('jenkins.job.JenkinsJob.get_json', return_value=sample_data(
        [Pr('1').dict, Pr('2', author='a').dict, Pr('2', author='b').dict],
        [Pr('4').dict, Pr('5').dict, Pr('5').dict]))
    @patch('jenkins.job.JenkinsJob.stop_build', return_value=True)
    @patch('jenkins.job.JenkinsJob.update_build_desc', return_value=True)
    def test_main_one_per_author(self, update_desc, stop_build, get_json):
        args = [
            '-t', self.api_key,
            '-u', self.user,
            '-j', self.job_url,
            '--log-level', 'INFO',
            '--one-per-author'
        ]
        deduper_main(args)
        get_json.assert_called_once_with()
        self.assertFalse(stop_build.called)
        self.assertFalse(update_desc.called)