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
b1e11c9a
Commit
b1e11c9a
authored
Apr 29, 2015
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PLAT-612: Fix VAL error on re-import
parent
d6087908
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
6 deletions
+24
-6
edxval/api.py
+1
-1
edxval/models.py
+12
-0
edxval/tests/test_api.py
+11
-5
No files found.
edxval/api.py
View file @
b1e11c9a
...
@@ -437,7 +437,7 @@ def import_from_xml(xml, edx_video_id, course_id=None):
...
@@ -437,7 +437,7 @@ def import_from_xml(xml, edx_video_id, course_id=None):
course_id
,
course_id
,
)
)
if
course_id
:
if
course_id
:
CourseVideo
.
create_with_validation
(
video
=
video
,
course_id
=
course_id
)
CourseVideo
.
get_or_
create_with_validation
(
video
=
video
,
course_id
=
course_id
)
return
return
except
ValidationError
as
err
:
except
ValidationError
as
err
:
logger
.
exception
(
err
.
message
)
logger
.
exception
(
err
.
message
)
...
...
edxval/models.py
View file @
b1e11c9a
...
@@ -32,6 +32,18 @@ class ModelFactoryWithValidation(object):
...
@@ -32,6 +32,18 @@ class ModelFactoryWithValidation(object):
ret_val
.
full_clean
()
ret_val
.
full_clean
()
ret_val
.
save
()
ret_val
.
save
()
@classmethod
def
get_or_create_with_validation
(
cls
,
*
args
,
**
kwargs
):
"""
Factory method that gets or creates-and-validates the model object before it is saved.
Similar to the get_or_create method on Models, it returns a tuple of (object, created),
where created is a boolean specifying whether an object was created.
"""
try
:
return
cls
.
objects
.
get
(
*
args
,
**
kwargs
),
False
except
cls
.
DoesNotExist
:
return
cls
.
create_with_validation
(
*
args
,
**
kwargs
),
True
class
Profile
(
models
.
Model
):
class
Profile
(
models
.
Model
):
"""
"""
...
...
edxval/tests/test_api.py
View file @
b1e11c9a
...
@@ -743,6 +743,7 @@ class ExportTest(TestCase):
...
@@ -743,6 +743,7 @@ class ExportTest(TestCase):
api
.
export_to_xml
(
"unknown_video"
)
api
.
export_to_xml
(
"unknown_video"
)
@ddt
class
ImportTest
(
TestCase
):
class
ImportTest
(
TestCase
):
"""Tests import_from_xml"""
"""Tests import_from_xml"""
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -831,9 +832,13 @@ class ImportTest(TestCase):
...
@@ -831,9 +832,13 @@ class ImportTest(TestCase):
self
.
assertFalse
(
video
.
encoded_videos
.
all
()
.
exists
())
self
.
assertFalse
(
video
.
encoded_videos
.
all
()
.
exists
())
self
.
assertFalse
(
video
.
courses
.
all
()
.
exists
())
self
.
assertFalse
(
video
.
courses
.
all
()
.
exists
())
def
test_existing_video
(
self
):
@data
(
new_course_id
=
"new_course_id"
# import into another course, where the video already exists, but is not associated with the course.
"new_course_id"
,
# re-import case, where the video and course association already exists.
"existing_course_id"
)
def
test_existing_video
(
self
,
course_id
):
xml
=
self
.
make_import_xml
(
xml
=
self
.
make_import_xml
(
video_dict
=
{
video_dict
=
{
"client_video_id"
:
"new_client_video_id"
,
"client_video_id"
:
"new_client_video_id"
,
...
@@ -849,7 +854,7 @@ class ImportTest(TestCase):
...
@@ -849,7 +854,7 @@ class ImportTest(TestCase):
},
},
]
]
)
)
api
.
import_from_xml
(
xml
,
constants
.
VIDEO_DICT_FISH
[
"edx_video_id"
],
new_
course_id
)
api
.
import_from_xml
(
xml
,
constants
.
VIDEO_DICT_FISH
[
"edx_video_id"
],
course_id
)
video
=
Video
.
objects
.
get
(
edx_video_id
=
constants
.
VIDEO_DICT_FISH
[
"edx_video_id"
])
video
=
Video
.
objects
.
get
(
edx_video_id
=
constants
.
VIDEO_DICT_FISH
[
"edx_video_id"
])
self
.
assert_video_matches_dict
(
video
,
constants
.
VIDEO_DICT_FISH
)
self
.
assert_video_matches_dict
(
video
,
constants
.
VIDEO_DICT_FISH
)
...
@@ -860,7 +865,8 @@ class ImportTest(TestCase):
...
@@ -860,7 +865,8 @@ class ImportTest(TestCase):
self
.
assertFalse
(
self
.
assertFalse
(
video
.
encoded_videos
.
filter
(
profile__profile_name
=
constants
.
PROFILE_DESKTOP
)
.
exists
()
video
.
encoded_videos
.
filter
(
profile__profile_name
=
constants
.
PROFILE_DESKTOP
)
.
exists
()
)
)
self
.
assertTrue
(
video
.
courses
.
filter
(
course_id
=
new_course_id
)
.
exists
())
self
.
assertTrue
(
video
.
courses
.
filter
(
course_id
=
course_id
)
.
exists
())
def
test_existing_video_with_invalid_course_id
(
self
):
def
test_existing_video_with_invalid_course_id
(
self
):
xml
=
self
.
make_import_xml
(
video_dict
=
constants
.
VIDEO_DICT_FISH
)
xml
=
self
.
make_import_xml
(
video_dict
=
constants
.
VIDEO_DICT_FISH
)
...
...
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