delete transcript from advance tab
EDUCATOR-1759
This commit is contained in:
@@ -20,19 +20,21 @@ from xmodule.exceptions import NotFoundError
|
||||
from xmodule.fields import RelativeTime
|
||||
from opaque_keys.edx.locator import CourseLocator
|
||||
|
||||
from edxval.api import create_or_update_video_transcript, create_external_video
|
||||
from edxval.api import create_or_update_video_transcript, create_external_video, delete_video_transcript
|
||||
from .transcripts_utils import (
|
||||
clean_video_id,
|
||||
get_or_create_sjson,
|
||||
generate_sjson_for_all_speeds,
|
||||
get_video_transcript_content,
|
||||
save_to_store,
|
||||
subs_filename,
|
||||
Transcript,
|
||||
TranscriptException,
|
||||
TranscriptsGenerationException,
|
||||
youtube_speed_dict,
|
||||
get_transcript,
|
||||
get_transcript_from_contentstore
|
||||
get_transcript_from_contentstore,
|
||||
remove_subs_from_store,
|
||||
get_html5_ids
|
||||
)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -488,6 +490,36 @@ class VideoStudioViewHandlers(object):
|
||||
},
|
||||
status=400
|
||||
)
|
||||
elif request.method == 'DELETE':
|
||||
request_data = request.json
|
||||
|
||||
if 'lang' not in request_data or 'edx_video_id' not in request_data:
|
||||
return Response(status=400)
|
||||
|
||||
language = request_data['lang']
|
||||
edx_video_id = clean_video_id(request_data['edx_video_id'])
|
||||
|
||||
if edx_video_id:
|
||||
delete_video_transcript(video_id=edx_video_id, language_code=language)
|
||||
|
||||
if language == u'en':
|
||||
# remove any transcript file from content store for the video ids
|
||||
possible_sub_ids = [
|
||||
self.sub, # pylint: disable=access-member-before-definition
|
||||
self.youtube_id_1_0
|
||||
] + get_html5_ids(self.html5_sources)
|
||||
for sub_id in possible_sub_ids:
|
||||
remove_subs_from_store(sub_id, self, language)
|
||||
|
||||
# update metadata as `en` can also be present in `transcripts` field
|
||||
remove_subs_from_store(self.transcripts.pop(language, None), self, language)
|
||||
|
||||
# also empty `sub` field
|
||||
self.sub = '' # pylint: disable=attribute-defined-outside-init
|
||||
else:
|
||||
remove_subs_from_store(self.transcripts.pop(language, None), self, language)
|
||||
|
||||
return Response(status=200)
|
||||
|
||||
elif request.method == 'GET':
|
||||
language = request.GET.get('language_code')
|
||||
|
||||
@@ -81,6 +81,11 @@ DEFAULT_SETTINGS = [
|
||||
['YouTube ID for 1.5x speed', '', False]
|
||||
]
|
||||
|
||||
# field names without clear button
|
||||
FIELDS_WO_CLEAR = [
|
||||
'Transcript Languages'
|
||||
]
|
||||
|
||||
|
||||
# We should wait 300 ms for event handler invocation + 200ms for safety.
|
||||
DELAY = 0.5
|
||||
@@ -346,15 +351,22 @@ class VideoComponentPage(VideoPage):
|
||||
"""
|
||||
Verify that video component has correct default settings.
|
||||
"""
|
||||
query = '.wrapper-comp-setting'
|
||||
settings = self.q(css=query).results
|
||||
if len(DEFAULT_SETTINGS) != len(settings):
|
||||
return False
|
||||
def _check_settings_length():
|
||||
"""Check video settings"""
|
||||
query = '.wrapper-comp-setting'
|
||||
settings = self.q(css=query).results
|
||||
if len(DEFAULT_SETTINGS) == len(settings):
|
||||
return True, settings
|
||||
return (False, None)
|
||||
|
||||
settings = Promise(_check_settings_length, 'All video fields are present').fulfill()
|
||||
|
||||
for counter, setting in enumerate(settings):
|
||||
is_verified = self._verify_setting_entry(setting,
|
||||
DEFAULT_SETTINGS[counter][0],
|
||||
DEFAULT_SETTINGS[counter][1])
|
||||
is_verified = self._verify_setting_entry(
|
||||
setting,
|
||||
DEFAULT_SETTINGS[counter][0],
|
||||
DEFAULT_SETTINGS[counter][1]
|
||||
)
|
||||
|
||||
if not is_verified:
|
||||
return is_verified
|
||||
@@ -395,9 +407,8 @@ class VideoComponentPage(VideoPage):
|
||||
if field_value != current_value:
|
||||
return False
|
||||
|
||||
# Clear button should be visible(active class is present) for
|
||||
# every setting that don't have 'metadata-videolist-enum' class
|
||||
if 'metadata-videolist-enum' not in setting.get_attribute('class'):
|
||||
# Verify if clear button is active for expected video fields
|
||||
if field_name not in FIELDS_WO_CLEAR and 'metadata-videolist-enum' not in setting.get_attribute('class'):
|
||||
setting_clear_button = setting.find_elements_by_class_name('setting-clear')[0]
|
||||
if 'active' not in setting_clear_button.get_attribute('class'):
|
||||
return False
|
||||
@@ -543,7 +554,9 @@ class VideoComponentPage(VideoPage):
|
||||
language_code (str): language code
|
||||
|
||||
"""
|
||||
self.q(css='.remove-action').filter(lambda el: language_code == el.get_attribute('data-lang')).click()
|
||||
selector = '.metadata-video-translations .list-settings-item'
|
||||
translation = self.q(css=selector).filter(lambda el: language_code == el.get_attribute('data-original-lang'))
|
||||
translation[0].find_element_by_class_name('remove-action').click()
|
||||
|
||||
@property
|
||||
def upload_status_message(self):
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
"""
|
||||
Acceptance tests for CMS Video Editor.
|
||||
"""
|
||||
import ddt
|
||||
from nose.plugins.attrib import attr
|
||||
|
||||
from common.test.acceptance.pages.common.utils import confirm_prompt
|
||||
from common.test.acceptance.tests.video.test_studio_video_module import CMSVideoBaseTest
|
||||
|
||||
|
||||
@attr(shard=6)
|
||||
@ddt.ddt
|
||||
class VideoEditorTest(CMSVideoBaseTest):
|
||||
"""
|
||||
CMS Video Editor Test Class
|
||||
@@ -263,6 +265,7 @@ class VideoEditorTest(CMSVideoBaseTest):
|
||||
self.open_advanced_tab()
|
||||
self.assertEqual(self.video.translations(), ['zh', 'uk'])
|
||||
self.video.remove_translation('uk')
|
||||
confirm_prompt(self.video)
|
||||
self.save_unit_settings()
|
||||
self.assertTrue(self.video.is_captions_visible())
|
||||
unicode_text = "好 各位同学".decode('utf-8')
|
||||
@@ -271,6 +274,7 @@ class VideoEditorTest(CMSVideoBaseTest):
|
||||
self.open_advanced_tab()
|
||||
self.assertEqual(self.video.translations(), ['zh'])
|
||||
self.video.remove_translation('zh')
|
||||
confirm_prompt(self.video)
|
||||
self.save_unit_settings()
|
||||
self.assertFalse(self.video.is_captions_visible())
|
||||
|
||||
@@ -292,9 +296,28 @@ class VideoEditorTest(CMSVideoBaseTest):
|
||||
self.video.upload_translation('uk_transcripts.srt', 'uk')
|
||||
self.assertEqual(self.video.translations(), ['uk'])
|
||||
self.video.remove_translation('uk')
|
||||
confirm_prompt(self.video)
|
||||
self.save_unit_settings()
|
||||
self.assertFalse(self.video.is_captions_visible())
|
||||
|
||||
def test_translations_entry_remove_works(self):
|
||||
"""
|
||||
Scenario: Translations entry removal works correctly when transcript is not uploaded
|
||||
Given I have created a Video component
|
||||
And I edit the component
|
||||
And I open tab "Advanced"
|
||||
And I click on "+ Add" button for "Transcript Languages" field
|
||||
Then I click on "Remove" button
|
||||
And I see newly created entry is removed
|
||||
"""
|
||||
self._create_video_component()
|
||||
self.edit_component()
|
||||
self.open_advanced_tab()
|
||||
self.video.click_button("translation_add")
|
||||
self.assertEqual(self.video.translations_count(), 1)
|
||||
self.video.remove_translation("")
|
||||
self.assertEqual(self.video.translations_count(), 0)
|
||||
|
||||
def test_cannot_upload_sjson_translation(self):
|
||||
"""
|
||||
Scenario: User cannot upload translations in sjson format
|
||||
@@ -394,6 +417,7 @@ class VideoEditorTest(CMSVideoBaseTest):
|
||||
self.video.upload_translation('chinese_transcripts.srt', 'zh')
|
||||
self.assertEqual(self.video.translations(), ['zh'])
|
||||
self.video.remove_translation('zh')
|
||||
confirm_prompt(self.video)
|
||||
self.video.upload_translation('uk_transcripts.srt', 'zh')
|
||||
self.save_unit_settings()
|
||||
self.assertTrue(self.video.is_captions_visible())
|
||||
|
||||
Reference in New Issue
Block a user