Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-val
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-val
Commits
1872d8e6
Commit
1872d8e6
authored
Dec 22, 2016
by
muhammad-ammar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update video status
TNL-4777
parent
4d4c631a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
2 deletions
+83
-2
edxval/api.py
+24
-0
edxval/models.py
+17
-0
edxval/tests/test_api.py
+39
-0
edxval/tests/test_serializers.py
+2
-1
setup.py
+1
-1
No files found.
edxval/api.py
View file @
1872d8e6
...
@@ -158,6 +158,30 @@ def update_video(video_data):
...
@@ -158,6 +158,30 @@ def update_video(video_data):
raise
ValCannotUpdateError
(
serializer
.
errors
)
raise
ValCannotUpdateError
(
serializer
.
errors
)
def
update_video_status
(
edx_video_id
,
status
):
"""
Update status for an existing video.
Args:
edx_video_id: ID of the video
status: video status
Raises:
Raises ValVideoNotFoundError if the video cannot be retrieved.
"""
try
:
video
=
_get_video
(
edx_video_id
)
except
Video
.
DoesNotExist
:
error_message
=
u"Video not found when trying to update video status with edx_video_id: {0}"
.
format
(
edx_video_id
)
raise
ValVideoNotFoundError
(
error_message
)
video
.
status
=
status
video
.
save
()
def
create_profile
(
profile_name
):
def
create_profile
(
profile_name
):
"""
"""
Used to create Profile objects in the database
Used to create Profile objects in the database
...
...
edxval/models.py
View file @
1872d8e6
...
@@ -11,10 +11,14 @@ themselves. After these are resolved, errors such as a negative file_size or
...
@@ -11,10 +11,14 @@ themselves. After these are resolved, errors such as a negative file_size or
invalid profile_name will be returned.
invalid profile_name will be returned.
"""
"""
import
logging
from
django.db
import
models
from
django.db
import
models
from
django.dispatch
import
receiver
from
django.core.validators
import
MinValueValidator
,
RegexValidator
from
django.core.validators
import
MinValueValidator
,
RegexValidator
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
logger
=
logging
.
getLogger
(
__name__
)
# pylint: disable=C0103
URL_REGEX
=
r'^[a-zA-Z0-9\-_]*$'
URL_REGEX
=
r'^[a-zA-Z0-9\-_]*$'
...
@@ -190,3 +194,16 @@ class Subtitle(models.Model):
...
@@ -190,3 +194,16 @@ class Subtitle(models.Model):
return
'application/json'
return
'application/json'
else
:
else
:
return
'text/plain'
return
'text/plain'
@receiver
(
models
.
signals
.
post_save
,
sender
=
Video
)
def
video_status_update_callback
(
sender
,
**
kwargs
):
# pylint: disable=unused-argument
"""
Log video status for an existing video instance
"""
video
=
kwargs
[
'instance'
]
if
kwargs
[
'created'
]:
logger
.
info
(
'VAL: Video created with id [
%
s] and status [
%
s]'
,
video
.
edx_video_id
,
video
.
status
)
else
:
logger
.
info
(
'VAL: Status changed to [
%
s] for video [
%
s]'
,
video
.
status
,
video
.
edx_video_id
)
edxval/tests/test_api.py
View file @
1872d8e6
...
@@ -4,6 +4,7 @@ Tests for the API for Video Abstraction Layer
...
@@ -4,6 +4,7 @@ Tests for the API for Video Abstraction Layer
"""
"""
import
mock
import
mock
from
mock
import
patch
from
lxml
import
etree
from
lxml
import
etree
from
django.test
import
TestCase
from
django.test
import
TestCase
...
@@ -1099,3 +1100,41 @@ class GetCourseVideoRemoveTest(TestCase):
...
@@ -1099,3 +1100,41 @@ class GetCourseVideoRemoveTest(TestCase):
# verify that video for other course has the correct info
# verify that video for other course has the correct info
video_info
=
{
key
:
videos
[
0
][
key
]
for
key
in
constants
.
VIDEO_DICT_FISH
}
video_info
=
{
key
:
videos
[
0
][
key
]
for
key
in
constants
.
VIDEO_DICT_FISH
}
self
.
assertEqual
(
video_info
,
constants
.
VIDEO_DICT_FISH
)
self
.
assertEqual
(
video_info
,
constants
.
VIDEO_DICT_FISH
)
class
VideoStatusUpdateTest
(
TestCase
):
"""
Tests to check video status update works correctly
"""
@patch
(
'edxval.models.logger'
)
def
test_video_instance_save_logging
(
self
,
mock_logger
):
"""
Tests correct message is logged when video instance is created and updated
"""
video
=
Video
.
objects
.
create
(
**
constants
.
VIDEO_DICT_FISH
)
mock_logger
.
info
.
assert_called_with
(
'VAL: Video created with id [
%
s] and status [
%
s]'
,
video
.
edx_video_id
,
constants
.
VIDEO_DICT_FISH
.
get
(
'status'
)
)
video
.
status
=
'new_status'
video
.
save
()
mock_logger
.
info
.
assert_called_with
(
'VAL: Status changed to [
%
s] for video [
%
s]'
,
video
.
status
,
video
.
edx_video_id
)
@patch
(
'edxval.models.logger'
)
def
test_update_video_status_logging
(
self
,
mock_logger
):
"""
Tests correct message is logged when `update_video_status` is called
"""
video
=
Video
.
objects
.
create
(
**
constants
.
VIDEO_DICT_FISH
)
api
.
update_video_status
(
video
.
edx_video_id
,
'fail'
)
mock_logger
.
info
.
assert_called_with
(
'VAL: Status changed to [
%
s] for video [
%
s]'
,
'fail'
,
video
.
edx_video_id
)
edxval/tests/test_serializers.py
View file @
1872d8e6
...
@@ -23,7 +23,8 @@ class SerializerTests(TestCase):
...
@@ -23,7 +23,8 @@ class SerializerTests(TestCase):
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE_DESKTOP
)
Video
.
objects
.
create
(
Video
.
objects
.
create
(
duration
=
0
,
duration
=
0
,
edx_video_id
=
constants
.
VIDEO_DICT_NON_LATIN_ID
[
"edx_video_id"
]
edx_video_id
=
constants
.
VIDEO_DICT_NON_LATIN_ID
[
"edx_video_id"
],
status
=
'test'
)
)
def
test_negative_fields_for_encoded_video_serializer
(
self
):
def
test_negative_fields_for_encoded_video_serializer
(
self
):
...
...
setup.py
View file @
1872d8e6
...
@@ -39,7 +39,7 @@ def load_requirements(*requirements_paths):
...
@@ -39,7 +39,7 @@ def load_requirements(*requirements_paths):
setup
(
setup
(
name
=
'edxval'
,
name
=
'edxval'
,
version
=
'0.0.1
1
'
,
version
=
'0.0.1
2
'
,
author
=
'edX'
,
author
=
'edX'
,
url
=
'http://github.com/edx/edx-val'
,
url
=
'http://github.com/edx/edx-val'
,
description
=
'edx-val'
,
description
=
'edx-val'
,
...
...
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