Commit 9a0ac493 by Qubad786

Fix tests after rebase

parent 4fe4ddf5
...@@ -5,6 +5,7 @@ Transcript tests ...@@ -5,6 +5,7 @@ Transcript tests
import json import json
import responses import responses
import urllib import urllib
import urlparse
from boto.exception import S3ResponseError from boto.exception import S3ResponseError
from boto.s3.connection import S3Connection from boto.s3.connection import S3Connection
...@@ -368,7 +369,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -368,7 +369,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
Creates an s3 bucket. That is happening in moto's virtual environment. Creates an s3 bucket. That is happening in moto's virtual environment.
""" """
connection = S3Connection() connection = S3Connection()
connection.create_bucket(CONFIG_DATA['transcript_bucket_name']) connection.create_bucket(CONFIG_DATA['aws_video_transcripts_bucket'])
return connection return connection
def invoke_3play_callback(self, state='complete'): def invoke_3play_callback(self, state='complete'):
...@@ -387,7 +388,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -387,7 +388,7 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
) )
return response return response
def assert_request(self, received_request, expected_request): def assert_request(self, received_request, expected_request, decode_func):
""" """
Verify that `received_request` matches `expected_request` Verify that `received_request` matches `expected_request`
""" """
...@@ -397,6 +398,11 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -397,6 +398,11 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
actual_headers = getattr(received_request, request_attr) actual_headers = getattr(received_request, request_attr)
for attr, expect_value in expected_headers.iteritems(): for attr, expect_value in expected_headers.iteritems():
self.assertEqual(actual_headers[attr], expect_value) self.assertEqual(actual_headers[attr], expect_value)
elif request_attr == 'body' and decode_func:
expected_body = expected_request[request_attr]
actual_body = decode_func(getattr(received_request, request_attr))
for attr, expect_value in expected_body.iteritems():
self.assertEqual(actual_body[attr], expect_value)
else: else:
self.assertEqual(getattr(received_request, request_attr), expected_request[request_attr]) self.assertEqual(getattr(received_request, request_attr), expected_request[request_attr])
...@@ -404,9 +410,9 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -404,9 +410,9 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
""" """
Verify sjson data uploaded to s3 Verify sjson data uploaded to s3
""" """
key = Key(connection.get_bucket(CONFIG_DATA['transcript_bucket_name'])) key = Key(connection.get_bucket(CONFIG_DATA['aws_video_transcripts_bucket']))
key.key = '{directory}{uuid}.sjson'.format( key.key = '{directory}{uuid}.sjson'.format(
directory=CONFIG_DATA['transcript_bucket_directory'], uuid=self.uuid_hex directory=CONFIG_DATA['aws_video_transcripts_prefix'], uuid=self.uuid_hex
) )
sjson_transcript = json.loads(key.get_contents_as_string()) sjson_transcript = json.loads(key.get_contents_as_string())
self.assertEqual(sjson_transcript, TRANSCRIPT_SJSON_DATA) self.assertEqual(sjson_transcript, TRANSCRIPT_SJSON_DATA)
...@@ -531,47 +537,54 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -531,47 +537,54 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
# request - 2 # request - 2
{ {
'url': CONFIG_DATA['val_token_url'], 'url': CONFIG_DATA['val_token_url'],
'body': urllib.urlencode({ 'body': {
'grant_type': 'password', 'grant_type': ['password'],
'client_id': CONFIG_DATA['val_client_id'], 'client_id': [CONFIG_DATA['val_client_id']],
'client_secret': CONFIG_DATA['val_secret_key'], 'client_secret': [CONFIG_DATA['val_secret_key']],
'username': CONFIG_DATA['val_username'], 'username': [CONFIG_DATA['val_username']],
'password': CONFIG_DATA['val_password'], 'password': [CONFIG_DATA['val_password']],
}) },
'decode_func': urlparse.parse_qs,
}, },
# request - 3 # request - 3
{ {
'url': CONFIG_DATA['val_transcript_create_url'], 'url': CONFIG_DATA['val_transcript_create_url'],
'body': json.dumps({ 'body': {
'transcript_format': transcripts.TRANSCRIPT_SJSON, 'file_format': transcripts.TRANSCRIPT_SJSON,
'video_id': self.video.studio_id, 'video_id': self.video.studio_id,
'language': 'en', 'language_code': 'en',
'transcript_url': '{directory}{uuid}.sjson'.format( 'name': '{directory}{uuid}.sjson'.format(
directory=CONFIG_DATA['transcript_bucket_directory'], uuid=self.uuid_hex directory=CONFIG_DATA['aws_video_transcripts_prefix'], uuid=self.uuid_hex
), ),
'provider': TranscriptProvider.THREE_PLAY 'provider': TranscriptProvider.THREE_PLAY
}), },
'headers': { 'headers': {
'Authorization': 'Bearer 1234567890', 'Authorization': 'Bearer 1234567890',
'content-type': 'application/json' 'content-type': 'application/json'
} },
'decode_func': json.loads,
}, },
# request - 4 # request - 4
{ {
'url': CONFIG_DATA['val_video_transcript_status_url'], 'url': CONFIG_DATA['val_video_transcript_status_url'],
'body': json.dumps({ 'body': {
'status': transcripts.VideoStatus.TRANSCRIPTION_READY, 'status': transcripts.VideoStatus.TRANSCRIPTION_READY,
'edx_video_id': self.video.studio_id 'edx_video_id': self.video.studio_id
}), },
'headers': { 'headers': {
'Authorization': 'Bearer 1234567890', 'Authorization': 'Bearer 1234567890',
'content-type': 'application/json' 'content-type': 'application/json'
} },
'decode_func': json.loads,
} }
] ]
for position, expected_request in enumerate(expected_requests): for position, expected_request in enumerate(expected_requests):
self.assert_request(responses.calls[position].request, expected_request) self.assert_request(
responses.calls[position].request,
expected_request,
expected_request.pop('decode_func', None)
)
# verify transcript sjson data uploaded to s3 # verify transcript sjson data uploaded to s3
self.assert_uploaded_transcript_on_s3(connection=conn) self.assert_uploaded_transcript_on_s3(connection=conn)
...@@ -683,30 +696,32 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -683,30 +696,32 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
# request - 2 # request - 2
{ {
'url': CONFIG_DATA['val_token_url'], 'url': CONFIG_DATA['val_token_url'],
'body': urllib.urlencode({ 'body': {
'grant_type': 'password', 'grant_type': ['password'],
'client_id': CONFIG_DATA['val_client_id'], 'client_id': [CONFIG_DATA['val_client_id']],
'client_secret': CONFIG_DATA['val_secret_key'], 'client_secret': [CONFIG_DATA['val_secret_key']],
'username': CONFIG_DATA['val_username'], 'username': [CONFIG_DATA['val_username']],
'password': CONFIG_DATA['val_password'], 'password': [CONFIG_DATA['val_password']],
}) },
'decode_func': urlparse.parse_qs,
}, },
# request - 3 # request - 3
{ {
'url': CONFIG_DATA['val_transcript_create_url'], 'url': CONFIG_DATA['val_transcript_create_url'],
'body': json.dumps({ 'body': {
'transcript_format': transcripts.TRANSCRIPT_SJSON, 'file_format': transcripts.TRANSCRIPT_SJSON,
'video_id': self.video.studio_id, 'video_id': self.video.studio_id,
'language': 'en', 'language_code': 'en',
'transcript_url': '{directory}{uuid}.sjson'.format( 'name': '{directory}{uuid}.sjson'.format(
directory=CONFIG_DATA['transcript_bucket_directory'], uuid=self.uuid_hex directory=CONFIG_DATA['aws_video_transcripts_prefix'], uuid=self.uuid_hex
), ),
'provider': TranscriptProvider.THREE_PLAY 'provider': TranscriptProvider.THREE_PLAY
}), },
'headers': { 'headers': {
'Authorization': 'Bearer 1234567890', 'Authorization': 'Bearer 1234567890',
'content-type': 'application/json' 'content-type': 'application/json'
} },
'decode_func': json.loads,
}, },
# request - 4 # request - 4
{ {
...@@ -718,16 +733,21 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -718,16 +733,21 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
# request - 5 # request - 5
{ {
'url': transcripts.THREE_PLAY_ORDER_TRANSLATION_URL.format(file_id=self.file_id), 'url': transcripts.THREE_PLAY_ORDER_TRANSLATION_URL.format(file_id=self.file_id),
'body': json.dumps({ 'body': {
'apikey': self.transcript_prefs.api_key, 'apikey': self.transcript_prefs.api_key,
'api_secret_key': self.transcript_prefs.api_secret, 'api_secret_key': self.transcript_prefs.api_secret,
'translation_service_id': 30, 'translation_service_id': 30,
}) },
'decode_func': json.loads,
}, },
] ]
for position, expected_request in enumerate(expected_requests): for position, expected_request in enumerate(expected_requests):
self.assert_request(responses.calls[position].request, expected_request) self.assert_request(
responses.calls[position].request,
expected_request,
expected_request.pop('decode_func', None),
)
# verify sjson data uploaded to s3 # verify sjson data uploaded to s3
self.assert_uploaded_transcript_on_s3(connection=conn) self.assert_uploaded_transcript_on_s3(connection=conn)
...@@ -1114,34 +1134,40 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -1114,34 +1134,40 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
# request - 3 # request - 3
{ {
'url': CONFIG_DATA['val_token_url'], 'url': CONFIG_DATA['val_token_url'],
'body': urllib.urlencode({ 'body': {
'grant_type': 'password', 'grant_type': ['password'],
'client_id': CONFIG_DATA['val_client_id'], 'client_id': [CONFIG_DATA['val_client_id']],
'client_secret': CONFIG_DATA['val_secret_key'], 'client_secret': [CONFIG_DATA['val_secret_key']],
'username': CONFIG_DATA['val_username'], 'username': [CONFIG_DATA['val_username']],
'password': CONFIG_DATA['val_password'], 'password': [CONFIG_DATA['val_password']],
}) },
'decode_func': urlparse.parse_qs,
}, },
# request - 4 # request - 4
{ {
'url': CONFIG_DATA['val_transcript_create_url'], 'url': CONFIG_DATA['val_transcript_create_url'],
'body': json.dumps({ 'body': {
'transcript_format': transcripts.TRANSCRIPT_SJSON, 'file_format': transcripts.TRANSCRIPT_SJSON,
'video_id': self.video.studio_id, 'video_id': self.video.studio_id,
'language': lang_code, 'language_code': lang_code,
'transcript_url': '{directory}{uuid}.sjson'.format( 'name': '{directory}{uuid}.sjson'.format(
directory=CONFIG_DATA['transcript_bucket_directory'], uuid=self.uuid_hex directory=CONFIG_DATA['aws_video_transcripts_prefix'], uuid=self.uuid_hex
), ),
'provider': TranscriptProvider.THREE_PLAY 'provider': TranscriptProvider.THREE_PLAY
}), },
'headers': { 'headers': {
'Authorization': 'Bearer 1234567890', 'Authorization': 'Bearer 1234567890',
'content-type': 'application/json' 'content-type': 'application/json'
} },
'decode_func': json.loads,
} }
] ]
for expected_request in expected_requests: for expected_request in expected_requests:
self.assert_request(responses.calls[position].request, expected_request) self.assert_request(
responses.calls[position].request,
expected_request,
expected_request.pop('decode_func', None),
)
position += 1 position += 1
# Asserts the transcript sjson data uploaded to s3 # Asserts the transcript sjson data uploaded to s3
...@@ -1162,16 +1188,20 @@ class ThreePlayTranscriptionCallbackTest(APITestCase): ...@@ -1162,16 +1188,20 @@ class ThreePlayTranscriptionCallbackTest(APITestCase):
# upon receiving all the translations # upon receiving all the translations
expected_video_status_update_request = { expected_video_status_update_request = {
'url': CONFIG_DATA['val_video_transcript_status_url'], 'url': CONFIG_DATA['val_video_transcript_status_url'],
'body': json.dumps({ 'body': {
'status': transcripts.VideoStatus.TRANSCRIPTION_READY, 'status': transcripts.VideoStatus.TRANSCRIPTION_READY,
'edx_video_id': self.video.studio_id 'edx_video_id': self.video.studio_id
}), },
'headers': { 'headers': {
'Authorization': 'Bearer 1234567890', 'Authorization': 'Bearer 1234567890',
'content-type': 'application/json' 'content-type': 'application/json'
} }
} }
self.assert_request(responses.calls[position].request, expected_video_status_update_request) self.assert_request(
responses.calls[position].request,
expected_video_status_update_request,
decode_func=json.loads,
)
@data( @data(
......
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