File: test_job_scm_hg.py

package info (click to toggle)
python-jenkinsapi 0.3.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,500 kB
  • sloc: python: 10,001; xml: 50; makefile: 31; sh: 26
file content (203 lines) | stat: -rw-r--r-- 8,806 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# flake8: noqa
#    import mock
#
#    # To run unittests on python 2.6 please use unittest2 library
#    try:
#        import unittest2 as unittest
#    except ImportError:
#        import unittest
#
#    from jenkinsapi import config
#    from jenkinsapi.job import Job
#    from jenkinsapi.jenkinsbase import JenkinsBase
#
#
#    CFG_NODE = """
#    <project>
#    <scm class="hudson.plugins.mercurial.MercurialSCM" plugin="mercurial@1.42">
#    <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>
#    """
#
#    # TODO: Make JOB_DATA to be one coming from Hg job
#    class TestHgJob(unittest.TestCase):
#        JOB_DATA = {
#            "actions": [],
#            "description": "test job",
#            "displayName": "foo",
#            "displayNameOrNull": None,
#            "name": "foo",
#            "url": "http://halob:8080/job/foo/",
#            "buildable": True,
#            "builds": [
#                {"number": 3, "url": "http://halob:8080/job/foo/3/"},
#                {"number": 2, "url": "http://halob:8080/job/foo/2/"},
#                {"number": 1, "url": "http://halob:8080/job/foo/1/"},
#            ],
#            "color": "blue",
#            "firstBuild": {"number": 1, "url": "http://halob:8080/job/foo/1/"},
#            "healthReport": [
#                {
#                    "description": "Build stability: No recent builds failed.",
#                    "iconUrl": "health-80plus.png",
#                    "score": 100,
#                }
#            ],
#            "inQueue": False,
#            "keepDependencies": False,
#            # build running
#            "lastBuild": {"number": 4, "url": "http://halob:8080/job/foo/4/"},
#            "lastCompletedBuild": {
#                "number": 3,
#                "url": "http://halob:8080/job/foo/3/",
#            },
#            "lastFailedBuild": None,
#            "lastStableBuild": {
#                "number": 3,
#                "url": "http://halob:8080/job/foo/3/",
#            },
#            "lastSuccessfulBuild": {
#                "number": 3,
#                "url": "http://halob:8080/job/foo/3/",
#            },
#            "lastUnstableBuild": None,
#            "lastUnsuccessfulBuild": None,
#            "nextBuildNumber": 4,
#            "property": [],
#            "queueItem": None,
#            "concurrentBuild": False,
#            "downstreamProjects": [],
#            "scm": {},
#            "upstreamProjects": [],
#        }
#
#        URL_DATA = {"http://halob:8080/job/foo/%s" % config.JENKINS_API: JOB_DATA}
#
#        def fakeGetData(self, url, *args, **kwargs):
#            try:
#                return TestHgJob.URL_DATA[url]
#            except KeyError:
#                raise Exception("Missing data for %s" % url)
#
#        @mock.patch.object(JenkinsBase, "get_data", fakeGetData)
#        def setUp(self):
#            self.J = mock.MagicMock()  # Jenkins object
#            self.j = Job("http://halob:8080/job/foo/", "foo", self.J)
#
#        def configtree_with_branch(self):
#            config_node = CFG_NODE
#            return config_node
#
#        def configtree_with_default_branch(self):
#            config_node = CFG_NODE
#            return config_node
#
#        def configtree_multibranch_git(self):
#            config_node = """
#    <flow-definition plugin="workflow-job@2.35">
#        <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="workflow-multibranch@2.21">
#                <branch plugin="branch-api@2.5.4">
#                    <sourceId>a2d4bcda-6141-4af2-8088-39139a147902</sourceId>
#                    <head class="com.cloudbees.jenkins.plugins.bitbucket.BranchSCMHead"
#                            plugin="cloudbees-bitbucket-branch-source@2.5.0">
#                        <name>master</name>
#                        <repositoryType>GIT</repositoryType>
#                    </head>
#                    <scm class="hudson.plugins.git.GitSCM" plugin="git@3.12.1">
#                        <configVersion>2</configVersion>
#                        <userRemoteConfigs>
#                            <hudson.plugins.git.UserRemoteConfig>
#                                <name>origin</name>
#                                <refspec>+refs/heads/master:refs/remotes/origin/master</refspec>
#                                <url>ssh://git@bitbucket.site/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="workflow-multibranch@2.21">
#            <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.j.load_config()
#            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.j.load_config()
#            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://git@bitbucket.site/project-name/reponame.git"]
#            self.j.load_config()
#            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"])
#
#
#    if __name__ == "__main__":
#        unittest.main()