Skip to content

Commit

Permalink
chore: update error msg for non_existant_edx_video_id
Browse files Browse the repository at this point in the history
  • Loading branch information
amirtds committed May 13, 2022
1 parent 5340bba commit d5c67cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
41 changes: 16 additions & 25 deletions cms/djangoapps/contentstore/views/tests/test_transcripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['DOC_STORE_CONFIG']['db'] = 'test_xcontent_%s' % uuid4().hex

SRT_TRANSCRIPT_CONTENT = "1\n00:00:00,030 --> 00:00:00,030\nHello world"
SRT_TRANSCRIPT_CONTENT = """0
00:00:00,260 --> 00:00:00,260
Hello, welcome to Open edX.
"""

SJSON_TRANSCRIPT_CONTENT = Transcript.convert(
SRT_TRANSCRIPT_CONTENT,
Expand Down Expand Up @@ -160,11 +164,11 @@ def setUp(self):
self.bom_srt_file = self.create_transcript_file(content=self.contents['good'], suffix='.srt', include_bom=True)
self.good_transcript_data = {
"transcript_srt":
"1\n00:00:00,030 --> 00:00:00,030\nHello world"
"0\n00:00:00,260 --> 00:00:00,260\nHello, welcome to Open edX."
}
self.bad_transcript_data = {
"srt":
"1\n00:00:00,030 --> 00:00:00,030\nHello world"
"0\n00:00:00,260 --> 00:00:00,260\nHello, welcome to Open edX."
}

# Setup a VEDA produced video and persist `edx_video_id` in VAL.
Expand Down Expand Up @@ -211,15 +215,14 @@ def upload_transcript(self, locator, transcript_data, edx_video_id=None):
Uploads a transcript for a video
"""
payload = {}
transcript_srt = transcript_data.get('transcript_srt', '')
if locator:
payload.update({'locator': locator})

if edx_video_id is not None:
payload.update({'edx_video_id': edx_video_id})

if transcript_data:
payload.update({'transcript-file': transcript_srt})
payload.update({'transcript-file': transcript_data})

upload_url = reverse('upload_transcripts')
response = self.client.post(upload_url, payload)
Expand Down Expand Up @@ -247,7 +250,7 @@ def test_transcript_upload_success(self, edx_video_id, include_bom):
modulestore().update_item(self.item, self.user.id)

# Upload a transcript
transcript_data = self.good_transcript_data
transcript_data = self.good_transcript_data["transcript_srt"]
response = self.upload_transcript(self.video_usage_key, transcript_data, '')

# Verify the response
Expand All @@ -273,7 +276,7 @@ def test_transcript_upload_without_locator(self):
"""
Test that transcript upload validation fails if the video locator is missing
"""
transcript_data = self.good_transcript_data
transcript_data = self.good_transcript_data["transcript_srt"]
response = self.upload_transcript(locator=None, transcript_data=transcript_data, edx_video_id='')
self.assert_response(
response,
Expand Down Expand Up @@ -304,7 +307,7 @@ def test_transcript_upload_bad_format(self):
self.assert_response(
response,
expected_status_code=400,
expected_message=u'Transcript data misses transcript_srt field.'
expected_message=u'There is a problem with this transcript file. Try to upload a different file.'
)

def test_transcript_upload_bad_content(self):
Expand All @@ -320,7 +323,7 @@ def test_transcript_upload_bad_content(self):
self.assert_response(
response,
expected_status_code=400,
expected_message=u'Transcript data misses transcript_srt field.'
expected_message=u'There is a problem with this transcript file. Try to upload a different file.'
)

def test_transcript_upload_unknown_category(self):
Expand All @@ -330,7 +333,7 @@ def test_transcript_upload_unknown_category(self):
# non_video module setup - i.e. an item whose category is not 'video'.
usage_key = self.create_non_video_module()
# Request to upload transcript for the item
transcript_data = self.good_transcript_data
transcript_data = self.good_transcript_data["transcript_srt"]
response = self.upload_transcript(locator=usage_key, transcript_data=transcript_data, edx_video_id='')
self.assert_response(
response,
Expand All @@ -343,7 +346,7 @@ def test_transcript_upload_non_existent_item(self):
Test that transcript upload validation fails in case of invalid item's locator.
"""
# Request to upload transcript for the item
transcript_data = self.good_transcript_data
transcript_data = self.good_transcript_data["transcript_srt"]
response = self.upload_transcript(
locator='non_existent_locator',
transcript_data=transcript_data,
Expand All @@ -355,25 +358,13 @@ def test_transcript_upload_non_existent_item(self):
expected_message=u'Cannot find item by locator.'
)

def test_transcript_upload_without_edx_video_id(self):
"""
Test that transcript upload validation fails if the `edx_video_id` is missing
"""
transcript_data = self.good_transcript_data
response = self.upload_transcript(locator=self.video_usage_key, transcript_data=transcript_data)
self.assert_response(
response,
expected_status_code=400,
expected_message=u'There is a problem with this transcript file. Try to upload a different file.'
)

def test_transcript_upload_with_non_existant_edx_video_id(self):
"""
Test that transcript upload works as expected if `edx_video_id` set on
video descriptor is different from `edx_video_id` received in POST request.
"""
non_existant_edx_video_id = '1111-2222-3333-4444'
transcript_data = self.good_transcript_data
transcript_data = self.good_transcript_data["transcript_srt"]
# Upload with non-existant `edx_video_id`
response = self.upload_transcript(
locator=self.video_usage_key,
Expand All @@ -383,7 +374,7 @@ def test_transcript_upload_with_non_existant_edx_video_id(self):
# Verify the response
self.assert_response(
response, expected_status_code=400,
expected_message='There is a problem with this transcript file. Try to upload a different file.'
expected_message="edx_video_id doesn't exist."
)

# Verify transcript does not exist for non-existant `edx_video_id`
Expand Down
2 changes: 0 additions & 2 deletions cms/djangoapps/contentstore/views/transcripts_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ def validate_transcript_upload_data(request):
error = _("Video locator is required.")
elif "transcript-file" not in files and "transcript-file" not in data:
error = _("A transcript file is required.")
if "transcript-file" in data and "transcript_srt" not in data["transcript-file"]:
error = _("Transcript data misses transcript_srt field.")
if "edx_video_id" in data and data["edx_video_id"]:
try:
_get_video(data["edx_video_id"])
Expand Down

0 comments on commit d5c67cc

Please sign in to comment.