def test_get_config_does_not_exist(self): """ Tests that utils.get_config if file does not exist. """ del os.environ['VEDA_ENCODE_WORKER_CFG'] with self.assertRaises(IOError): utils.get_config(yaml_config_file='does_not_exist')
def test_get_config_with_path(self): """ Tests that utils.get_config works as expected when reading config from environment path. """ with patch('video_worker.utils.STATIC_CONFIG_FILE_PATH', self.static_file_path): with patch('video_worker.utils.DEFAULT_CONFIG_FILE_NAME', self.file_path): instance_config = utils.get_config() self.assertDictEqual(instance_config, dict(TEST_CONFIG, **TEST_STATIC_CONFIG))
def test_get_config_with_default(self): """ Tests that utils.get_config works as expected when reading default config. """ del os.environ['VEDA_ENCODE_WORKER_CFG'] instance_config = utils.get_config() self.assertNotEqual(instance_config, {}) # read the default config file default_yaml_config_file = os.path.join(utils.ROOT_DIR, utils.DEFAULT_CONFIG_FILE_NAME) with open(default_yaml_config_file, 'r') as config: config_dict = yaml.load(config, Loader=yaml.FullLoader) # read the default static config file with open(utils.STATIC_CONFIG_FILE_PATH, 'r') as config: static_config_dict = yaml.load(config, Loader=yaml.FullLoader) self.assertDictEqual(instance_config, dict(config_dict, **static_config_dict))
""" from __future__ import absolute_import import ast import logging import os import requests import urllib3 from video_worker.utils import get_config """Disable insecure warning for requests lib""" urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) settings = get_config() logger = logging.getLogger(__name__) def veda_tokengen(): """ Gen and authorize a VEDA API token """ # Generate Token payload = {'grant_type': 'client_credentials'} veda_token_response = requests.post(settings['veda_token_url'] + '/', params=payload, auth=(settings['veda_client_id'], settings['veda_secret_key']), timeout=settings['global_timeout'])
def settings_setup(self): return get_config()
""" This file tests token generation for val and veda APIs. """ import json import unittest from ddt import ddt, data, unpack from mock import Mock, patch from video_worker.generate_apitoken import val_tokengen, veda_tokengen from video_worker.tests.utils import TEST_INSTANCE_YAML_FILE from video_worker.utils import get_config WORKER_SETTINGS = get_config(yaml_config_file=TEST_INSTANCE_YAML_FILE) @ddt @patch('video_worker.generate_apitoken.settings', WORKER_SETTINGS) class GenerateApiTokenTest(unittest.TestCase): """ GenerateApiToken test class. """ @patch('video_worker.generate_apitoken.requests.post') @patch('video_worker.generate_apitoken.logger') def test_veda_tokengen_fail(self, mock_logger, mock_post): """ Tests `veda_tokengen` method logs correct error message. """ mock_post.return_value = Mock(status_code=400, text='', content={}) response = veda_tokengen()
def settings_setup(self): """ Initialize settings """ return get_config()
def run(self): self.settings = get_config() if self.encode_profile is None: logger.error('No Encode Profile Specified') return self.VideoObject = Video(veda_id=self.veda_id, ) if self.source_file is not None: self.VideoObject.mezz_filepath = os.path.join( self.workdir, self.source_file) self.VideoObject.activate() if not self.VideoObject.valid: logger.error('{id} : Invalid Video Data'.format( id=self.VideoObject.veda_id)) return if not os.path.exists(self.workdir): os.mkdir(self.workdir) logger.info('{id} | {encoding} : Ready for Encode'.format( id=self.VideoObject.veda_id, encoding=self.encode_profile)) # Pipeline Steps : # I. Intake # Ib. Validate Mezz # II. change status in APIs # III. Generate Encode Command # IV. Execute Encodes # IVa. Validate Products # (*)V. Deliver Encodes (sftp and others?), retrieve URLs # (*)VI. Change Status in APIs, add URLs # VII. Clean Directory self._engine_intake() if not self.VideoObject.valid: logger.error('Invalid Video / Local') return if self.VideoObject.val_id is not None: self._update_api() # generate video images command and update S3 and edxval # run against 'hls' encode only if self.encode_profile == 'hls': # Run HLS encode self._hls_pipeline() # Auto-video Images VideoImages(video_object=self.VideoObject, work_dir=self.workdir, source_file=self.source_file, jobid=self.jobid, settings=self.settings).create_and_update() else: self._static_pipeline() logger.info('{id} | {encoding} : Encode Complete'.format( id=self.VideoObject.veda_id, encoding=self.encode_profile)) if self.endpoint_url is not None and self.VideoObject.veda_id is not None: # Integrate with main veda_id = self.veda_id encode_profile = self.encode_profile deliverable_route.apply_async( (veda_id, encode_profile), queue=self.settings['celery_deliver_queue']) logger.info( '{id} | {encoding} : encoded file queued for delivery'.format( id=self.VideoObject.veda_id, encoding=self.encode_profile)) # Clean up workdir if self.jobid is not None: shutil.rmtree(self.workdir)
This file tests the working of Video Worker. """ import os import unittest from ddt import ddt, data, unpack from boto.exception import S3ResponseError from mock import Mock, patch from video_worker import VideoWorker, logger as video_worker_logger, deliverable_route from video_worker.abstractions import Video from video_worker.global_vars import ENCODE_WORK_DIR from video_worker.utils import get_config worker_settings = get_config() @ddt class VideoWorkerTest(unittest.TestCase): """ Test class for Video Worker. """ def setUp(self): super(VideoWorkerTest, self).setUp() self.VW = VideoWorker(**{'workdir': '/dummy-work-dir'}) # Provide dummy values for Video Worker. self.VW.VideoObject = Video(veda_id='XXXXXXXX2016-V00TEST') self.VW.VideoObject.valid = True self.VW.output_file = 'dummy-outfile'
#! user/bin/env python """ Globals """ import os from os.path import expanduser from video_worker.utils import get_config, ROOT_DIR DEFAULT_ENCODE_WORK_DIR = os.path.join(ROOT_DIR, 'ENCODE_WORKDIR') WORKER_CONFIG = get_config() ENCODE_WORK_DIR = WORKER_CONFIG.get('ENCODE_WORK_DIR', DEFAULT_ENCODE_WORK_DIR) NODE_TRANSCODE_STATUS = 'Active Transcode' VAL_TRANSCODE_STATUS = 'transcode_active' # Initially set to 16:9, can be changed # We can also just ignore this, # and push through video at original res/ar # but you probably shouldn't ## ENFORCE_TARGET_ASPECT = True TARGET_ASPECT_RATIO = float(1920) / float(1080) # The subbed out profile for HLS HLS_SUBSTITUTE = 'mobile_low' # For BOTO Multipart uploader MULTI_UPLOAD_BARRIER = 2000000000 BOTO_TIMEOUT = '60'