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
58fef4a3
Commit
58fef4a3
authored
Nov 14, 2012
by
Jay Zoldak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create factory for courses
parent
a060b8de
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
cms/djangoapps/contentstore/tests/factories.py
+58
-0
No files found.
cms/djangoapps/contentstore/tests/factories.py
0 → 100644
View file @
58fef4a3
from
factory
import
Factory
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
time
import
gmtime
from
uuid
import
uuid4
from
xmodule.timeparse
import
stringify_time
class
XModuleCourseFactory
(
Factory
):
"""
Factory for XModule courses.
"""
ABSTRACT_FACTORY
=
True
@classmethod
def
_create
(
cls
,
target_class
,
*
args
,
**
kwargs
):
template
=
Location
(
'i4x'
,
'edx'
,
'templates'
,
'course'
,
'Empty'
)
org
=
kwargs
.
get
(
'org'
)
number
=
kwargs
.
get
(
'number'
)
display_name
=
kwargs
.
get
(
'display_name'
)
location
=
Location
(
'i4x'
,
org
,
number
,
'course'
,
Location
.
clean
(
display_name
))
store
=
modulestore
(
'direct'
)
# Write the data to the mongo datastore
new_course
=
store
.
clone_item
(
template
,
location
)
# This metadata code was copied from cms/djangoapps/contentstore/views.py
if
display_name
is
not
None
:
new_course
.
metadata
[
'display_name'
]
=
display_name
new_course
.
metadata
[
'data_dir'
]
=
uuid4
()
.
hex
new_course
.
metadata
[
'start'
]
=
stringify_time
(
gmtime
())
new_course
.
tabs
=
[{
"type"
:
"courseware"
},
{
"type"
:
"course_info"
,
"name"
:
"Course Info"
},
{
"type"
:
"discussion"
,
"name"
:
"Discussion"
},
{
"type"
:
"wiki"
,
"name"
:
"Wiki"
},
{
"type"
:
"progress"
,
"name"
:
"Progress"
}]
# Update the data in the mongo datastore
store
.
update_metadata
(
new_course
.
location
.
url
(),
new_course
.
own_metadata
)
return
new_course
class
Course
:
pass
class
CourseFactory
(
XModuleCourseFactory
):
FACTORY_FOR
=
Course
template
=
'i4x://edx/templates/course/Empty'
org
=
'MITx'
number
=
'999'
display_name
=
'Robot Super Course'
\ No newline at end of file
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