Esempio n. 1
0
class TestJobFolders(unittest.TestCase):
    def setUp(self):
        self.jb = JenkinsBase('http://*****:*****@mock.patch('jenkinsapi.jenkins.JenkinsBase.resolve_job_folders')
    @mock.patch('jenkinsapi.jenkins.JenkinsBase._poll')
    def test_called_in__poll(self, _poll_mock, resolve_job_folders_mock):
        _poll_mock.return_value = {
            'description': "My jobs",
            'jobs': [
                {
                    'name': "Foo",
                    'url': "http://*****:*****@mock.patch('jenkinsapi.jenkins.JenkinsBase.get_data')
    def test_empty_folder(self, get_data_mock):
        get_data_mock.return_value = {'jobs': []}
        jobs = [
            {
                'name': "Folder1",
                'url': "http://*****:*****@mock.patch('jenkinsapi.jenkins.JenkinsBase.get_data')
    def test_folder_job_mix(self, get_data_mock):
        get_data_mock.return_value = {'jobs': [
                {
                    'name': "Bar",
                    'url': "http://*****:*****@mock.patch('jenkinsapi.jenkins.JenkinsBase.get_data')
    def test_multiple_folders(self, get_data_mock):
        get_data_mock.side_effect = [
            # first call
            {
                'jobs': [
                    {
                        'name': "Foo",
                        'url': "http://*****:*****@mock.patch('jenkinsapi.jenkins.JenkinsBase.get_data')
    def test_multiple_folder_levels(self, get_data_mock):
        get_data_mock.side_effect = [
            # first call
            {
                'jobs': [
                    {
                        'name': "Bar",
                        'url': "http://localhost:8080/job/Folder1/job/Bar",
                        'color': "disabled",
                    },
                    {
                        'name': "Folder2",
                        'url': "http://localhost:8080/job/Folder1/job/Folder2",
                    },
                ]
            },

            # second call
            {
                'jobs': [
                    {
                        'name': "Baz",
                        'url': "http://localhost:8080/job/Folder1/job/Folder2/job/Baz",
                        'color': "disabled",
                    },
                ]
            },
        ]

        jobs = [
            {
                'name': "Foo",
                'url': "http://localhost:8080/job/Foo",
                'color': "blue",
            },
            {
                'name': "Folder1",
                'url': "http://localhost:8080/job/Folder1",
            },
        ]

        self.assertEquals(
            self.jb.resolve_job_folders(jobs),
            [
                {
                    'name': "Foo",
                    'url': "http://localhost:8080/job/Foo",
                    'color': "blue",
                },
                {
                    'name': "Bar",
                    'url': "http://localhost:8080/job/Folder1/job/Bar",
                    'color': "disabled",
                },
                {
                    'name': "Baz",
                    'url': "http://localhost:8080/job/Folder1/job/Folder2/job/Baz",
                    'color': "disabled",
                },
            ]
        )

        self.assertEquals(
            get_data_mock.call_args_list,
            [
                mock.call('http://localhost:8080/job/Folder1/api/python'),
                mock.call('http://localhost:8080/job/Folder1/job/Folder2/api/python'),
            ]
        )
Esempio n. 2
0
 def setUp(self):
     self.jb = JenkinsBase('http://localhost:8080/', poll=False)
Esempio n. 3
0
def jenkinsbase():
    return JenkinsBase('http://localhost:8080/', poll=False)