Begin test cases for testing jenkins API calls related to the SCM
authorSudharshan S <sudharsh@gmail.com>
Tue, 25 Jun 2013 16:24:31 +0000 (21:54 +0530)
committerSudharshan S <sudharsh@gmail.com>
Wed, 26 Jun 2013 09:41:39 +0000 (15:11 +0530)
Use JenkinsLauncher.install_plugin to install Jenkins git plugins and verify coverage for Build.get_revision() fix

jenkinsapi_tests/systests/job_configs.py
jenkinsapi_tests/systests/test_scm.py [new file with mode: 0644]

index 4cea72be94b8327470682847617eb3e1f01a907e..a7a4204d73906f126de49bc57915b471037154cf 100644 (file)
@@ -67,3 +67,61 @@ SHORTISH_JOB = """
   <publishers/>
   <buildWrappers/>
 </project>""".strip()
+
+
+SCM_GIT_JOB = """
+<?xml version='1.0' encoding='UTF-8'?>
+<project>
+  <actions/>
+  <description></description>
+  <properties/>
+  <scm class="hudson.plugins.git.GitSCM" plugin="git@1.4.0">
+    <configVersion>2</configVersion>
+    <userRemoteConfigs>
+      <hudson.plugins.git.UserRemoteConfig>
+        <name></name>
+        <refspec></refspec>
+        <url>https://github.com/salimfadhley/jenkinsapi.git</url>
+      </hudson.plugins.git.UserRemoteConfig>
+    </userRemoteConfigs>
+    <branches>
+      <hudson.plugins.git.BranchSpec>
+        <name>**</name>
+      </hudson.plugins.git.BranchSpec>
+    </branches>
+    <disableSubmodules>false</disableSubmodules>
+    <recursiveSubmodules>false</recursiveSubmodules>
+    <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
+    <authorOrCommitter>false</authorOrCommitter>
+    <clean>false</clean>
+    <wipeOutWorkspace>false</wipeOutWorkspace>
+    <pruneBranches>false</pruneBranches>
+    <remotePoll>false</remotePoll>
+    <ignoreNotifyCommit>false</ignoreNotifyCommit>
+    <useShallowClone>false</useShallowClone>
+    <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
+    <gitTool>Default</gitTool>
+    <submoduleCfg class="list"/>
+    <relativeTargetDir></relativeTargetDir>
+    <reference></reference>
+    <excludedRegions></excludedRegions>
+    <excludedUsers></excludedUsers>
+    <gitConfigName></gitConfigName>
+    <gitConfigEmail></gitConfigEmail>
+    <skipTag>false</skipTag>
+    <includedRegions></includedRegions>
+    <scmName></scmName>
+  </scm>
+  <canRoam>true</canRoam>
+  <disabled>false</disabled>
+  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
+  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
+  <builders>
+    <hudson.tasks.Shell>
+      <command>ping -c 10 localhost</command>
+    </hudson.tasks.Shell>
+  </builders>
+  <publishers/>
+  <buildWrappers/>
+</project>
+"""
diff --git a/jenkinsapi_tests/systests/test_scm.py b/jenkinsapi_tests/systests/test_scm.py
new file mode 100644 (file)
index 0000000..c5fcfb1
--- /dev/null
@@ -0,0 +1,31 @@
+'''
+System tests for `jenkinsapi.jenkins` module.
+'''
+import unittest
+from jenkinsapi.invocation import Invocation
+from jenkinsapi_tests.systests import state
+from jenkinsapi_tests.systests.base import BaseSystemTest
+from jenkinsapi_tests.test_utils.random_strings import random_string
+from jenkinsapi_tests.systests.job_configs import SCM_GIT_JOB
+
+# Maybe have a base class for all SCM test activites?
+class TestSCMGIT(BaseSystemTest):
+    # Maybe it makes sense to move plugin dependencies outside the code.
+    # Have a config to dependencies mapping from the launcher can use to install plugins.
+    PLUGIN_DEPENDENCIES = ["http://updates.jenkins-ci.org/latest/git.hpi",
+                           "http://updates.jenkins-ci.org/latest/git-client.hpi"]
+    
+    def test_get_revision(self):
+        job_name = 'create_%s' % random_string()
+        state['launcher'].install_plugin(self.PLUGIN_DEPENDENCIES)
+        job = self.jenkins.create_job(job_name, SCM_GIT_JOB)
+        ii = job.invoke()
+        ii.block(until='completed')
+        self.assertFalse(ii.is_running())
+        bn = ii.get_build_number()
+        b = job.get_build(bn)
+        self.assertIsInstance(b.get_revision(), basestring)
+
+if __name__ == '__main__':
+    unittest.main()
+