Commit 1872d8e6 by muhammad-ammar

update video status

TNL-4777
parent 4d4c631a
...@@ -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
......
...@@ -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)
...@@ -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
)
...@@ -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):
......
...@@ -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.11', version='0.0.12',
author='edX', author='edX',
url='http://github.com/edx/edx-val', url='http://github.com/edx/edx-val',
description='edx-val', description='edx-val',
......
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