class TestHgJob(unittest.TestCase): JOB_DATA = { "actions": [], "description": "test job", "displayName": "foo", "displayNameOrNull": None, "name": "foo", "url": "http://*****:*****@mock.patch.object(JenkinsBase, 'get_data', fakeGetData) def setUp(self): self.J = mock.MagicMock() # Jenkins object self.j = Job('http://*****:*****@1.42"> <source>http://cm5/hg/sandbox/v01.0/int</source> <modules/> <branch>testme</branch> <clean>false</clean> <browser class="hudson.plugins.mercurial.browser.HgWeb"> <url>http://cm5/hg/sandbox/v01.0/int/</url> </browser> </scm> </project> ''' return config_node def configtree_with_default_branch(self): config_node = ''' <project> <scm class="hudson.plugins.mercurial.MercurialSCM" plugin="[email protected]"> <source>http://cm5/hg/sandbox/v01.0/int</source> <modules/> <clean>false</clean> <browser class="hudson.plugins.mercurial.browser.HgWeb"> <url>http://cm5/hg/sandbox/v01.0/int/</url> </browser> </scm> </project> ''' return config_node @mock.patch.object(Job, 'get_config', configtree_with_branch) def test_hg_attributes(self): expected_url = ['http://cm5/hg/sandbox/v01.0/int'] self.assertEquals(self.j.get_scm_type(), 'hg') self.assertEquals(self.j.get_scm_url(), expected_url) self.assertEquals(self.j.get_scm_branch(), ['testme']) @mock.patch.object(Job, 'get_config', configtree_with_default_branch) def test_hg_attributes_default_branch(self): self.assertEquals(self.j.get_scm_branch(), ['default'])
class TestHgJob(unittest.TestCase): JOB_DATA = { "actions": [], "description": "test job", "displayName": "foo", "displayNameOrNull": None, "name": "foo", "url": "http://*****:*****@mock.patch.object(JenkinsBase, 'get_data', fakeGetData) def setUp(self): self.J = mock.MagicMock() # Jenkins object self.j = Job('http://*****:*****@1.42"> <source>http://cm5/hg/sandbox/v01.0/int</source> <modules/> <branch>testme</branch> <clean>false</clean> <browser class="hudson.plugins.mercurial.browser.HgWeb"> <url>http://cm5/hg/sandbox/v01.0/int/</url> </browser> </scm> </project> ''' return config_node def configtree_with_default_branch(self): config_node = ''' <project> <scm class="hudson.plugins.mercurial.MercurialSCM" plugin="[email protected]"> <source>http://cm5/hg/sandbox/v01.0/int</source> <modules/> <clean>false</clean> <browser class="hudson.plugins.mercurial.browser.HgWeb"> <url>http://cm5/hg/sandbox/v01.0/int/</url> </browser> </scm> </project> ''' return config_node def configtree_multibranch_git(self): config_node = ''' <flow-definition plugin="[email protected]"> <keepDependencies>false</keepDependencies> <properties> <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty> <triggers> <hudson.triggers.TimerTrigger> <spec>H H * * H(6-7)</spec> </hudson.triggers.TimerTrigger> <jenkins.triggers.ReverseBuildTrigger> <spec></spec> <upstreamProjects></upstreamProjects> <threshold> <name>SUCCESS</name> <ordinal>0</ordinal> <color>BLUE</color> <completeBuild>true</completeBuild> </threshold> </jenkins.triggers.ReverseBuildTrigger> </triggers> </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty> <jenkins.model.BuildDiscarderProperty> <strategy class="hudson.tasks.LogRotator"> <daysToKeep>-1</daysToKeep> <numToKeep>5</numToKeep> <artifactDaysToKeep>-1</artifactDaysToKeep> <artifactNumToKeep>5</artifactNumToKeep> </strategy> </jenkins.model.BuildDiscarderProperty> <org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty plugin="[email protected]"> <branch plugin="[email protected]"> <sourceId>a2d4bcda-6141-4af2-8088-39139a147902</sourceId> <head class="com.cloudbees.jenkins.plugins.bitbucket.BranchSCMHead" plugin="[email protected]"> <name>master</name> <repositoryType>GIT</repositoryType> </head> <scm class="hudson.plugins.git.GitSCM" plugin="[email protected]"> <configVersion>2</configVersion> <userRemoteConfigs> <hudson.plugins.git.UserRemoteConfig> <name>origin</name> <refspec>+refs/heads/master:refs/remotes/origin/master</refspec> <url>ssh://[email protected]/project-name/reponame.git</url> <credentialsId>jenkins-stash</credentialsId> </hudson.plugins.git.UserRemoteConfig> </userRemoteConfigs> <branches class="singleton-list"> <hudson.plugins.git.BranchSpec> <name>master</name> </hudson.plugins.git.BranchSpec> </branches> <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> <browser class="hudson.plugins.git.browser.BitbucketWeb"> <url>https://bitbucket.site/projects/project-name/repos/reponame</url> </browser> <submoduleCfg class="empty-list"/> <extensions> <jenkins.plugins.git.GitSCMSourceDefaults> <includeTags>false</includeTags> </jenkins.plugins.git.GitSCMSourceDefaults> </extensions> </scm> <properties/> </branch> </org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty> </properties> <definition class="org.jenkinsci.plugins.workflow.multibranch.SCMBinder" plugin="[email protected]"> <scriptPath>Jenkinsfile</scriptPath> </definition> <triggers/> <disabled>false</disabled> </flow-definition> ''' return config_node @mock.patch.object(Job, 'get_config', configtree_with_branch) def test_hg_attributes(self): expected_url = ['http://cm5/hg/sandbox/v01.0/int'] self.assertEqual(self.j.get_scm_type(), 'hg') self.assertEqual(self.j.get_scm_url(), expected_url) self.assertEqual(self.j.get_scm_branch(), ['testme']) @mock.patch.object(Job, 'get_config', configtree_with_default_branch) def test_hg_attributes_default_branch(self): self.assertEqual(self.j.get_scm_branch(), ['default']) @mock.patch.object(Job, 'get_config', configtree_multibranch_git) def test_git_attributes_multibranch(self): expected_url = ['ssh://[email protected]/project-name/reponame.git'] self.assertEqual(self.j.get_scm_type(), 'git') self.assertEqual(self.j.get_scm_url(), expected_url) self.assertEqual(self.j.get_scm_branch(), ['master'])
class TestHgJob(unittest.TestCase): JOB_DATA = { "actions": [], "description": "test job", "displayName": "foo", "displayNameOrNull": None, "name": "foo", "url": "http://*****:*****@mock.patch.object(JenkinsBase, 'get_data', fakeGetData) def setUp(self): self.J = mock.MagicMock() # Jenkins object self.j = Job('http://*****:*****@1.42"> <source>http://cm5/hg/sandbox/v01.0/int</source> <modules/> <branch>testme</branch> <clean>false</clean> <browser class="hudson.plugins.mercurial.browser.HgWeb"> <url>http://cm5/hg/sandbox/v01.0/int/</url> </browser> </scm> </project> ''' return config_node def configtree_with_default_branch(self): config_node = ''' <project> <scm class="hudson.plugins.mercurial.MercurialSCM" plugin="[email protected]"> <source>http://cm5/hg/sandbox/v01.0/int</source> <modules/> <clean>false</clean> <browser class="hudson.plugins.mercurial.browser.HgWeb"> <url>http://cm5/hg/sandbox/v01.0/int/</url> </browser> </scm> </project> ''' return config_node @mock.patch.object(Job, 'get_config', configtree_with_branch) def test_hg_attributes(self): expected_url = ['http://cm5/hg/sandbox/v01.0/int'] self.assertEqual(self.j.get_scm_type(), 'hg') self.assertEqual(self.j.get_scm_url(), expected_url) self.assertEqual(self.j.get_scm_branch(), ['testme']) @mock.patch.object(Job, 'get_config', configtree_with_default_branch) def test_hg_attributes_default_branch(self): self.assertEqual(self.j.get_scm_branch(), ['default'])