Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
6f5b3fa1
Commit
6f5b3fa1
authored
Nov 14, 2012
by
Jay Zoldak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create factory for Xmodule items
parent
58fef4a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
2 deletions
+62
-2
cms/djangoapps/contentstore/tests/factories.py
+49
-2
cms/djangoapps/contentstore/tests/tests.py
+13
-0
No files found.
cms/djangoapps/contentstore/tests/factories.py
View file @
6f5b3fa1
...
...
@@ -54,4 +54,51 @@ class CourseFactory(XModuleCourseFactory):
template
=
'i4x://edx/templates/course/Empty'
org
=
'MITx'
number
=
'999'
display_name
=
'Robot Super Course'
\ No newline at end of file
display_name
=
'Robot Super Course'
class
XModuleItemFactory
(
Factory
):
"""
Factory for XModule items.
"""
ABSTRACT_FACTORY
=
True
@classmethod
def
_create
(
cls
,
target_class
,
*
args
,
**
kwargs
):
DETACHED_CATEGORIES
=
[
'about'
,
'static_tab'
,
'course_info'
]
parent_location
=
Location
(
kwargs
.
get
(
'parent_location'
))
template
=
Location
(
kwargs
.
get
(
'template'
))
display_name
=
kwargs
.
get
(
'display_name'
)
store
=
modulestore
(
'direct'
)
parent
=
store
.
get_item
(
parent_location
)
dest_location
=
parent_location
.
_replace
(
category
=
template
.
category
,
name
=
uuid4
()
.
hex
)
new_item
=
store
.
clone_item
(
template
,
dest_location
)
# TODO: This needs to be deleted when we have proper storage for static content
new_item
.
metadata
[
'data_dir'
]
=
parent
.
metadata
[
'data_dir'
]
# replace the display name with an optional parameter passed in from the caller
if
display_name
is
not
None
:
new_item
.
metadata
[
'display_name'
]
=
display_name
store
.
update_metadata
(
new_item
.
location
.
url
(),
new_item
.
own_metadata
)
if
new_item
.
location
.
category
not
in
DETACHED_CATEGORIES
:
store
.
update_children
(
parent_location
,
parent
.
definition
.
get
(
'children'
,
[])
+
[
new_item
.
location
.
url
()])
return
new_item
class
Item
:
pass
class
ItemFactory
(
XModuleItemFactory
):
FACTORY_FOR
=
Item
parent_location
=
'i4x://MITx/999/course/Robot_Super_Course'
template
=
'i4x://edx/templates/chapter/Empty'
display_name
=
'Section One'
\ No newline at end of file
cms/djangoapps/contentstore/tests/tests.py
View file @
6f5b3fa1
...
...
@@ -323,3 +323,16 @@ class ContentStoreTest(TestCase):
def
test_edit_unit_full
(
self
):
self
.
check_edit_unit
(
'full'
)
def
test_factory
(
self
):
from
factories
import
*
course
=
CourseFactory
.
create
()
print
'
\n
'
print
course
print
'
\n
'
section
=
ItemFactory
.
create
()
print
'
\n
'
print
section
print
'
\n
'
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