From 407f34426b7e35942b6fcf23103c8df5c3bd0cee Mon Sep 17 00:00:00 2001 From: muhammad-ammar Date: Wed, 4 Apr 2018 16:04:41 +0500 Subject: [PATCH] fix status update EDUCATOR-2609 --- control/tests/test_val.py | 43 +++++++++++++++++++++++++++++++++++++++ control/veda_val.py | 26 +++++++++++++++++++++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/control/tests/test_val.py b/control/tests/test_val.py index 5cbc80c..84c1959 100644 --- a/control/tests/test_val.py +++ b/control/tests/test_val.py @@ -3,6 +3,7 @@ import os import sys from django.test import TestCase +from ddt import data, ddt, unpack from mock import PropertyMock, patch @@ -12,6 +13,7 @@ from control.veda_val import VALAPICall from VEDA import utils from control.veda_file_ingest import VideoProto +from VEDA_OS01.utils import ValTranscriptStatus requests.packages.urllib3.disable_warnings() @@ -25,6 +27,7 @@ CONFIG_DATA = utils.get_config('test_config.yaml') +@ddt class TestVALAPI(TestCase): def setUp(self): @@ -73,3 +76,43 @@ def test_val_connection(self): self.assertFalse(response.status_code == 404) self.assertFalse(response.status_code > 299) + + @data( + { + 'encode_list': [], + 'val_status': 'file_complete', + 'expected_response': False + }, + { + 'encode_list': [], + 'val_status': ValTranscriptStatus.TRANSCRIPT_READY, + 'expected_response': False + }, + { + 'encode_list': [], + 'val_status': ValTranscriptStatus.TRANSCRIPTION_IN_PROGRESS, + 'expected_response': False + }, + { + 'encode_list': ['abc.mp4'], + 'val_status': 'file_complete', + 'expected_response': True + }, + { + 'encode_list': ['abc.mp4'], + 'val_status': ValTranscriptStatus.TRANSCRIPT_READY, + 'expected_response': True + }, + { + 'encode_list': ['abc.mp4'], + 'val_status': ValTranscriptStatus.TRANSCRIPTION_IN_PROGRESS, + 'expected_response': True + }, + ) + @unpack + def test_val_should_update_status(self, encode_list, val_status, expected_response): + """ + Verify that `should_update_status` works as expected. + """ + response = self.VAC.should_update_status(encode_list, val_status) + self.assertEqual(response, expected_response) diff --git a/control/veda_val.py b/control/veda_val.py index 4cb5114..fd44833 100644 --- a/control/veda_val.py +++ b/control/veda_val.py @@ -11,6 +11,8 @@ from control_env import * from control.veda_utils import Output, VideoProto +from VEDA_OS01.utils import ValTranscriptStatus + LOGGER = logging.getLogger(__name__) requests.packages.urllib3.disable_warnings() @@ -29,6 +31,12 @@ ''' +FILE_COMPLETE_STATUSES = ( + 'file_complete', + ValTranscriptStatus.TRANSCRIPT_READY, + ValTranscriptStatus.TRANSCRIPTION_IN_PROGRESS, +) + class VALAPICall(object): @@ -290,6 +298,20 @@ def profile_determiner(self, val_api_return): return + @staticmethod + def should_update_status(encode_list, val_status): + """ + Check if we need to update video status in val + + Arguments: + encode_list (list): list of video encodes + val_status (unicode): val status + """ + if len(encode_list) == 0 and val_status in FILE_COMPLETE_STATUSES: + return False + + return True + def send_404(self): """ Generate new VAL ID @@ -298,7 +320,7 @@ def send_404(self): self.val_data['status'] = self.val_status - if len(self.encode_data) == 0 and self.val_status is 'file_complete': + if self.should_update_status(self.encode_data, self.val_status) is False: return None sending_data = dict( @@ -341,7 +363,7 @@ def send_200(self, val_api_return): """ Make Request, finally """ - if len(self.encode_data) == 0 and self.val_status is 'file_complete': + if self.should_update_status(self.encode_data, self.val_status) is False: return None r4 = requests.put(