Commit 7d9e88af by Qubad786

improve code, fix tests, address feedback

parent 7ee3449d
...@@ -661,6 +661,17 @@ class TranscriptProcessMetadata(TimeStampedModel): ...@@ -661,6 +661,17 @@ class TranscriptProcessMetadata(TimeStampedModel):
verbose_name_plural = 'Transcript process metadata' verbose_name_plural = 'Transcript process metadata'
get_latest_by = 'modified' get_latest_by = 'modified'
def update(self, **fields):
"""
Updates a process.
Keyword Arguments:
fields(dict): dict containing all the fields to be updated.
"""
for attr, value in fields.iteritems():
setattr(self, attr, value)
self.save()
def __unicode__(self): def __unicode__(self):
return u'{video} - {provider} - {lang}'.format( return u'{video} - {provider} - {lang}'.format(
video=self.video.edx_id, video=self.video.edx_id,
......
...@@ -765,21 +765,22 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -765,21 +765,22 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
{'body': json.dumps({'iserror': True}), 'content_type': 'application/json', 'status': 200}, {'body': json.dumps({'iserror': True}), 'content_type': 'application/json', 'status': 200},
'error', 'error',
( (
'[3PlayMedia Task] Transcript fetch error for video=%s -- lang_code=%s -- process=%s -- response=%s', u'[%s] Transcript fetch error for video=%s -- lang_code=%s -- process=%s -- response=%s',
ANY, u'3PlayMedia Callback',
ANY, u'12345',
ANY, u'en',
ANY u'112233',
json.dumps({'iserror': True}),
), ),
), ),
( (
{'body': None, 'status': 400}, {'body': None, 'status': 400},
'exception', 'exception',
( (
'[3PlayMedia Callback] Fetch request failed for video=%s -- lang=%s -- process_id=%s', u'[3PlayMedia Callback] Fetch request failed for video=%s -- lang_code=%s -- process_id=%s',
ANY, u'12345',
ANY, u'en',
ANY, u'112233',
), ),
) )
) )
...@@ -870,10 +871,9 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -870,10 +871,9 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
{ {
'method': 'exception', 'method': 'exception',
'args': ( 'args': (
'[3PlayMedia Callback] Translation could not be performed - org=%s, edx_video_id=%s, ' '[3PlayMedia Callback] Translation could not be performed - video=%s, lang_code=%s, file_id=%s.',
'file_id=%s.',
'MAx',
'12345', '12345',
'en',
'112233' '112233'
) )
} }
...@@ -893,10 +893,9 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -893,10 +893,9 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
{ {
'method': 'exception', 'method': 'exception',
'args': ( 'args': (
'[3PlayMedia Callback] Translation could not be performed - org=%s, edx_video_id=%s, ' '[3PlayMedia Callback] Translation could not be performed - video=%s, lang_code=%s, file_id=%s.',
'file_id=%s.',
'MAx',
'12345', '12345',
'en',
'112233' '112233'
) )
} }
...@@ -1203,7 +1202,6 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -1203,7 +1202,6 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
decode_func=json.loads, decode_func=json.loads,
) )
@data( @data(
# not-an-ok response on translation status fetch request. # not-an-ok response on translation status fetch request.
( (
...@@ -1228,7 +1226,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -1228,7 +1226,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
400, 400,
) )
}, },
TranscriptStatus.IN_PROGRESS TranscriptStatus.FAILED
), ),
# 3Play Error response on fetching translations status. # 3Play Error response on fetching translations status.
( (
...@@ -1245,7 +1243,8 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -1245,7 +1243,8 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
{ {
'method': 'error', 'method': 'error',
'args': ( 'args': (
'[3PlayMedia Task] Translation error for video=%s -- lang_code=%s -- process_id=%s -- response=%s', '[3PlayMedia Task] unable to get translation status for '
'video=%s -- lang_code=%s -- process_id=%s -- response=%s',
VIDEO_DATA['studio_id'], VIDEO_DATA['studio_id'],
'ro', 'ro',
'112233', '112233',
...@@ -1268,7 +1267,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -1268,7 +1267,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
'status': 200, 'status': 200,
}, },
{ {
'mothod': responses.GET, 'method': responses.GET,
'url': transcripts.THREE_PLAY_TRANSLATION_DOWNLOAD_URL.format( 'url': transcripts.THREE_PLAY_TRANSLATION_DOWNLOAD_URL.format(
file_id='112233', translation_id='1q2w3e' file_id='112233', translation_id='1q2w3e'
), ),
...@@ -1302,7 +1301,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -1302,7 +1301,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
'status': 200, 'status': 200,
}, },
{ {
'mothod': responses.GET, 'method': responses.GET,
'url': transcripts.THREE_PLAY_TRANSLATION_DOWNLOAD_URL.format( 'url': transcripts.THREE_PLAY_TRANSLATION_DOWNLOAD_URL.format(
file_id='112233', translation_id='1q2w3e' file_id='112233', translation_id='1q2w3e'
), ),
...@@ -1314,7 +1313,8 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -1314,7 +1313,8 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
{ {
'method': 'error', 'method': 'error',
'args': ( 'args': (
'[3PlayMedia Task] Translation error for video=%s -- lang_code=%s -- process_id=%s -- response=%s', '[%s] Transcript fetch error for video=%s -- lang_code=%s -- process=%s -- response=%s',
'3PlayMedia Task',
VIDEO_DATA['studio_id'], VIDEO_DATA['studio_id'],
'ro', 'ro',
'112233', '112233',
...@@ -1328,7 +1328,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -1328,7 +1328,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
@responses.activate @responses.activate
@mock_s3_deprecated @mock_s3_deprecated
@patch('VEDA_OS01.transcripts.LOGGER') @patch('VEDA_OS01.transcripts.LOGGER')
def translations_retrieval_exceptions(self, mock_responses, expected_logging, transcript_status, mock_logger): def test_translations_retrieval_exceptions(self, mock_responses, expected_logging, transcript_status, mock_logger):
""" """
Tests possible error cases during translation fetch process form 3PlayMedia. Tests possible error cases during translation fetch process form 3PlayMedia.
""" """
......
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