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
d5d7d654
Commit
d5d7d654
authored
Sep 13, 2015
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixup! Split Test Transformer fixes.
parent
2021ba63
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
16 deletions
+62
-16
lms/djangoapps/course_blocks/api.py
+0
-1
lms/djangoapps/course_blocks/transformers/split_test.py
+2
-1
lms/djangoapps/course_blocks/transformers/tests/test_helpers.py
+44
-8
lms/djangoapps/course_blocks/transformers/tests/test_split_test.py
+0
-0
lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py
+16
-6
No files found.
lms/djangoapps/course_blocks/api.py
View file @
d5d7d654
...
...
@@ -10,7 +10,6 @@ from .transformers import (
start_date
,
user_partitions
,
visibility
,
split_test
,
library_content
,
)
from
.user_info
import
CourseUserInfo
...
...
lms/djangoapps/course_blocks/transformers/split_test.py
View file @
d5d7d654
...
...
@@ -46,7 +46,8 @@ class SplitTestTransformer(BlockStructureTransformer):
# set group access for each child
for
child_location
in
xblock
.
children
:
child
=
block_structure
.
get_xblock
(
child_location
)
child
.
group_access
[
partition_for_this_block
.
id
]
=
[
child_to_group
[
child_location
]]
group
=
child_to_group
.
get
(
child_location
,
None
)
child
.
group_access
[
partition_for_this_block
.
id
]
=
[
group
]
if
group
else
[]
def
transform
(
self
,
user_info
,
block_structure
):
"""
...
...
lms/djangoapps/course_blocks/transformers/tests/test_helpers.py
View file @
d5d7d654
...
...
@@ -25,6 +25,13 @@ class CourseStructureTestCase(ModuleStoreTestCase):
self
.
user
=
UserFactory
.
create
(
password
=
self
.
password
)
self
.
staff
=
UserFactory
.
create
(
password
=
self
.
password
,
is_staff
=
True
)
def
create_block_id
(
self
,
block_type
,
block_ref
):
"""
Returns the block id (display name) that is used in the test
course structures for the given block type and block reference string.
"""
return
'{}_{}'
.
format
(
block_type
,
block_ref
)
def
build_xblock
(
self
,
block_hierarchy
,
block_map
,
parent
):
"""
Build an XBlock, add it to block_map, and call build_xblock on the
...
...
@@ -47,7 +54,7 @@ class CourseStructureTestCase(ModuleStoreTestCase):
kwargs
[
'parent'
]
=
parent
xblock
=
factory
.
create
(
display_name
=
'{} {}'
.
format
(
block_type
,
block_ref
),
display_name
=
self
.
create_block_id
(
block_type
,
block_ref
),
publish_item
=
True
,
**
kwargs
)
...
...
@@ -63,15 +70,35 @@ class CourseStructureTestCase(ModuleStoreTestCase):
The additional parents are obtained from the '#parents' field
and is expected to be a list of '#ref' values of the parents.
Note: if a '#parents' field is found, the block is removed from
the course block since it is expected to not belong to the root.
If the block is meant to be a direct child of the course as well,
the course should be explicitly listed in '#parents'.
Arguments:
block_hierarchy (BlockStructureDict): Definition of block hierarchy.
block_map (dict[str: XBlock]): Mapping from '#ref' values to their XBlocks.
"""
parents
=
block_hierarchy
.
get
(
'#parents'
,
[])
for
parent_ref
in
parents
:
parent_block
=
block_map
[
parent_ref
]
parent_block
.
children
.
append
(
block_map
[
block_hierarchy
[
'#ref'
]]
.
location
)
update_block
(
parent_block
)
if
parents
:
block_key
=
block_map
[
block_hierarchy
[
'#ref'
]]
.
location
# First remove the block from the course.
# It would be re-added to the course if the course was
# explicitly listed in parents.
course
=
modulestore
()
.
get_item
(
block_map
[
'course'
]
.
location
)
course
.
children
.
remove
(
block_key
)
block_map
[
'course'
]
=
update_block
(
course
)
# Add this to block to each listed parent.
for
parent_ref
in
parents
:
parent_block
=
modulestore
()
.
get_item
(
block_map
[
parent_ref
]
.
location
)
parent_block
.
children
.
append
(
block_key
)
block_map
[
parent_ref
]
=
update_block
(
parent_block
)
# recursively call the children
for
child_hierarchy
in
block_hierarchy
.
get
(
'#children'
,
[]):
self
.
add_parents
(
child_hierarchy
,
block_map
)
...
...
@@ -278,3 +305,11 @@ def update_block(block):
Helper method to update the block in the modulestore
"""
return
modulestore
()
.
update_item
(
block
,
'test_user'
)
def
create_location
(
org
,
course
,
run
,
block_type
,
block_id
):
"""
Returns the usage key for the given key parameters using the
default modulestore
"""
return
modulestore
()
.
make_course_key
(
org
,
course
,
run
)
.
make_usage_key
(
block_type
,
block_id
)
\ No newline at end of file
lms/djangoapps/course_blocks/transformers/tests/test_split_test.py
View file @
d5d7d654
This diff is collapsed.
Click to expand it.
lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py
View file @
d5d7d654
...
...
@@ -2,6 +2,8 @@
Tests for UserPartitionTransformer.
"""
import
ddt
from
openedx.core.djangoapps.course_groups.partition_scheme
import
CohortPartitionScheme
from
openedx.core.djangoapps.course_groups.tests.helpers
import
CohortFactory
,
config_course_cohorts
from
openedx.core.djangoapps.course_groups.cohorts
import
add_user_to_cohort
...
...
@@ -10,10 +12,11 @@ from student.tests.factories import CourseEnrollmentFactory
from
xmodule.partitions.partitions
import
Group
,
UserPartition
from
course_blocks.transformers.user_partitions
import
UserPartitionTransformer
from
course_blocks.api
import
get_course_blocks
,
clear_course_from_cache
from
course_blocks.api
import
get_course_blocks
from
lms.djangoapps.course_blocks.transformers.tests.test_helpers
import
CourseStructureTestCase
@ddt.ddt
class
UserPartitionTransformerTestCase
(
CourseStructureTestCase
):
"""
UserPartitionTransformer Test
...
...
@@ -57,8 +60,6 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
group
.
id
,
)
add_user_to_cohort
(
self
.
cohorts
[
0
],
self
.
user
.
username
)
self
.
transformer
=
UserPartitionTransformer
()
def
get_course_hierarchy
(
self
):
...
...
@@ -159,11 +160,20 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
},
]
def
test_user_assigned
(
self
):
@ddt.data
(
(
None
,
(
'course'
,
'B'
,
'O'
)),
(
1
,
(
'course'
,
'A'
,
'B'
,
'C'
,
'E'
,
'F'
,
'G'
,
'J'
,
'L'
,
'M'
,
'O'
)),
(
2
,
(
'course'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
,
'H'
,
'I'
,
'J'
,
'M'
,
'O'
)),
(
3
,
(
'course'
,
'A'
,
'B'
,
'D'
,
'E'
,
'I'
,
'J'
,
'O'
)),
(
4
,
(
'course'
,
'B'
,
'O'
)),
)
@ddt.unpack
def
test_user_assigned
(
self
,
group_id
,
expected_blocks
):
"""
Test when user is assigned to group in user partition.
"""
# TODO ddt with testing user in different groups
if
group_id
:
add_user_to_cohort
(
self
.
cohorts
[
group_id
-
1
],
self
.
user
.
username
)
trans_block_structure
=
get_course_blocks
(
self
.
user
,
...
...
@@ -172,7 +182,7 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
)
self
.
assertSetEqual
(
set
(
trans_block_structure
.
get_block_keys
()),
self
.
get_block_key_set
(
self
.
blocks
,
'course'
,
'A'
,
'B'
,
'C'
,
'E'
,
'F'
,
'G'
,
'J'
,
'L'
,
'M'
,
'O'
)
self
.
get_block_key_set
(
self
.
blocks
,
*
expected_blocks
)
)
def
test_staff_user
(
self
):
...
...
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