Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
bf190287
Commit
bf190287
authored
Dec 19, 2017
by
Mushtaq Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add python tests
parent
333842a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
3 deletions
+96
-3
cms/djangoapps/contentstore/views/tests/test_videos.py
+94
-2
cms/djangoapps/contentstore/views/videos.py
+2
-1
No files found.
cms/djangoapps/contentstore/views/tests/test_videos.py
View file @
bf190287
...
...
@@ -15,7 +15,13 @@ import pytz
from
django.conf
import
settings
from
django.core.files.uploadedfile
import
UploadedFile
from
django.test.utils
import
override_settings
from
edxval.api
import
create_profile
,
create_video
,
get_video_info
,
get_course_video_image_url
from
edxval.api
import
(
create_profile
,
create_video
,
get_video_info
,
get_course_video_image_url
,
create_or_update_video_transcript
)
from
mock
import
Mock
,
patch
from
contentstore.models
import
VideoUploadConfig
...
...
@@ -26,7 +32,8 @@ from contentstore.views.videos import (
validate_video_image
,
VIDEO_IMAGE_UPLOAD_ENABLED
,
WAFFLE_SWITCHES
,
TranscriptProvider
TranscriptProvider
,
get_all_transcript_languages
)
from
contentstore.views.videos
import
KEY_EXPIRATION_IN_SECONDS
,
StatusDisplayStrings
,
convert_video_status
from
xmodule.modulestore.tests.factories
import
CourseFactory
...
...
@@ -228,6 +235,85 @@ class VideosHandlerTestCase(VideoUploadTestMixin, CourseTestCase):
convert_video_status
(
original_video
)
)
@ddt.data
(
True
,
False
)
@patch
(
'openedx.core.djangoapps.video_config.models.VideoTranscriptEnabledFlag.feature_enabled'
)
def
test_get_json_transcripts
(
self
,
is_video_transcript_enabled
,
video_transcript_feature
):
"""
Test that transcripts are attached based on video transcript feature enablement.
"""
video_transcript_feature
.
return_value
=
is_video_transcript_enabled
response
=
self
.
client
.
get_json
(
self
.
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_videos
=
json
.
loads
(
response
.
content
)[
'videos'
]
self
.
assertEqual
(
len
(
response_videos
),
len
(
self
.
previous_uploads
))
expected_keys
=
[
'edx_video_id'
,
'client_video_id'
,
'created'
,
'duration'
,
'status'
,
'course_video_image_url'
]
if
is_video_transcript_enabled
:
expected_keys
+=
[
'transcripts'
]
for
response_video
in
response_videos
:
self
.
assertEqual
(
set
(
response_video
.
keys
()),
set
(
expected_keys
))
@ddt.data
(
([],
{}),
(
[
{
'video_id'
:
'test1'
,
'language_code'
:
'en'
,
'file_name'
:
'edx101.srt'
,
'file_format'
:
'srt'
,
'provider'
:
'Cielo24'
}
],
{
'en'
:
'English'
}
),
(
[
{
'video_id'
:
'test1'
,
'language_code'
:
'en'
,
'file_name'
:
'edx101_en.srt'
,
'file_format'
:
'srt'
,
'provider'
:
'Cielo24'
},
{
'video_id'
:
'test1'
,
'language_code'
:
'es'
,
'file_name'
:
'edx101_es.srt'
,
'file_format'
:
'srt'
,
'provider'
:
'Cielo24'
}
],
{
'en'
:
'English'
,
'es'
:
'Spanish'
}
)
)
@ddt.unpack
@patch
(
'openedx.core.djangoapps.video_config.models.VideoTranscriptEnabledFlag.feature_enabled'
)
def
test_get_transcripts
(
self
,
transcripts_data
,
expected_transcripts
,
video_transcript_feature
):
"""
Test that transcripts are attached based on video transcript feature enablement.
"""
is_video_transcript_enabled
=
True
video_transcript_feature
.
return_value
=
is_video_transcript_enabled
for
transcript_data
in
transcripts_data
:
create_or_update_video_transcript
(
**
transcript_data
)
response
=
self
.
client
.
get_json
(
self
.
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response_videos
=
json
.
loads
(
response
.
content
)[
'videos'
]
all_languages
=
get_all_transcript_languages
(
is_video_transcript_enabled
)
for
response_video
in
response_videos
:
if
response_video
[
'edx_video_id'
]
==
self
.
previous_uploads
[
0
][
'edx_video_id'
]:
self
.
assertDictEqual
(
response_video
[
'transcripts'
],
expected_transcripts
)
def
test_get_html
(
self
):
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
...
...
@@ -569,6 +655,12 @@ class VideosHandlerTestCase(VideoUploadTestMixin, CourseTestCase):
is_video_transcript_enabled
)
# Verify that transcripts column is present in the response if videos transcript feature is enabled.
self
.
assertEqual
(
'<div class="video-head-col video-col transcripts-col">Transcripts</div>'
in
response
.
content
,
is_video_transcript_enabled
)
@ddt.ddt
@patch.dict
(
'django.conf.settings.FEATURES'
,
{
'ENABLE_VIDEO_UPLOAD_PIPELINE'
:
True
})
...
...
cms/djangoapps/contentstore/views/videos.py
View file @
bf190287
...
...
@@ -528,6 +528,7 @@ def _get_videos(course):
Retrieves the list of videos from VAL corresponding to this course.
"""
is_video_transcript_enabled
=
VideoTranscriptEnabledFlag
.
feature_enabled
(
course
.
id
)
all_languages
=
get_all_transcript_languages
(
is_video_transcript_enabled
)
videos
=
list
(
get_videos_for_course
(
unicode
(
course
.
id
),
VideoSortField
.
created
,
SortDirection
.
desc
))
# convert VAL's status to studio's Video Upload feature status.
...
...
@@ -537,7 +538,7 @@ def _get_videos(course):
if
is_video_transcript_enabled
:
transcripts
=
{}
for
lang_code
in
get_available_transcript_languages
([
video
[
'edx_video_id'
]]):
transcripts
.
update
({
lang_code
:
get_all_transcript_languages
(
is_video_transcript_enabled
)
[
lang_code
]})
transcripts
.
update
({
lang_code
:
all_languages
[
lang_code
]})
video
[
'transcripts'
]
=
transcripts
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment