From: Salim Fadhley Date: Sun, 30 Jun 2013 00:01:35 +0000 (+0100) Subject: support for binary artifacts X-Git-Tag: v0.2.23~117^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2a7b66eb6a9170afd426a5fbabdc8cd087a3443c;p=tools%2Fpython-jenkinsapi.git support for binary artifacts --- diff --git a/jenkinsapi/artifact.py b/jenkinsapi/artifact.py index ffb619c..ac11fb2 100644 --- a/jenkinsapi/artifact.py +++ b/jenkinsapi/artifact.py @@ -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): """ diff --git a/jenkinsapi_tests/systests/job_configs.py b/jenkinsapi_tests/systests/job_configs.py index 59c5c47..2dd75db 100644 --- a/jenkinsapi_tests/systests/job_configs.py +++ b/jenkinsapi_tests/systests/job_configs.py @@ -142,12 +142,13 @@ JOB_WITH_ARTIFACTS = """ false - ping -c 5 localhost | tee out.txt + ping -c 5 localhost | tee out.txt +gzip < out.txt > out.gz - *.txt + *.txt,*.gz false diff --git a/jenkinsapi_tests/systests/test_jenkins_artifacts.py b/jenkinsapi_tests/systests/test_jenkins_artifacts.py index ee69ae9..42abdcb 100644 --- a/jenkinsapi_tests/systests/test_jenkins_artifacts.py +++ b/jenkinsapi_tests/systests/test_jenkins_artifacts.py @@ -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: