From 62817eec40dd09787239be3c499888d4068a02f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 10 May 2016 12:33:38 +0200 Subject: [PATCH] Skip renaming file on GCS when testing. This allows running this test while the internet is gone. --- pillar/application/modules/encoding.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pillar/application/modules/encoding.py b/pillar/application/modules/encoding.py index 73903ba5..7e411cc1 100644 --- a/pillar/application/modules/encoding.py +++ b/pillar/application/modules/encoding.py @@ -8,6 +8,7 @@ from flask import abort from flask import request from flask import current_app from application import utils +from application.utils import skip_when_testing from application.utils.gcs import GoogleCloudStorageBucket encoding = Blueprint('encoding', __name__) @@ -41,6 +42,13 @@ def size_descriptor(width, height): return '%ip' % height +@skip_when_testing +def rename_on_gcs(bucket_name, from_path, to_path): + gcs = GoogleCloudStorageBucket(str(bucket_name)) + blob = gcs.bucket.blob(from_path) + gcs.bucket.rename_blob(blob, to_path) + + @encoding.route('/zencoder/notifications', methods=['POST']) def zencoder_notifications(): """ @@ -137,9 +145,9 @@ def zencoder_notifications(): # Rename on Google Cloud Storage try: - gcs = GoogleCloudStorageBucket(str(file_doc['project'])) - blob = gcs.bucket.blob('_/' + variation['file_path']) - gcs.bucket.rename_blob(blob, '_/' + new_fname) + rename_on_gcs(file_doc['project'], + '_/' + variation['file_path'], + '_/' + new_fname) except Exception: log.warning('Unable to rename GCS blob %r to %r. Keeping old name.', variation['file_path'], new_fname, exc_info=True)