Unverified Commit 05c4822d by Muhammad Ammar Committed by GitHub

Merge pull request #98 from edx/fix-status-update

fix status update
parents dfc600de 407f3442
...@@ -3,6 +3,7 @@ import ast ...@@ -3,6 +3,7 @@ import ast
import os import os
import sys import sys
from django.test import TestCase from django.test import TestCase
from ddt import data, ddt, unpack
from mock import PropertyMock, patch from mock import PropertyMock, patch
...@@ -12,6 +13,7 @@ import responses ...@@ -12,6 +13,7 @@ import responses
from control.veda_val import VALAPICall from control.veda_val import VALAPICall
from VEDA import utils from VEDA import utils
from control.veda_file_ingest import VideoProto from control.veda_file_ingest import VideoProto
from VEDA_OS01.utils import ValTranscriptStatus
requests.packages.urllib3.disable_warnings() requests.packages.urllib3.disable_warnings()
...@@ -25,6 +27,7 @@ sys.path.append(os.path.dirname(os.path.dirname(__file__))) ...@@ -25,6 +27,7 @@ sys.path.append(os.path.dirname(os.path.dirname(__file__)))
CONFIG_DATA = utils.get_config('test_config.yaml') CONFIG_DATA = utils.get_config('test_config.yaml')
@ddt
class TestVALAPI(TestCase): class TestVALAPI(TestCase):
def setUp(self): def setUp(self):
...@@ -73,3 +76,43 @@ class TestVALAPI(TestCase): ...@@ -73,3 +76,43 @@ class TestVALAPI(TestCase):
self.assertFalse(response.status_code == 404) self.assertFalse(response.status_code == 404)
self.assertFalse(response.status_code > 299) 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)
...@@ -11,6 +11,8 @@ import json ...@@ -11,6 +11,8 @@ import json
from control_env import * from control_env import *
from control.veda_utils import Output, VideoProto from control.veda_utils import Output, VideoProto
from VEDA_OS01.utils import ValTranscriptStatus
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
requests.packages.urllib3.disable_warnings() requests.packages.urllib3.disable_warnings()
...@@ -29,6 +31,12 @@ requests.packages.urllib3.disable_warnings() ...@@ -29,6 +31,12 @@ requests.packages.urllib3.disable_warnings()
''' '''
FILE_COMPLETE_STATUSES = (
'file_complete',
ValTranscriptStatus.TRANSCRIPT_READY,
ValTranscriptStatus.TRANSCRIPTION_IN_PROGRESS,
)
class VALAPICall(object): class VALAPICall(object):
...@@ -290,6 +298,20 @@ class VALAPICall(object): ...@@ -290,6 +298,20 @@ class VALAPICall(object):
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): def send_404(self):
""" """
Generate new VAL ID Generate new VAL ID
...@@ -298,7 +320,7 @@ class VALAPICall(object): ...@@ -298,7 +320,7 @@ class VALAPICall(object):
self.val_data['status'] = self.val_status 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 return None
sending_data = dict( sending_data = dict(
...@@ -341,7 +363,7 @@ class VALAPICall(object): ...@@ -341,7 +363,7 @@ class VALAPICall(object):
""" """
Make Request, finally 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 return None
r4 = requests.put( r4 = requests.put(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment