Commit 26716a1c by Muhammad Ammar Committed by GitHub

Merge pull request #64 from edx/ammar/tnl-5898-edxval-soft-delete-video

soft delete video for a course
parents 0640e912 c811297f
......@@ -147,7 +147,7 @@ def update_video(video_data):
try:
video = _get_video(video_data.get("edx_video_id"))
except Video.DoesNotExist:
error_message = u"Video not found when trying to update video with edx_video_id: {0}".format(video_data.get("edx_video_id"))
error_message = u"Video not found when trying to update video with edx_video_id: {0}".format(video_data.get("edx_video_id"))
raise ValVideoNotFoundError(error_message)
serializer = VideoSerializer(video, data=video_data)
......@@ -328,12 +328,25 @@ def get_videos_for_course(
total order.
"""
return _get_videos_for_filter(
{"courses__course_id":unicode(course_id)},
{"courses__course_id": unicode(course_id), "courses__is_hidden": False},
sort_field,
sort_dir,
)
def remove_video_for_course(course_id, edx_video_id):
"""
Soft deletes video for particular course.
Arguments:
course_id (str): id of the course
edx_video_id (str): id of the video to be hidden
"""
course_video = CourseVideo.objects.get(course_id=course_id, video__edx_video_id=edx_video_id)
course_video.is_hidden = True
course_video.save()
def get_videos_for_ids(
edx_video_ids,
sort_field=None,
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('edxval', '0002_data__default_profiles'),
]
operations = [
migrations.AddField(
model_name='coursevideo',
name='is_hidden',
field=models.BooleanField(default=False, help_text=b'Hide this video for course.'),
),
]
......@@ -125,6 +125,7 @@ class CourseVideo(models.Model, ModelFactoryWithValidation):
"""
course_id = models.CharField(max_length=255)
video = models.ForeignKey(Video, related_name='courses')
is_hidden = models.BooleanField(default=False, help_text='Hide video for course.')
class Meta: # pylint: disable=C1001
"""
......
......@@ -149,7 +149,7 @@ class UpdateVideoTest(TestCase):
"""
Tests the update of a video
"""
video_data = dict(
encoded_videos=[
constants.ENCODED_VIDEO_DICT_FISH_MOBILE
......@@ -1055,3 +1055,47 @@ class ImportTest(TestCase):
def test_invalid_course_id(self):
xml = self.make_import_xml(video_dict=constants.VIDEO_DICT_FISH)
self.assert_invalid_import(xml, "x" * 300)
class GetCourseVideoRemoveTest(TestCase):
"""
Tests to check `remove_video_for_course` function works correctly
"""
def setUp(self):
"""
Creates video objects for courses
"""
# create video in the test course
self.course_id = 'test-course'
video = Video.objects.create(**constants.VIDEO_DICT_FISH)
CourseVideo.objects.create(video=video, course_id=self.course_id)
self.edx_video_id = video.edx_video_id
# add the video in another course (to make sure that video is removed for correct course)
CourseVideo.objects.create(video=video, course_id='other-course')
def test_remove_video_for_course(self):
"""
Tests video removal for a course
"""
# we have one video for this course
videos = list(api.get_videos_for_course(self.course_id))
self.assertEqual(len(videos), 1)
# remove the video and verify that video is removed from correct course
api.remove_video_for_course(self.course_id, self.edx_video_id)
videos = list(api.get_videos_for_course(self.course_id))
self.assertEqual(len(videos), 0)
# verify that CourseVideo related object exists(soft removal) for removed video
course_video = CourseVideo.objects.get(course_id=self.course_id, video__edx_video_id=self.edx_video_id)
self.assertEqual(course_video.is_hidden, True)
# verify that video still exists for other course
videos = list(api.get_videos_for_course('other-course'))
self.assertEqual(len(videos), 1)
# verify that video for other course has the correct info
video_info = {key: videos[0][key] for key in constants.VIDEO_DICT_FISH}
self.assertEqual(video_info, constants.VIDEO_DICT_FISH)
......@@ -39,7 +39,7 @@ def load_requirements(*requirements_paths):
setup(
name='edxval',
version='0.0.9',
version='0.0.10',
author='edX',
url='http://github.com/edx/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