Don't encode video and don't send uploaded files to GCS when TESTING.

Unittests shouldn't connect to external systems. We could mock GCS and
Zencoder, but that's a lot more work, and takes time to maintain.
This commit is contained in:
2016-07-08 10:56:15 +02:00
parent bfba44e5b8
commit 1c03ea8dec

View File

@@ -120,6 +120,9 @@ def _process_image(gcs, file_id, local_file, src_file):
# TODO: parallelize this at some point. # TODO: parallelize this at some point.
for variation in src_file['variations']: for variation in src_file['variations']:
fname = variation['file_path'] fname = variation['file_path']
if current_app.config['TESTING']:
log.warning(' - NOT sending thumbnail %s to GCS', fname)
else:
log.debug(' - Sending thumbnail %s to GCS', fname) log.debug(' - Sending thumbnail %s to GCS', fname)
blob = gcs.bucket.blob('_/' + fname, chunk_size=256 * 1024 * 2) blob = gcs.bucket.blob('_/' + fname, chunk_size=256 * 1024 * 2)
blob.upload_from_filename(variation['local_path'], blob.upload_from_filename(variation['local_path'],
@@ -166,6 +169,12 @@ def _process_video(gcs, file_id, local_file, src_file):
# that's why we build a list. # that's why we build a list.
src_file['variations'].append(file_variation) src_file['variations'].append(file_variation)
if current_app.config['TESTING']:
log.warning('_process_video: NOT sending out encoding job due to TESTING=%r',
current_app.config['TESTING'])
j = type('EncoderJob', (), {'process_id': 'fake-process-id',
'backend': 'fake'})
else:
j = Encoder.job_create(src_file) j = Encoder.job_create(src_file)
if j is None: if j is None:
log.warning('_process_video: unable to create encoder job for file %s.', file_id) log.warning('_process_video: unable to create encoder job for file %s.', file_id)
@@ -561,6 +570,12 @@ def stream_to_gcs(project_id):
else: else:
file_size = os.fstat(stream_for_gcs.fileno()).st_size file_size = os.fstat(stream_for_gcs.fileno()).st_size
if current_app.config['TESTING']:
log.warning('NOT streaming to GCS because TESTING=%r', current_app.config['TESTING'])
# Fake a Blob object.
gcs = None
blob = type('Blob', (), {'size': file_size})
else:
# Upload the file to GCS. # Upload the file to GCS.
from gcloud.streaming import transfer from gcloud.streaming import transfer
# Files larger than this many bytes will be streamed directly from disk, smaller # Files larger than this many bytes will be streamed directly from disk, smaller