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
f338a709
Commit
f338a709
authored
Mar 27, 2015
by
Greg Price
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #42 from edx/gprice/remove-profile-fields
Remove Profile fields other than name
parents
64aa7637
657c51ed
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
165 additions
and
201 deletions
+165
-201
edxval/admin.py
+1
-1
edxval/api.py
+17
-31
edxval/migrations/0004_remove_profile_fields.py
+89
-0
edxval/models.py
+2
-22
edxval/serializers.py
+0
-14
edxval/tests/constants.py
+4
-52
edxval/tests/test_api.py
+33
-54
edxval/tests/test_serializers.py
+11
-7
edxval/tests/test_views.py
+8
-8
edxval/views.py
+0
-12
No files found.
edxval/admin.py
View file @
f338a709
...
@@ -7,7 +7,7 @@ from .models import Video, Profile, EncodedVideo, Subtitle, CourseVideo
...
@@ -7,7 +7,7 @@ from .models import Video, Profile, EncodedVideo, Subtitle, CourseVideo
class
ProfileAdmin
(
admin
.
ModelAdmin
):
# pylint: disable=C0111
class
ProfileAdmin
(
admin
.
ModelAdmin
):
# pylint: disable=C0111
list_display
=
(
'id'
,
'profile_name'
,
'extension'
,
'width'
,
'height'
)
list_display
=
(
'id'
,
'profile_name'
)
list_display_links
=
(
'id'
,
'profile_name'
)
list_display_links
=
(
'id'
,
'profile_name'
)
admin_order_field
=
'profile_name'
admin_order_field
=
'profile_name'
...
...
edxval/api.py
View file @
f338a709
...
@@ -3,11 +3,14 @@
...
@@ -3,11 +3,14 @@
"""
"""
The internal API for VAL. This is not yet stable
The internal API for VAL. This is not yet stable
"""
"""
from
enum
import
Enum
import
logging
import
logging
from
edxval.models
import
Video
,
EncodedVideo
,
CourseVideo
from
enum
import
Enum
from
edxval.serializers
import
VideoSerializer
,
ProfileSerializer
from
django.core.exceptions
import
ValidationError
from
edxval.models
import
Video
,
EncodedVideo
,
CourseVideo
,
Profile
from
edxval.serializers
import
VideoSerializer
logger
=
logging
.
getLogger
(
__name__
)
# pylint: disable=C0103
logger
=
logging
.
getLogger
(
__name__
)
# pylint: disable=C0103
...
@@ -88,11 +91,7 @@ def create_video(video_data):
...
@@ -88,11 +91,7 @@ def create_video(video_data):
encoded_video: a list of EncodedVideo dicts
encoded_video: a list of EncodedVideo dicts
url: url of the video
url: url of the video
file_size: size of the video in bytes
file_size: size of the video in bytes
profile: a dict of encoding details
profile: ID of the profile
profile_name: ID of the profile
extension: 3 letter extension of video
width: horizontal pixel resolution
height: vertical pixel resolution
courses: Courses associated with this video
courses: Courses associated with this video
}
}
"""
"""
...
@@ -104,33 +103,24 @@ def create_video(video_data):
...
@@ -104,33 +103,24 @@ def create_video(video_data):
raise
ValCannotCreateError
(
serializer
.
errors
)
raise
ValCannotCreateError
(
serializer
.
errors
)
def
create_profile
(
profile_
data
):
def
create_profile
(
profile_
name
):
"""
"""
Used to create Profile objects in the database
Used to create Profile objects in the database
A profile needs to exists before an EncodedVideo object can be created.
A profile needs to exists before an EncodedVideo object can be created.
Args:
Args:
data (dict):
profile_name (str): ID of the profile
{
profile_name: ID of the profile
extension: 3 letter extension of video
width: horizontal pixel resolution
height: vertical pixel resolution
}
Returns:
(int): id of the newly created object
Raises:
Raises:
ValCannotCreateError: Raised if the
serializer throws an error
ValCannotCreateError: Raised if the
profile name is invalid or exists
"""
"""
serializer
=
ProfileSerializer
(
data
=
profile_data
)
try
:
if
serializer
.
is_valid
():
profile
=
Profile
(
profile_name
=
profile_name
)
serializer
.
save
()
profile
.
full_clean
()
return
profile_data
.
get
(
"profile_name"
)
profile
.
save
(
)
e
lse
:
e
xcept
ValidationError
as
err
:
raise
ValCannotCreateError
(
serializer
.
errors
)
raise
ValCannotCreateError
(
err
.
message_dict
)
def
get_video_info
(
edx_video_id
,
location
=
None
):
# pylint: disable=W0613
def
get_video_info
(
edx_video_id
,
location
=
None
):
# pylint: disable=W0613
...
@@ -154,11 +144,7 @@ def get_video_info(edx_video_id, location=None): # pylint: disable=W0613
...
@@ -154,11 +144,7 @@ def get_video_info(edx_video_id, location=None): # pylint: disable=W0613
encoded_video: a list of EncodedVideo dicts
encoded_video: a list of EncodedVideo dicts
url: url of the video
url: url of the video
file_size: size of the video in bytes
file_size: size of the video in bytes
profile: a dict of encoding details
profile: ID of the profile
profile_name: ID of the profile
extension: 3 letter extension of video
width: horizontal pixel resolution
height: vertical pixel resolution
subtitles: a list of Subtitle dicts
subtitles: a list of Subtitle dicts
fmt: file format (SRT or SJSON)
fmt: file format (SRT or SJSON)
language: language code
language: language code
...
...
edxval/migrations/0004_remove_profile_fields.py
0 → 100644
View file @
f338a709
# -*- coding: utf-8 -*-
from
south.utils
import
datetime_utils
as
datetime
from
south.db
import
db
from
south.v2
import
SchemaMigration
from
django.db
import
models
class
Migration
(
SchemaMigration
):
def
forwards
(
self
,
orm
):
# The extension, width, and height fields of the Profile model are
# removed, but we want this migration to be non-destructive. Thus, the
# columns are simply altered to allow null values.
db
.
alter_column
(
'edxval_profile'
,
'width'
,
self
.
gf
(
'django.db.models.fields.PositiveIntegerField'
)(
null
=
True
,
default
=
1
))
db
.
alter_column
(
'edxval_profile'
,
'extension'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
max_length
=
10
,
null
=
True
,
default
=
'mp4'
))
db
.
alter_column
(
'edxval_profile'
,
'height'
,
self
.
gf
(
'django.db.models.fields.PositiveIntegerField'
)(
null
=
True
,
default
=
1
))
# On MySQL, attempts to insert new model instances (which lack values
# for the removed fields) results in a warning about a lack of a default
# value. Because django does not have a mechanism for specifying the
# default value in the database, we must manually alter the table here.
if
db
.
backend_name
==
'mysql'
:
db
.
execute
(
"ALTER TABLE edxval_profile MODIFY extension VARCHAR(10) DEFAULT 'mp4'"
)
db
.
execute
(
"ALTER TABLE edxval_profile MODIFY width INT(10) UNSIGNED DEFAULT 1"
)
db
.
execute
(
"ALTER TABLE edxval_profile MODIFY height INT(10) UNSIGNED DEFAULT 1"
)
def
backwards
(
self
,
orm
):
# Remove database-level defaults applied above
if
db
.
backend_name
==
'mysql'
:
db
.
execute
(
"ALTER TABLE edxval_profile MODIFY extension VARCHAR(10)"
)
db
.
execute
(
"ALTER TABLE edxval_profile MODIFY width INT(10) UNSIGNED"
)
db
.
execute
(
"ALTER TABLE edxval_profile MODIFY height INT(10) UNSIGNED"
)
# Because the forward migration is non-destructive and simply alters the
# extension, width, and height columns of the Profile model to allow
# null values, values from before the forward migration will still be
# present in the table. The backward migration restores the non-null
# restriction to each column and provides dumb defaults for any profiles
# that were created between the application of the forward migration and
# backward migration.
db
.
alter_column
(
'edxval_profile'
,
'width'
,
self
.
gf
(
'django.db.models.fields.PositiveIntegerField'
)(
default
=
1
))
db
.
alter_column
(
'edxval_profile'
,
'extension'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
default
=
'mp4'
,
max_length
=
10
))
db
.
alter_column
(
'edxval_profile'
,
'height'
,
self
.
gf
(
'django.db.models.fields.PositiveIntegerField'
)(
default
=
1
))
models
=
{
'edxval.coursevideo'
:
{
'Meta'
:
{
'unique_together'
:
"(('course_id', 'video'),)"
,
'object_name'
:
'CourseVideo'
},
'course_id'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'255'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'video'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'related_name'
:
"'courses'"
,
'to'
:
"orm['edxval.Video']"
})
},
'edxval.encodedvideo'
:
{
'Meta'
:
{
'object_name'
:
'EncodedVideo'
},
'bitrate'
:
(
'django.db.models.fields.PositiveIntegerField'
,
[],
{}),
'created'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'auto_now_add'
:
'True'
,
'blank'
:
'True'
}),
'file_size'
:
(
'django.db.models.fields.PositiveIntegerField'
,
[],
{}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'modified'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'auto_now'
:
'True'
,
'blank'
:
'True'
}),
'profile'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'related_name'
:
"'+'"
,
'to'
:
"orm['edxval.Profile']"
}),
'url'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'200'
}),
'video'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'related_name'
:
"'encoded_videos'"
,
'to'
:
"orm['edxval.Video']"
})
},
'edxval.profile'
:
{
'Meta'
:
{
'object_name'
:
'Profile'
},
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'profile_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'50'
})
},
'edxval.subtitle'
:
{
'Meta'
:
{
'object_name'
:
'Subtitle'
},
'content'
:
(
'django.db.models.fields.TextField'
,
[],
{
'default'
:
"''"
}),
'created'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'auto_now_add'
:
'True'
,
'blank'
:
'True'
}),
'fmt'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'20'
,
'db_index'
:
'True'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'language'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'8'
,
'db_index'
:
'True'
}),
'modified'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'auto_now'
:
'True'
,
'blank'
:
'True'
}),
'video'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'related_name'
:
"'subtitles'"
,
'to'
:
"orm['edxval.Video']"
})
},
'edxval.video'
:
{
'Meta'
:
{
'object_name'
:
'Video'
},
'client_video_id'
:
(
'django.db.models.fields.CharField'
,
[],
{
'db_index'
:
'True'
,
'max_length'
:
'255'
,
'blank'
:
'True'
}),
'created'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'auto_now_add'
:
'True'
,
'blank'
:
'True'
}),
'duration'
:
(
'django.db.models.fields.FloatField'
,
[],
{}),
'edx_video_id'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'100'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'status'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'255'
,
'db_index'
:
'True'
})
}
}
complete_apps
=
[
'edxval'
]
edxval/models.py
View file @
f338a709
...
@@ -5,26 +5,9 @@ When calling a serializers' .errors field, there is a priority in which the
...
@@ -5,26 +5,9 @@ When calling a serializers' .errors field, there is a priority in which the
errors are returned. This may cause a partial return of errors, starting with
errors are returned. This may cause a partial return of errors, starting with
the highest priority.
the highest priority.
Example:
Missing a field, having an incorrect input type (expected an int, not a str),
class Profile(models.Model)
profile_name = models.CharField(
max_length=50,
unique=True,
validators=[
RegexValidator(
regex=regex,
message='profile_name has invalid characters',
code='invalid profile_name'
),
]
)
extension = models.CharField(max_length=10)
width = models.PositiveIntegerField()
height = models.PositiveIntegerField()
Missing a field, having an input type (expected an int, not a str),
nested serialization errors, or any similar errors will be returned by
nested serialization errors, or any similar errors will be returned by
themselves. After these are resolved, errors such as a negative
height,
or
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.
"""
"""
...
@@ -54,9 +37,6 @@ class Profile(models.Model):
...
@@ -54,9 +37,6 @@ class Profile(models.Model):
),
),
]
]
)
)
extension
=
models
.
CharField
(
max_length
=
10
)
width
=
models
.
PositiveIntegerField
()
height
=
models
.
PositiveIntegerField
()
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
profile_name
return
self
.
profile_name
...
...
edxval/serializers.py
View file @
f338a709
...
@@ -10,20 +10,6 @@ from django.core.exceptions import ValidationError
...
@@ -10,20 +10,6 @@ from django.core.exceptions import ValidationError
from
edxval.models
import
Profile
,
Video
,
EncodedVideo
,
Subtitle
,
CourseVideo
from
edxval.models
import
Profile
,
Video
,
EncodedVideo
,
Subtitle
,
CourseVideo
class
ProfileSerializer
(
serializers
.
ModelSerializer
):
"""
Serializer for Profile object.
"""
class
Meta
:
# pylint: disable=C1001, C0111
model
=
Profile
fields
=
(
"profile_name"
,
"extension"
,
"width"
,
"height"
)
class
EncodedVideoSerializer
(
serializers
.
ModelSerializer
):
class
EncodedVideoSerializer
(
serializers
.
ModelSerializer
):
"""
"""
Serializer for EncodedVideo object.
Serializer for EncodedVideo object.
...
...
edxval/tests/constants.py
View file @
f338a709
...
@@ -7,24 +7,9 @@ EDX_VIDEO_ID = "itchyjacket"
...
@@ -7,24 +7,9 @@ EDX_VIDEO_ID = "itchyjacket"
"""
"""
Generic Profiles for manually creating profile objects
Generic Profiles for manually creating profile objects
"""
"""
PROFILE_DICT_MOBILE
=
dict
(
PROFILE_MOBILE
=
"mobile"
profile_name
=
"mobile"
,
PROFILE_DESKTOP
=
"desktop"
extension
=
"avi"
,
PROFILE_YOUTUBE
=
"youtube"
width
=
100
,
height
=
101
)
PROFILE_DICT_DESKTOP
=
dict
(
profile_name
=
"desktop"
,
extension
=
"mp4"
,
width
=
200
,
height
=
2001
)
PROFILE_DICT_YOUTUBE
=
dict
(
profile_name
=
"youtube"
,
extension
=
"mp4"
,
width
=
1280
,
height
=
720
)
"""
"""
Encoded_videos for test_api, does not have profile.
Encoded_videos for test_api, does not have profile.
"""
"""
...
@@ -112,40 +97,7 @@ VIDEO_DICT_NON_LATIN_ID = dict(
...
@@ -112,40 +97,7 @@ VIDEO_DICT_NON_LATIN_ID = dict(
encoded_videos
=
[],
encoded_videos
=
[],
subtitles
=
[]
subtitles
=
[]
)
)
PROFILE_DICT_NON_LATIN
=
dict
(
PROFILE_INVALID_NAME
=
"lo/lol"
profile_name
=
u"배고파"
,
extension
=
"mew"
,
width
=
100
,
height
=
300
)
PROFILE_DICT_INVALID_NAME
=
dict
(
profile_name
=
"lo/lol"
,
extension
=
"mew"
,
width
=
100
,
height
=
300
)
PROFILE_DICT_NEGATIVE_WIDTH
=
dict
(
profile_name
=
"mobile"
,
extension
=
"mew"
,
width
=-
100
,
height
=
300
)
PROFILE_DICT_NEGATIVE_HEIGHT
=
dict
(
profile_name
=
"mobile"
,
extension
=
"mew"
,
width
=
100
,
height
=-
300
)
PROFILE_DICT_MISSING_EXTENSION
=
dict
(
profile_name
=
"mobile"
,
width
=
100
,
height
=
300
)
PROFILE_DICT_MANY_INVALID
=
dict
(
profile_name
=
"hh/ff"
,
width
=-
100
,
height
=
"lol"
,
)
"""
"""
Subtitles
Subtitles
"""
"""
...
...
edxval/tests/test_api.py
View file @
f338a709
...
@@ -8,7 +8,6 @@ import mock
...
@@ -8,7 +8,6 @@ import mock
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.db
import
DatabaseError
from
django.db
import
DatabaseError
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.core.exceptions
import
ValidationError
from
rest_framework
import
status
from
rest_framework
import
status
from
ddt
import
ddt
,
data
from
ddt
import
ddt
,
data
...
@@ -35,8 +34,8 @@ class CreateVideoTest(TestCase):
...
@@ -35,8 +34,8 @@ class CreateVideoTest(TestCase):
"""
"""
Creation of Profile objects that will be used to test video creation
Creation of Profile objects that will be used to test video creation
"""
"""
api
.
create_profile
(
constants
.
PROFILE_D
ICT_D
ESKTOP
)
api
.
create_profile
(
constants
.
PROFILE_DESKTOP
)
api
.
create_profile
(
constants
.
PROFILE_
DICT_
MOBILE
)
api
.
create_profile
(
constants
.
PROFILE_MOBILE
)
def
test_create_video
(
self
):
def
test_create_video
(
self
):
"""
"""
...
@@ -65,24 +64,7 @@ class CreateVideoTest(TestCase):
...
@@ -65,24 +64,7 @@ class CreateVideoTest(TestCase):
with
self
.
assertRaises
(
ValCannotCreateError
):
with
self
.
assertRaises
(
ValCannotCreateError
):
api
.
create_video
(
data
)
api
.
create_video
(
data
)
def
test_invalid_profile
(
self
):
"""
Tests inputting bad profile type
"""
video_data
=
dict
(
encoded_videos
=
[
dict
(
profile
=
constants
.
PROFILE_DICT_MOBILE
,
**
constants
.
ENCODED_VIDEO_DICT_MOBILE
)
],
**
constants
.
VIDEO_DICT_FISH
)
with
self
.
assertRaises
(
ValidationError
):
api
.
create_video
(
video_data
)
@ddt
class
CreateProfileTest
(
TestCase
):
class
CreateProfileTest
(
TestCase
):
"""
"""
Tests the create_profile function in the api.py
Tests the create_profile function in the api.py
...
@@ -92,29 +74,26 @@ class CreateProfileTest(TestCase):
...
@@ -92,29 +74,26 @@ class CreateProfileTest(TestCase):
"""
"""
Tests the creation of a profile
Tests the creation of a profile
"""
"""
result
=
api
.
create_profile
(
constants
.
PROFILE_D
ICT_D
ESKTOP
)
result
=
api
.
create_profile
(
constants
.
PROFILE_DESKTOP
)
profiles
=
list
(
Profile
.
objects
.
all
())
profiles
=
list
(
Profile
.
objects
.
all
())
self
.
assertEqual
(
len
(
profiles
),
6
)
self
.
assertEqual
(
len
(
profiles
),
6
)
self
.
assertEqual
(
self
.
assertEqual
(
profiles
[
-
1
]
.
profile_name
,
profiles
[
-
1
]
.
profile_name
,
constants
.
PROFILE_D
ICT_DESKTOP
.
get
(
'profile_name'
)
constants
.
PROFILE_D
ESKTOP
)
)
self
.
assertEqual
(
len
(
profiles
),
6
)
self
.
assertEqual
(
len
(
profiles
),
6
)
self
.
assertEqual
(
"desktop"
,
result
)
@data
(
def
test_invalid_create_profile
(
self
):
constants
.
PROFILE_DICT_NEGATIVE_WIDTH
,
constants
.
PROFILE_DICT_NEGATIVE_HEIGHT
,
constants
.
PROFILE_DICT_MISSING_EXTENSION
,
constants
.
PROFILE_DICT_MANY_INVALID
,
constants
.
PROFILE_DICT_INVALID_NAME
,
)
def
test_invalid_create_profile
(
self
,
data
):
# pylint: disable=W0621
"""
"""
Tests the creation of invalid profile data
Tests the creation of invalid profile data
"""
"""
with
self
.
assertRaises
(
ValCannotCreateError
):
with
self
.
assertRaises
(
ValCannotCreateError
):
api
.
create_profile
(
data
)
api
.
create_profile
(
constants
.
PROFILE_INVALID_NAME
)
def
test_create_profile_duplicate
(
self
):
api
.
create_profile
(
constants
.
PROFILE_DESKTOP
)
with
self
.
assertRaises
(
ValCannotCreateError
):
api
.
create_profile
(
constants
.
PROFILE_DESKTOP
)
class
GetVideoInfoTest
(
TestCase
):
class
GetVideoInfoTest
(
TestCase
):
...
@@ -126,8 +105,8 @@ class GetVideoInfoTest(TestCase):
...
@@ -126,8 +105,8 @@ class GetVideoInfoTest(TestCase):
"""
"""
Creates EncodedVideo objects in database
Creates EncodedVideo objects in database
"""
"""
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_MOBILE
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_MOBILE
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_DESKTOP
)
video
=
Video
.
objects
.
create
(
**
constants
.
VIDEO_DICT_FISH
)
video
=
Video
.
objects
.
create
(
**
constants
.
VIDEO_DICT_FISH
)
EncodedVideo
.
objects
.
create
(
EncodedVideo
.
objects
.
create
(
video
=
video
,
video
=
video
,
...
@@ -211,8 +190,8 @@ class GetUrlsForProfileTest(TestCase):
...
@@ -211,8 +190,8 @@ class GetUrlsForProfileTest(TestCase):
"""
"""
Creates EncodedVideo objects in database
Creates EncodedVideo objects in database
"""
"""
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_MOBILE
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_MOBILE
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_DESKTOP
)
video
=
Video
.
objects
.
create
(
**
constants
.
VIDEO_DICT_FISH
)
video
=
Video
.
objects
.
create
(
**
constants
.
VIDEO_DICT_FISH
)
EncodedVideo
.
objects
.
create
(
EncodedVideo
.
objects
.
create
(
video
=
Video
.
objects
.
get
(
video
=
Video
.
objects
.
get
(
...
@@ -280,8 +259,8 @@ class GetVideoForCourseProfiles(TestCase):
...
@@ -280,8 +259,8 @@ class GetVideoForCourseProfiles(TestCase):
Creates two videos with 2 encoded videos for the first course, and then
Creates two videos with 2 encoded videos for the first course, and then
2 videos with 1 encoded video for the second course.
2 videos with 1 encoded video for the second course.
"""
"""
mobile_profile
=
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_MOBILE
)
mobile_profile
=
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_MOBILE
)
desktop_profile
=
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_DESKTOP
)
desktop_profile
=
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_DESKTOP
)
self
.
course_id
=
'test-course'
self
.
course_id
=
'test-course'
# 1st video
# 1st video
...
@@ -359,13 +338,13 @@ class GetVideoForCourseProfiles(TestCase):
...
@@ -359,13 +338,13 @@ class GetVideoForCourseProfiles(TestCase):
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_FISH
,
constants
.
VIDEO_DICT_FISH
,
{
{
constants
.
PROFILE_
DICT_MOBILE
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_MOBILE
constants
.
PROFILE_
MOBILE
:
constants
.
ENCODED_VIDEO_DICT_MOBILE
}
}
))
))
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_STAR
,
constants
.
VIDEO_DICT_STAR
,
{
{
constants
.
PROFILE_
DICT_MOBILE
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_MOBILE2
constants
.
PROFILE_
MOBILE
:
constants
.
ENCODED_VIDEO_DICT_MOBILE2
}))
}))
self
.
assertEqual
(
videos
,
expected_dict
)
self
.
assertEqual
(
videos
,
expected_dict
)
...
@@ -380,15 +359,15 @@ class GetVideoForCourseProfiles(TestCase):
...
@@ -380,15 +359,15 @@ class GetVideoForCourseProfiles(TestCase):
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_FISH
,
constants
.
VIDEO_DICT_FISH
,
{
{
constants
.
PROFILE_
DICT_MOBILE
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_MOBILE
,
constants
.
PROFILE_
MOBILE
:
constants
.
ENCODED_VIDEO_DICT_MOBILE
,
constants
.
PROFILE_D
ICT_DESKTOP
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_DESKTOP
,
constants
.
PROFILE_D
ESKTOP
:
constants
.
ENCODED_VIDEO_DICT_DESKTOP
,
}
}
))
))
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_STAR
,
constants
.
VIDEO_DICT_STAR
,
{
{
constants
.
PROFILE_
DICT_MOBILE
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_MOBILE2
,
constants
.
PROFILE_
MOBILE
:
constants
.
ENCODED_VIDEO_DICT_MOBILE2
,
constants
.
PROFILE_D
ICT_DESKTOP
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_DESKTOP2
,
constants
.
PROFILE_D
ESKTOP
:
constants
.
ENCODED_VIDEO_DICT_DESKTOP2
,
}
}
))
))
self
.
assertEqual
(
videos
,
expected_dict
)
self
.
assertEqual
(
videos
,
expected_dict
)
...
@@ -412,13 +391,13 @@ class GetVideoForCourseProfiles(TestCase):
...
@@ -412,13 +391,13 @@ class GetVideoForCourseProfiles(TestCase):
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_FISH
,
constants
.
VIDEO_DICT_FISH
,
{
{
constants
.
PROFILE_
DICT_MOBILE
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_MOBILE
constants
.
PROFILE_
MOBILE
:
constants
.
ENCODED_VIDEO_DICT_MOBILE
}
}
))
))
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_STAR
,
constants
.
VIDEO_DICT_STAR
,
{
{
constants
.
PROFILE_
DICT_MOBILE
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_MOBILE2
constants
.
PROFILE_
MOBILE
:
constants
.
ENCODED_VIDEO_DICT_MOBILE2
}
}
))
))
self
.
assertEqual
(
videos
,
expected_dict
)
self
.
assertEqual
(
videos
,
expected_dict
)
...
@@ -434,7 +413,7 @@ class GetVideoForCourseProfiles(TestCase):
...
@@ -434,7 +413,7 @@ class GetVideoForCourseProfiles(TestCase):
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_TREE
,
constants
.
VIDEO_DICT_TREE
,
{
{
constants
.
PROFILE_
DICT_MOBILE
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_MOBILE3
constants
.
PROFILE_
MOBILE
:
constants
.
ENCODED_VIDEO_DICT_MOBILE3
}
}
))
))
self
.
assertEqual
(
videos
,
expected_dict
)
self
.
assertEqual
(
videos
,
expected_dict
)
...
@@ -446,7 +425,7 @@ class GetVideoForCourseProfiles(TestCase):
...
@@ -446,7 +425,7 @@ class GetVideoForCourseProfiles(TestCase):
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_PLANT
,
constants
.
VIDEO_DICT_PLANT
,
{
{
constants
.
PROFILE_D
ICT_DESKTOP
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_DESKTOP3
constants
.
PROFILE_D
ESKTOP
:
constants
.
ENCODED_VIDEO_DICT_DESKTOP3
}
}
))
))
self
.
assertEqual
(
videos
,
expected_dict
)
self
.
assertEqual
(
videos
,
expected_dict
)
...
@@ -462,13 +441,13 @@ class GetVideoForCourseProfiles(TestCase):
...
@@ -462,13 +441,13 @@ class GetVideoForCourseProfiles(TestCase):
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_FISH
,
constants
.
VIDEO_DICT_FISH
,
{
{
constants
.
PROFILE_
DICT_MOBILE
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_MOBILE
,
constants
.
PROFILE_
MOBILE
:
constants
.
ENCODED_VIDEO_DICT_MOBILE
,
}
}
))
))
expected_dict
.
update
(
self
.
_create_video_dict
(
expected_dict
.
update
(
self
.
_create_video_dict
(
constants
.
VIDEO_DICT_STAR
,
constants
.
VIDEO_DICT_STAR
,
{
{
constants
.
PROFILE_
DICT_MOBILE
[
"profile_name"
]
:
constants
.
ENCODED_VIDEO_DICT_MOBILE2
constants
.
PROFILE_
MOBILE
:
constants
.
ENCODED_VIDEO_DICT_MOBILE2
}
}
))
))
self
.
assertEqual
(
videos
,
expected_dict
)
self
.
assertEqual
(
videos
,
expected_dict
)
...
@@ -483,8 +462,8 @@ class GetVideosForIds(TestCase):
...
@@ -483,8 +462,8 @@ class GetVideosForIds(TestCase):
"""
"""
Creates EncodedVideo objects in database
Creates EncodedVideo objects in database
"""
"""
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_MOBILE
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_MOBILE
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_DESKTOP
)
video
=
Video
.
objects
.
create
(
**
constants
.
VIDEO_DICT_FISH
)
video
=
Video
.
objects
.
create
(
**
constants
.
VIDEO_DICT_FISH
)
EncodedVideo
.
objects
.
create
(
EncodedVideo
.
objects
.
create
(
video
=
Video
.
objects
.
get
(
video
=
Video
.
objects
.
get
(
...
@@ -592,8 +571,8 @@ class GetVideoInfoTestWithHttpCalls(APIAuthTestCase):
...
@@ -592,8 +571,8 @@ class GetVideoInfoTestWithHttpCalls(APIAuthTestCase):
database via HTTP uploads.
database via HTTP uploads.
"""
"""
super
(
GetVideoInfoTestWithHttpCalls
,
self
)
.
setUp
()
super
(
GetVideoInfoTestWithHttpCalls
,
self
)
.
setUp
()
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_MOBILE
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_MOBILE
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_DESKTOP
)
url
=
reverse
(
'video-list'
)
url
=
reverse
(
'video-list'
)
response
=
self
.
client
.
post
(
response
=
self
.
client
.
post
(
url
,
constants
.
COMPLETE_SET_FISH
,
format
=
'json'
url
,
constants
.
COMPLETE_SET_FISH
,
format
=
'json'
...
...
edxval/tests/test_serializers.py
View file @
f338a709
...
@@ -8,7 +8,6 @@ from django.test import TestCase
...
@@ -8,7 +8,6 @@ from django.test import TestCase
from
edxval.serializers
import
(
from
edxval.serializers
import
(
EncodedVideoSerializer
,
EncodedVideoSerializer
,
ProfileSerializer
,
VideoSerializer
,
VideoSerializer
,
ValidationError
,
ValidationError
,
)
)
...
@@ -22,11 +21,14 @@ class SerializerTests(TestCase):
...
@@ -22,11 +21,14 @@ class SerializerTests(TestCase):
"""
"""
def
setUp
(
self
):
def
setUp
(
self
):
"""
"""
Creates Profile objects
Creates Profile objects
and a video object
"""
"""
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT_MOBILE
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE_MOBILE
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE_DESKTOP
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT_NON_LATIN
)
Video
.
objects
.
create
(
duration
=
0
,
edx_video_id
=
constants
.
VIDEO_DICT_NON_LATIN_ID
[
"edx_video_id"
]
)
def
test_negative_fields_for_encoded_video_serializer
(
self
):
def
test_negative_fields_for_encoded_video_serializer
(
self
):
"""
"""
...
@@ -60,8 +62,10 @@ class SerializerTests(TestCase):
...
@@ -60,8 +62,10 @@ class SerializerTests(TestCase):
"""
"""
# TODO not the best test. Need to understand what result we want
# TODO not the best test. Need to understand what result we want
self
.
assertIsInstance
(
self
.
assertIsInstance
(
ProfileSerializer
(
Profile
.
objects
.
get
(
profile_name
=
"배고파"
)),
VideoSerializer
(
ProfileSerializer
Video
.
objects
.
get
(
edx_video_id
=
constants
.
VIDEO_DICT_NON_LATIN_ID
[
"edx_video_id"
])
),
VideoSerializer
)
)
def
test_invalid_edx_video_id
(
self
):
def
test_invalid_edx_video_id
(
self
):
...
...
edxval/tests/test_views.py
View file @
f338a709
...
@@ -18,8 +18,8 @@ class VideoDetail(APIAuthTestCase):
...
@@ -18,8 +18,8 @@ class VideoDetail(APIAuthTestCase):
"""
"""
Used for manually creating profile objects which EncodedVideos require.
Used for manually creating profile objects which EncodedVideos require.
"""
"""
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_MOBILE
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_MOBILE
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_DESKTOP
)
super
(
VideoDetail
,
self
)
.
setUp
()
super
(
VideoDetail
,
self
)
.
setUp
()
# Tests for successful PUT requests.
# Tests for successful PUT requests.
...
@@ -321,8 +321,8 @@ class VideoListTest(APIAuthTestCase):
...
@@ -321,8 +321,8 @@ class VideoListTest(APIAuthTestCase):
"""
"""
Used for manually creating profile objects which EncodedVideos require.
Used for manually creating profile objects which EncodedVideos require.
"""
"""
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_MOBILE
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_MOBILE
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_DESKTOP
)
super
(
VideoListTest
,
self
)
.
setUp
()
super
(
VideoListTest
,
self
)
.
setUp
()
def
tearDown
(
self
):
def
tearDown
(
self
):
...
@@ -573,8 +573,8 @@ class VideoDetailTest(APIAuthTestCase):
...
@@ -573,8 +573,8 @@ class VideoDetailTest(APIAuthTestCase):
"""
"""
Used for manually creating profile objects which EncodedVideos require.
Used for manually creating profile objects which EncodedVideos require.
"""
"""
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_MOBILE
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_MOBILE
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_DESKTOP
)
super
(
VideoDetailTest
,
self
)
.
setUp
()
super
(
VideoDetailTest
,
self
)
.
setUp
()
def
test_get_all_videos
(
self
):
def
test_get_all_videos
(
self
):
...
@@ -615,8 +615,8 @@ class SubtitleDetailTest(APIAuthTestCase):
...
@@ -615,8 +615,8 @@ class SubtitleDetailTest(APIAuthTestCase):
Tests for subtitle API
Tests for subtitle API
"""
"""
def
setUp
(
self
):
def
setUp
(
self
):
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_MOBILE
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_MOBILE
)
Profile
.
objects
.
create
(
**
constants
.
PROFILE_DICT
_DESKTOP
)
Profile
.
objects
.
create
(
profile_name
=
constants
.
PROFILE
_DESKTOP
)
super
(
SubtitleDetailTest
,
self
)
.
setUp
()
super
(
SubtitleDetailTest
,
self
)
.
setUp
()
def
test_get_subtitle_content
(
self
):
def
test_get_subtitle_content
(
self
):
...
...
edxval/views.py
View file @
f338a709
...
@@ -11,7 +11,6 @@ from django.views.decorators.http import last_modified
...
@@ -11,7 +11,6 @@ from django.views.decorators.http import last_modified
from
edxval.models
import
Video
,
Profile
,
Subtitle
from
edxval.models
import
Video
,
Profile
,
Subtitle
from
edxval.serializers
import
(
from
edxval.serializers
import
(
VideoSerializer
,
VideoSerializer
,
ProfileSerializer
,
SubtitleSerializer
SubtitleSerializer
)
)
...
@@ -77,17 +76,6 @@ class VideoList(generics.ListCreateAPIView):
...
@@ -77,17 +76,6 @@ class VideoList(generics.ListCreateAPIView):
return
qset
return
qset
class
ProfileList
(
generics
.
ListCreateAPIView
):
"""
GETs or POST video objects
"""
authentication_classes
=
(
OAuth2Authentication
,
SessionAuthentication
)
permission_classes
=
(
ReadRestrictedDjangoModelPermissions
,)
queryset
=
Profile
.
objects
.
all
()
lookup_field
=
"profile_name"
serializer_class
=
ProfileSerializer
class
VideoDetail
(
generics
.
RetrieveUpdateDestroyAPIView
):
class
VideoDetail
(
generics
.
RetrieveUpdateDestroyAPIView
):
"""
"""
Gets a video instance given its edx_video_id
Gets a video instance given its edx_video_id
...
...
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