Commit ca2b84b0 by Qubad786 Committed by muzaffaryousaf

Add options={iwp_name: FINAL} to avoid multiple Cielo24 callbacks.

parent d5448f7c
...@@ -43,7 +43,7 @@ TRANSCRIPT_PREFERENCES = { ...@@ -43,7 +43,7 @@ TRANSCRIPT_PREFERENCES = {
'api_secret': 'i_am_secret', 'api_secret': 'i_am_secret',
} }
REQUEST_PARAMS = {'job_id': 100, 'lang_code': 'en', 'org': 'MAx', 'video_id': '111'} REQUEST_PARAMS = {'job_id': 100, 'iwp_name': 'FINAL', 'lang_code': 'en', 'org': 'MAx', 'video_id': '111'}
TRANSCRIPT_SRT_DATA = """ TRANSCRIPT_SRT_DATA = """
1 1
...@@ -154,15 +154,15 @@ class Cielo24TranscriptTests(APITestCase): ...@@ -154,15 +154,15 @@ class Cielo24TranscriptTests(APITestCase):
""" """
response = self.client.get( response = self.client.get(
url or self.url, url or self.url,
{'job_id': 3, 'lang_code': 'ar', 'org': 'edx', 'video_id': 12345} {'job_id': 3, 'iwp_name': 'FINAL', 'lang_code': 'ar', 'org': 'edx', 'video_id': 12345}
) )
self.assertEqual(response.status_code, status_code) self.assertEqual(response.status_code, status_code)
@data( @data(
({}, ['job_id', 'lang_code', 'org', 'video_id']), ({}, ['job_id', 'iwp_name', 'lang_code', 'org', 'video_id']),
({'job_id': 1}, ['lang_code', 'org', 'video_id']), ({'job_id': 1}, ['iwp_name', 'lang_code', 'org', 'video_id']),
({'job_id': 2, 'lang_code': 'en'}, ['org', 'video_id']), ({'job_id': 2, 'lang_code': 'en'}, ['iwp_name', 'org', 'video_id']),
({'job_id': 3, 'lang_code': 'ar', 'org': 'edx'}, ['video_id']), ({'job_id': 3, 'lang_code': 'ar', 'org': 'edx'}, ['iwp_name', 'video_id']),
) )
@unpack @unpack
@patch('VEDA_OS01.transcripts.LOGGER') @patch('VEDA_OS01.transcripts.LOGGER')
...@@ -195,9 +195,10 @@ class Cielo24TranscriptTests(APITestCase): ...@@ -195,9 +195,10 @@ class Cielo24TranscriptTests(APITestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
@patch('VEDA_OS01.transcripts.VALAPICall._AUTH', PropertyMock(return_value=lambda: CONFIG_DATA)) @patch('VEDA_OS01.transcripts.VALAPICall._AUTH', PropertyMock(return_value=lambda: CONFIG_DATA))
@patch('VEDA_OS01.transcripts.LOGGER')
@responses.activate @responses.activate
@mock_s3_deprecated @mock_s3_deprecated
def test_cielo24_callback(self): def test_cielo24_callback(self, mock_logger):
""" """
Verify that `cielo24_transcript_callback` method works as expected. Verify that `cielo24_transcript_callback` method works as expected.
""" """
...@@ -220,6 +221,16 @@ class Cielo24TranscriptTests(APITestCase): ...@@ -220,6 +221,16 @@ class Cielo24TranscriptTests(APITestCase):
transcripts.cielo24_transcript_callback(None, **REQUEST_PARAMS) transcripts.cielo24_transcript_callback(None, **REQUEST_PARAMS)
# Assert the logs.
mock_logger.info.assert_called_with(
'[CIELO24 TRANSCRIPTS] Transcript complete request received for '
'video=%s -- org=%s -- lang=%s -- job_id=%s -- iwp_name=%s',
REQUEST_PARAMS['video_id'],
REQUEST_PARAMS['org'],
REQUEST_PARAMS['lang_code'],
REQUEST_PARAMS['job_id'],
REQUEST_PARAMS['iwp_name']
)
# Total of 4 HTTP requests are made as registered above # Total of 4 HTTP requests are made as registered above
self.assertEqual(len(responses.calls), 4) self.assertEqual(len(responses.calls), 4)
......
...@@ -34,7 +34,9 @@ ERROR = 'error' ...@@ -34,7 +34,9 @@ ERROR = 'error'
# Transcript format # Transcript format
TRANSCRIPT_SJSON = 'sjson' TRANSCRIPT_SJSON = 'sjson'
CIELO24_TRANSCRIPT_COMPLETED = django.dispatch.Signal(providing_args=['job_id', 'lang_code', 'org', 'video_id']) CIELO24_TRANSCRIPT_COMPLETED = django.dispatch.Signal(providing_args=[
'job_id', 'iwp_name', 'lang_code', 'org', 'video_id'
])
CONFIG = utils.get_config() CONFIG = utils.get_config()
# Cielo24 API URLs # Cielo24 API URLs
...@@ -129,7 +131,7 @@ class Cielo24CallbackHandlerView(APIView): ...@@ -129,7 +131,7 @@ class Cielo24CallbackHandlerView(APIView):
""" """
Handle Cielo24 callback request. Handle Cielo24 callback request.
""" """
required_attrs = ('job_id', 'lang_code', 'org', 'video_id') required_attrs = ('job_id', 'iwp_name', 'lang_code', 'org', 'video_id')
missing = [attr for attr in required_attrs if attr not in request.query_params.keys()] missing = [attr for attr in required_attrs if attr not in request.query_params.keys()]
if missing: if missing:
LOGGER.warning( LOGGER.warning(
...@@ -142,6 +144,7 @@ class Cielo24CallbackHandlerView(APIView): ...@@ -142,6 +144,7 @@ class Cielo24CallbackHandlerView(APIView):
sender=self, sender=self,
org=request.query_params['org'], org=request.query_params['org'],
job_id=request.query_params['job_id'], job_id=request.query_params['job_id'],
iwp_name=request.query_params['iwp_name'],
video_id=request.query_params['video_id'], video_id=request.query_params['video_id'],
lang_code=request.query_params['lang_code'], lang_code=request.query_params['lang_code'],
) )
...@@ -162,14 +165,17 @@ def cielo24_transcript_callback(sender, **kwargs): ...@@ -162,14 +165,17 @@ def cielo24_transcript_callback(sender, **kwargs):
org = kwargs['org'] org = kwargs['org']
job_id = kwargs['job_id'] job_id = kwargs['job_id']
video_id = kwargs['video_id'] video_id = kwargs['video_id']
iwp_name = kwargs['iwp_name']
lang_code = kwargs['lang_code'] lang_code = kwargs['lang_code']
LOGGER.info( LOGGER.info(
'[CIELO24 TRANSCRIPTS] Transcript complete request received for video=%s -- org=%s -- lang=%s -- job_id=%s', '[CIELO24 TRANSCRIPTS] Transcript complete request received for '
'video=%s -- org=%s -- lang=%s -- job_id=%s -- iwp_name=%s',
video_id, video_id,
org, org,
lang_code, lang_code,
job_id job_id,
iwp_name
) )
# get transcript credentials for an organization # get transcript credentials for an organization
......
...@@ -149,11 +149,13 @@ class Cielo24TranscriptTests(TestCase): ...@@ -149,11 +149,13 @@ class Cielo24TranscriptTests(TestCase):
lang_code='TARGET_LANG', lang_code='TARGET_LANG',
video_id='12345', video_id='12345',
job_id='000-111-222', job_id='000-111-222',
iwp_name='{iwp_name}',
org='MAx', org='MAx',
), ),
api_token='cielo24_api_key', api_token='cielo24_api_key',
priority='PRIORITY', priority='PRIORITY',
transcription_fidelity='PROFESSIONAL', transcription_fidelity='PROFESSIONAL',
options='{"return_iwp": ["FINAL"]}'
), ),
'body': None, 'body': None,
'method': 'GET' 'method': 'GET'
......
...@@ -3,7 +3,7 @@ Cielo24 Integration ...@@ -3,7 +3,7 @@ Cielo24 Integration
""" """
import ast import ast
import logging import logging
import urllib import json
import requests import requests
from requests.packages.urllib3.exceptions import InsecurePlatformWarning from requests.packages.urllib3.exceptions import InsecurePlatformWarning
...@@ -119,6 +119,7 @@ class Cielo24Transcript(object): ...@@ -119,6 +119,7 @@ class Cielo24Transcript(object):
callback_url = build_url( callback_url = build_url(
self.callback_base_url, self.callback_base_url,
job_id=job_id, job_id=job_id,
iwp_name='{iwp_name}',
lang_code=lang_code, lang_code=lang_code,
org=self.org, org=self.org,
video_id=self.video.studio_id video_id=self.video.studio_id
...@@ -135,6 +136,7 @@ class Cielo24Transcript(object): ...@@ -135,6 +136,7 @@ class Cielo24Transcript(object):
api_token=self.api_key, api_token=self.api_key,
priority=self.turnaround, priority=self.turnaround,
transcription_fidelity=self.fidelity, transcription_fidelity=self.fidelity,
options=json.dumps({"return_iwp": ["FINAL"]})
) )
) )
......
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