Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #98 from edx/fix-status-update
Browse files Browse the repository at this point in the history
fix status update
  • Loading branch information
muhammad-ammar authored Apr 4, 2018
2 parents dfc600d + 407f344 commit 05c4822
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
43 changes: 43 additions & 0 deletions control/tests/test_val.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
from django.test import TestCase
from ddt import data, ddt, unpack

from mock import PropertyMock, patch

Expand All @@ -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()
Expand All @@ -25,6 +27,7 @@
CONFIG_DATA = utils.get_config('test_config.yaml')


@ddt
class TestVALAPI(TestCase):

def setUp(self):
Expand Down Expand Up @@ -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)
26 changes: 24 additions & 2 deletions control/veda_val.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -29,6 +31,12 @@
'''

FILE_COMPLETE_STATUSES = (
'file_complete',
ValTranscriptStatus.TRANSCRIPT_READY,
ValTranscriptStatus.TRANSCRIPTION_IN_PROGRESS,
)


class VALAPICall(object):

Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 05c4822

Please sign in to comment.