support for binary artifacts
authorSalim Fadhley <sal@stodge.org>
Sun, 30 Jun 2013 00:01:35 +0000 (01:01 +0100)
committerSalim Fadhley <sal@stodge.org>
Sun, 30 Jun 2013 00:01:35 +0000 (01:01 +0100)
jenkinsapi/artifact.py
jenkinsapi_tests/systests/job_configs.py
jenkinsapi_tests/systests/test_jenkins_artifacts.py

index ffb619c..ac11fb2 100644 (file)
@@ -7,13 +7,12 @@ artifacts associated with it.
 This module provides a class called Artifact which allows you to download objects from the server
 and also access them as a stream.
 """
-from __future__ import with_statement
 import os
 import logging
 import hashlib
 
-from jenkinsapi.exceptions import ArtifactBroken
 from jenkinsapi.fingerprint import Fingerprint
+from jenkinsapi.exceptions import ArtifactBroken
 
 log = logging.getLogger(__name__)
 
@@ -66,7 +65,7 @@ class Artifact(object):
         Grab the text of the artifact
         """
         response = self.get_jenkins_obj().requester.get_and_confirm_status(self.url)
-        return response.text
+        return response.content
 
     def _do_download(self, fspath):
         """
index 59c5c47..2dd75db 100644 (file)
@@ -142,12 +142,13 @@ JOB_WITH_ARTIFACTS = """
   <concurrentBuild>false</concurrentBuild>
   <builders>
     <hudson.tasks.Shell>
-      <command>ping -c 5 localhost | tee out.txt</command>
+      <command>ping -c 5 localhost | tee out.txt
+gzip &lt; out.txt &gt; out.gz</command>
     </hudson.tasks.Shell>
   </builders>
   <publishers>
     <hudson.tasks.ArtifactArchiver>
-      <artifacts>*.txt</artifacts>
+      <artifacts>*.txt,*.gz</artifacts>
       <latestOnly>false</latestOnly>
     </hudson.tasks.ArtifactArchiver>
     <hudson.tasks.Fingerprinter>
index ee69ae9..42abdcb 100644 (file)
@@ -3,6 +3,7 @@ System tests for `jenkinsapi.jenkins` module.
 '''
 import os
 import time
+import gzip
 import shutil
 import tempfile
 import unittest
@@ -11,6 +12,7 @@ from jenkinsapi_tests.systests.base import BaseSystemTest
 from jenkinsapi_tests.systests.job_configs import JOB_WITH_ARTIFACTS
 from jenkinsapi_tests.test_utils.random_strings import random_string
 
+
 class TestPingerJob(BaseSystemTest):
 
     def test_invoke_job(self):
@@ -21,18 +23,30 @@ class TestPingerJob(BaseSystemTest):
         b = job.get_last_build()
 
         while b.is_running():
-            time.sleep(0.25)
+            time.sleep(1)
 
         artifacts = b.get_artifact_dict()
         self.assertIsInstance(artifacts, dict)
 
-        artifact = artifacts['out.txt']
+        text_artifact = artifacts['out.txt']
+        binary_artifact = artifacts['out.gz']
 
         tempDir = tempfile.mkdtemp()
 
         try:
-            artifact.save_to_dir(tempDir)
-            readBackText = open(os.path.join(tempDir, artifact.filename), 'rb').read().strip()
+            # Verify that we can handle text artifacts
+            text_artifact.save_to_dir(tempDir)
+            readBackText = open(os.path.join(
+                tempDir, text_artifact.filename), 'rb').read().strip()
+            self.assertTrue(readBackText.startswith('PING localhost'))
+            self.assertTrue(readBackText.endswith('ms'))
+
+            # Verify that we can hande binary artifacts
+            binary_artifact.save_to_dir(tempDir)
+            readBackText = gzip.open(os.path.join(
+                tempDir, 
+                binary_artifact.filename,
+                ), 'rb' ).read().strip()
             self.assertTrue(readBackText.startswith('PING localhost'))
             self.assertTrue(readBackText.endswith('ms'))
         finally: