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
26716a1c
Commit
26716a1c
authored
Nov 17, 2016
by
Muhammad Ammar
Committed by
GitHub
Nov 17, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #64 from edx/ammar/tnl-5898-edxval-soft-delete-video
soft delete video for a course
parents
0640e912
c811297f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
4 deletions
+81
-4
edxval/api.py
+15
-2
edxval/migrations/0003_coursevideo_is_hidden.py
+19
-0
edxval/models.py
+1
-0
edxval/tests/test_api.py
+45
-1
setup.py
+1
-1
No files found.
edxval/api.py
View file @
26716a1c
...
...
@@ -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
,
...
...
edxval/migrations/0003_coursevideo_is_hidden.py
0 → 100644
View file @
26716a1c
# -*- 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.'
),
),
]
edxval/models.py
View file @
26716a1c
...
...
@@ -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
"""
...
...
edxval/tests/test_api.py
View file @
26716a1c
...
...
@@ -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
)
setup.py
View file @
26716a1c
...
...
@@ -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'
,
...
...
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