def test_reads_scm_from_string_props_when_no_scm_config(self,
                                                            mock_job_class):
        # given
        config_path = path.join(path.dirname(__name__),
                                'resources',
                                'jenkins_job_config_git_cfg_string_props.xml')
        config_root = ElementTree.parse(config_path).getroot()
        jenkins_job = mock_job_class()
        jenkins_job.get_config.return_value = ElementTree.tostring(config_root)

        action = JobAction()

        # when
        scm_urls = action.get_scm_url(jenkins_job)

        # then
        assert '[email protected]:secret-projects/project1.git' in scm_urls
    def test_updates_branch_in_scm_config_when_present(self, mock_job_class):
        # given
        config_path = path.join(path.dirname(__name__),
                                'resources',
                                'jenkins_job_config_git_cfg_scm.xml')
        config_root = ElementTree.parse(config_path).getroot()
        config_content = ElementTree.tostring(config_root)
        jenkins_job = mock_job_class()
        jenkins_job.get_config.return_value = config_content
        jenkins_job.get_scm_url.return_value = [
            '[email protected]:secret-projects/project1.git'
        ]

        action = JobAction()

        # when
        action.modify_scm_branch(jenkins_job, 'updated-branch')

        # then
        jenkins_job.modify_scm_branch.assert_called_with('updated-branch')
    def test_updates_branch_in_str_params_when_no_scm_revision(self,
                                                               mock_job_class):
        # given
        config_path = path.join(path.dirname(__name__),
                                'resources',
                                'jenkins_job_config_git_cfg_string_props.xml')
        config_root = ElementTree.parse(config_path).getroot()
        config_content = ElementTree.tostring(config_root)
        jenkins_job = mock_job_class()
        jenkins_job.get_config.return_value = config_content

        action = JobAction()

        # when
        action.modify_scm_branch(jenkins_job, 'updated-branch')
        updated_config_content = config_content.replace('>master<',
                                                        '>updated-branch<')

        # then
        jenkins_job.update_config.assert_called_with(updated_config_content)