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
4c286840
Commit
4c286840
authored
Aug 16, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pass xblock fields as top-level keywords on factories
parent
69a06833
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
39 deletions
+16
-39
cms/djangoapps/contentstore/tests/test_crud.py
+2
-2
common/lib/xmodule/xmodule/modulestore/tests/persistent_factories.py
+14
-37
No files found.
cms/djangoapps/contentstore/tests/test_crud.py
View file @
4c286840
...
...
@@ -151,7 +151,7 @@ class TemplateTests(unittest.TestCase):
parent_location
=
chapter
.
location
,
user_id
=
'testbot'
,
category
=
'vertical'
)
first_problem
=
persistent_factories
.
ItemFactory
.
create
(
display_name
=
'problem 1'
,
parent_location
=
sub
.
location
,
user_id
=
'testbot'
,
category
=
'problem'
,
fields
=
{
'data'
:
"<problem></problem>"
}
data
=
"<problem></problem>"
)
first_problem
.
max_attempts
=
3
first_problem
.
save
()
# decache the above into the kvs
...
...
@@ -165,7 +165,7 @@ class TemplateTests(unittest.TestCase):
display_name
=
'problem 2'
,
parent_location
=
BlockUsageLocator
(
updated_loc
,
usage_id
=
sub
.
location
.
usage_id
),
user_id
=
'testbot'
,
category
=
'problem'
,
fields
=
{
'data'
:
"<problem></problem>"
}
data
=
"<problem></problem>"
)
# course root only updated 2x
...
...
common/lib/xmodule/xmodule/modulestore/tests/persistent_factories.py
View file @
4c286840
...
...
@@ -11,38 +11,24 @@ class PersistentCourseFactory(factory.Factory):
"""
Create a new course (not a new version of a course, but a whole new index entry).
keywords:
keywords: any xblock field plus (note, the below are filtered out; so, if they
become legitimate xblock fields, they won't be settable via this factory)
* org: defaults to textX
* prettyid: defaults to 999
* display_name
* user_id
* fields (optional) the settings and content payloads. If display_name is in the metadata, that takes
precedence over any display_name provided directly.
* master_branch: (optional) defaults to 'draft'
* user_id: (optional) defaults to 'test_user'
* display_name (xblock field): will default to 'Robot Super Course' unless provided
"""
FACTORY_FOR
=
CourseDescriptor
org
=
'testX'
prettyid
=
'999'
display_name
=
'Robot Super Course'
user_id
=
"test_user"
master_branch
=
'draft'
# pylint: disable=W0613
@classmethod
def
_create
(
cls
,
target_class
,
*
args
,
**
kwargs
):
org
=
kwargs
.
get
(
'org'
)
prettyid
=
kwargs
.
get
(
'prettyid'
)
display_name
=
kwargs
.
get
(
'display_name'
)
user_id
=
kwargs
.
get
(
'user_id'
)
fields
=
kwargs
.
get
(
'fields'
,
{})
if
display_name
and
'display_name'
not
in
fields
:
fields
[
'display_name'
]
=
display_name
def
_create
(
cls
,
target_class
,
org
=
'testX'
,
prettyid
=
'999'
,
user_id
=
'test_user'
,
master_branch
=
'draft'
,
**
kwargs
):
# Write the data to the mongo datastore
new_course
=
modulestore
(
'split'
)
.
create_course
(
org
,
prettyid
,
user_id
,
fields
=
field
s
,
id_root
=
prettyid
,
master_branch
=
kwargs
.
get
(
'master_branch'
)
)
org
,
prettyid
,
user_id
,
fields
=
kwarg
s
,
id_root
=
prettyid
,
master_branch
=
master_branch
)
return
new_course
...
...
@@ -54,33 +40,24 @@ class PersistentCourseFactory(factory.Factory):
class
ItemFactory
(
factory
.
Factory
):
FACTORY_FOR
=
XModuleDescriptor
category
=
'chapter'
user_id
=
'test_user'
display_name
=
factory
.
LazyAttributeSequence
(
lambda
o
,
n
:
"{} {}"
.
format
(
o
.
category
,
n
))
# pylint: disable=W0613
@classmethod
def
_create
(
cls
,
target_class
,
*
args
,
**
kwargs
):
def
_create
(
cls
,
target_class
,
parent_location
,
category
=
'chapter'
,
user_id
=
'test_user'
,
definition_locator
=
None
,
**
kwargs
):
"""
Uses *kwargs*
:
passes *kwargs* as the new item's field values
:
:param parent_location: (required) the location of the course & possibly parent
:param category: (defaults to 'chapter')
:param fields: (optional) the data for the item
:param definition_locator (optional): the DescriptorLocator for the definition this uses or branches
:param display_name (optional): the display name of the item
"""
fields
=
kwargs
.
get
(
'fields'
,
{})
if
'display_name'
not
in
fields
and
'display_name'
in
kwargs
:
fields
[
'display_name'
]
=
kwargs
[
'display_name'
]
return
modulestore
(
'split'
)
.
create_item
(
kwargs
[
'parent_location'
],
kwargs
[
'category'
],
kwargs
[
'user_id'
],
definition_locator
=
kwargs
.
get
(
'definition_locator'
),
fields
=
fields
)
return
modulestore
(
'split'
)
.
create_item
(
parent_location
,
category
,
user_id
,
definition_locator
,
fields
=
kwargs
)
@classmethod
def
_build
(
cls
,
target_class
,
*
args
,
**
kwargs
):
...
...
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