More small fixes to jobs, I've begun work on a test for artifacts however I know...
authorsalimfadhley <sal@stodge.org>
Mon, 10 Jun 2013 23:54:44 +0000 (00:54 +0100)
committersalimfadhley <sal@stodge.org>
Mon, 10 Jun 2013 23:54:44 +0000 (00:54 +0100)
jenkinsapi/job.py
jenkinsapi_tests/systests/test_jenkins.py
jenkinsapi_tests/systests/test_jenkins_artifacts.py [new file with mode: 0644]

index f61d269..49a40e8 100644 (file)
@@ -331,14 +331,18 @@ class Job(JenkinsBase, MutableJenkinsThing):
                     scm_url.text = new_source_url
                     self.update_config(ET.tostring(element_tree))
 
+    def get_config_xml_url(self):
+        return '%s/config.xml' % self.baseurl
+
     def update_config(self, config):
         """
         Update the config.xml to the job
         Also refresh the ElementTree object since the config has changed
         """
-        post_data = self.post_data("%(baseurl)s/config.xml" % self.__dict__, config)
+        url = self.get_config_xml_url()
+        response = self.jenkins.requester.post_url(url, params={}, data='')
         self._element_tree = ET.fromstring(config)
-        return post_data
+        return response.text
 
     def get_downstream_jobs(self):
         """
index 6fca863..7f52eef 100644 (file)
@@ -14,12 +14,13 @@ class JobTests(BaseSystemTest):
         self.jenkins.create_job(job_name, EMPTY_JOB_CONFIG)
         self.assertJobIsPresent(job_name)
 
-    def test_get_job_config(self):
+    def test_get_job_and_update_config(self):
         job_name = 'config_%s' % random_string()
         self.jenkins.create_job(job_name, EMPTY_JOB_CONFIG)
         self.assertJobIsPresent(job_name)
         config = self.jenkins[job_name].get_config()
         self.assertEquals(config.strip(), EMPTY_JOB_CONFIG.strip())
+        self.jenkins[job_name].update_config(EMPTY_JOB_CONFIG)
 
     def test_invoke_job(self):
         job_name = 'create_%s' % random_string()
diff --git a/jenkinsapi_tests/systests/test_jenkins_artifacts.py b/jenkinsapi_tests/systests/test_jenkins_artifacts.py
new file mode 100644 (file)
index 0000000..282c175
--- /dev/null
@@ -0,0 +1,58 @@
+'''
+System tests for `jenkinsapi.jenkins` module.
+'''
+import time
+import unittest
+from jenkinsapi_tests.test_utils.random_strings import random_string
+from jenkinsapi_tests.systests.base import BaseSystemTest
+
+PINGER_JOB_CONFIG = """
+<?xml version='1.0' encoding='UTF-8'?>
+<project>
+  <actions/>
+  <description>Ping a load of stuff for about 10s</description>
+  <keepDependencies>false</keepDependencies>
+  <properties/>
+  <scm class="hudson.scm.NullSCM"/>
+  <canRoam>true</canRoam>
+  <disabled>false</disabled>
+  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
+  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
+  <triggers class="vector"/>
+  <concurrentBuild>false</concurrentBuild>
+  <builders>
+    <hudson.tasks.Shell>
+      <command>ping -c 5 localhost | tee out.txt</command>
+    </hudson.tasks.Shell>
+  </builders>
+  <publishers>
+    <hudson.tasks.ArtifactArchiver>
+      <artifacts>*.txt</artifacts>
+      <latestOnly>false</latestOnly>
+    </hudson.tasks.ArtifactArchiver>
+  </publishers>
+  <buildWrappers/>
+</project>""".strip()
+
+class TestPingerJob(BaseSystemTest):
+
+    def test_invoke_job(self):
+        job_name = 'create_%s' % random_string()
+        job = self.jenkins.create_job(job_name, PINGER_JOB_CONFIG)
+        job.invoke(block=True)
+
+        b = job.get_last_build()
+
+        while b.is_running():
+            time.sleep(0.25)
+
+        artifacts = b.get_artifact_dict()
+        self.assertIsInstance(artifacts, dict)
+
+        outfile = artifacts['out.txt']
+
+        # TODO: Actually verify the download
+
+
+if __name__ == '__main__':
+    unittest.main()