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
5b0d150f
Commit
5b0d150f
authored
Jan 26, 2015
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update to work with split_modulestore.
Cannot hold on to xblock references.
parent
6272817c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
61 deletions
+54
-61
lms/lib/xblock/test/test_mixin.py
+54
-61
No files found.
lms/lib/xblock/test/test_mixin.py
View file @
5b0d150f
...
@@ -34,10 +34,22 @@ class LmsXBlockMixinTestCase(ModuleStoreTestCase):
...
@@ -34,10 +34,22 @@ class LmsXBlockMixinTestCase(ModuleStoreTestCase):
self
.
group1
=
self
.
user_partition
.
groups
[
0
]
# pylint: disable=no-member
self
.
group1
=
self
.
user_partition
.
groups
[
0
]
# pylint: disable=no-member
self
.
group2
=
self
.
user_partition
.
groups
[
1
]
# pylint: disable=no-member
self
.
group2
=
self
.
user_partition
.
groups
[
1
]
# pylint: disable=no-member
self
.
course
=
CourseFactory
.
create
(
user_partitions
=
[
self
.
user_partition
])
self
.
course
=
CourseFactory
.
create
(
user_partitions
=
[
self
.
user_partition
])
self
.
section
=
ItemFactory
.
create
(
parent
=
self
.
course
,
category
=
'chapter'
,
display_name
=
'Test Section'
)
section
=
ItemFactory
.
create
(
parent
=
self
.
course
,
category
=
'chapter'
,
display_name
=
'Test Section'
)
self
.
subsection
=
ItemFactory
.
create
(
parent
=
self
.
section
,
category
=
'sequential'
,
display_name
=
'Test Subsection'
)
subsection
=
ItemFactory
.
create
(
parent
=
section
,
category
=
'sequential'
,
display_name
=
'Test Subsection'
)
self
.
vertical
=
ItemFactory
.
create
(
parent
=
self
.
subsection
,
category
=
'vertical'
,
display_name
=
'Test Unit'
)
vertical
=
ItemFactory
.
create
(
parent
=
subsection
,
category
=
'vertical'
,
display_name
=
'Test Unit'
)
self
.
video
=
ItemFactory
.
create
(
parent
=
self
.
vertical
,
category
=
'video'
,
display_name
=
'Test Video 1'
)
video
=
ItemFactory
.
create
(
parent
=
vertical
,
category
=
'video'
,
display_name
=
'Test Video 1'
)
self
.
section_location
=
section
.
location
self
.
subsection_location
=
subsection
.
location
self
.
vertical_location
=
vertical
.
location
self
.
video_location
=
video
.
location
def
set_group_access
(
self
,
block_location
,
access_dict
):
"""
Sets the group_access dict on the block referenced by block_location.
"""
block
=
self
.
store
.
get_item
(
block_location
)
block
.
group_access
=
access_dict
self
.
store
.
update_item
(
block
,
1
)
class
XBlockValidationTest
(
LmsXBlockMixinTestCase
):
class
XBlockValidationTest
(
LmsXBlockMixinTestCase
):
...
@@ -59,23 +71,23 @@ class XBlockValidationTest(LmsXBlockMixinTestCase):
...
@@ -59,23 +71,23 @@ class XBlockValidationTest(LmsXBlockMixinTestCase):
"""
"""
Test the validation messages produced for an xblock with full group access.
Test the validation messages produced for an xblock with full group access.
"""
"""
validation
=
self
.
video
.
validate
()
validation
=
self
.
store
.
get_item
(
self
.
video_location
)
.
validate
()
self
.
assertEqual
(
len
(
validation
.
messages
),
0
)
self
.
assertEqual
(
len
(
validation
.
messages
),
0
)
def
test_validate_restricted_group_access
(
self
):
def
test_validate_restricted_group_access
(
self
):
"""
"""
Test the validation messages produced for an xblock with a valid group access restriction
Test the validation messages produced for an xblock with a valid group access restriction
"""
"""
self
.
video
.
group_access
[
self
.
user_partition
.
id
]
=
[
self
.
group1
.
id
,
self
.
group2
.
id
]
# pylint: disable=no-member
self
.
set_group_access
(
self
.
video_location
,
{
self
.
user_partition
.
id
:
[
self
.
group1
.
id
,
self
.
group2
.
id
]})
validation
=
self
.
video
.
validate
()
validation
=
self
.
store
.
get_item
(
self
.
video_location
)
.
validate
()
self
.
assertEqual
(
len
(
validation
.
messages
),
0
)
self
.
assertEqual
(
len
(
validation
.
messages
),
0
)
def
test_validate_invalid_user_partitions
(
self
):
def
test_validate_invalid_user_partitions
(
self
):
"""
"""
Test the validation messages produced for an xblock referring to non-existent user partitions.
Test the validation messages produced for an xblock referring to non-existent user partitions.
"""
"""
self
.
video
.
group_access
[
999
]
=
[
self
.
group1
.
id
]
self
.
set_group_access
(
self
.
video_location
,
{
999
:
[
self
.
group1
.
id
]})
validation
=
self
.
video
.
validate
()
validation
=
self
.
store
.
get_item
(
self
.
video_location
)
.
validate
()
self
.
assertEqual
(
len
(
validation
.
messages
),
1
)
self
.
assertEqual
(
len
(
validation
.
messages
),
1
)
self
.
verify_validation_message
(
self
.
verify_validation_message
(
validation
.
messages
[
0
],
validation
.
messages
[
0
],
...
@@ -86,8 +98,8 @@ class XBlockValidationTest(LmsXBlockMixinTestCase):
...
@@ -86,8 +98,8 @@ class XBlockValidationTest(LmsXBlockMixinTestCase):
# Now add a second invalid user partition and validate again.
# Now add a second invalid user partition and validate again.
# Note that even though there are two invalid configurations,
# Note that even though there are two invalid configurations,
# only a single error message will be returned.
# only a single error message will be returned.
self
.
video
.
group_access
[
998
]
=
[
self
.
group2
.
id
]
self
.
set_group_access
(
self
.
video_location
,
{
998
:
[
self
.
group2
.
id
]})
validation
=
self
.
video
.
validate
()
validation
=
self
.
store
.
get_item
(
self
.
video_location
)
.
validate
()
self
.
assertEqual
(
len
(
validation
.
messages
),
1
)
self
.
assertEqual
(
len
(
validation
.
messages
),
1
)
self
.
verify_validation_message
(
self
.
verify_validation_message
(
validation
.
messages
[
0
],
validation
.
messages
[
0
],
...
@@ -99,8 +111,8 @@ class XBlockValidationTest(LmsXBlockMixinTestCase):
...
@@ -99,8 +111,8 @@ class XBlockValidationTest(LmsXBlockMixinTestCase):
"""
"""
Test the validation messages produced for an xblock referring to non-existent groups.
Test the validation messages produced for an xblock referring to non-existent groups.
"""
"""
self
.
video
.
group_access
[
self
.
user_partition
.
id
]
=
[
self
.
group1
.
id
,
999
]
# pylint: disable=no-member
self
.
set_group_access
(
self
.
video_location
,
{
self
.
user_partition
.
id
:
[
self
.
group1
.
id
,
999
]})
validation
=
self
.
video
.
validate
()
validation
=
self
.
store
.
get_item
(
self
.
video_location
)
.
validate
()
self
.
assertEqual
(
len
(
validation
.
messages
),
1
)
self
.
assertEqual
(
len
(
validation
.
messages
),
1
)
self
.
verify_validation_message
(
self
.
verify_validation_message
(
validation
.
messages
[
0
],
validation
.
messages
[
0
],
...
@@ -109,8 +121,8 @@ class XBlockValidationTest(LmsXBlockMixinTestCase):
...
@@ -109,8 +121,8 @@ class XBlockValidationTest(LmsXBlockMixinTestCase):
)
)
# Now try again with two invalid group ids
# Now try again with two invalid group ids
self
.
video
.
group_access
[
self
.
user_partition
.
id
]
=
[
self
.
group1
.
id
,
998
,
999
]
# pylint: disable=no-member
self
.
set_group_access
(
self
.
video_location
,
{
self
.
user_partition
.
id
:
[
self
.
group1
.
id
,
998
,
999
]})
validation
=
self
.
video
.
validate
()
validation
=
self
.
store
.
get_item
(
self
.
video_location
)
.
validate
()
self
.
assertEqual
(
len
(
validation
.
messages
),
1
)
self
.
assertEqual
(
len
(
validation
.
messages
),
1
)
self
.
verify_validation_message
(
self
.
verify_validation_message
(
validation
.
messages
[
0
],
validation
.
messages
[
0
],
...
@@ -184,10 +196,11 @@ class XBlockGetParentTest(LmsXBlockMixinTestCase):
...
@@ -184,10 +196,11 @@ class XBlockGetParentTest(LmsXBlockMixinTestCase):
# move the video to the new vertical
# move the video to the new vertical
with
self
.
store
.
default_store
(
modulestore_type
):
with
self
.
store
.
default_store
(
modulestore_type
):
self
.
build_course
()
self
.
build_course
()
new_vertical
=
ItemFactory
.
create
(
parent
=
self
.
subsection
,
category
=
'vertical'
,
display_name
=
'New Test Unit'
)
subsection
=
self
.
store
.
get_item
(
self
.
subsection_location
)
child_to_move_location
=
self
.
video
.
location
.
for_branch
(
None
)
new_vertical
=
ItemFactory
.
create
(
parent
=
subsection
,
category
=
'vertical'
,
display_name
=
'New Test Unit'
)
child_to_move_location
=
self
.
video_location
.
for_branch
(
None
)
new_parent_location
=
new_vertical
.
location
.
for_branch
(
None
)
new_parent_location
=
new_vertical
.
location
.
for_branch
(
None
)
old_parent_location
=
self
.
vertical
.
location
.
for_branch
(
None
)
old_parent_location
=
self
.
vertical
_
location
.
for_branch
(
None
)
with
self
.
store
.
branch_setting
(
ModuleStoreEnum
.
Branch
.
draft_preferred
):
with
self
.
store
.
branch_setting
(
ModuleStoreEnum
.
Branch
.
draft_preferred
):
self
.
assertIsNone
(
self
.
course
.
get_parent
())
self
.
assertIsNone
(
self
.
course
.
get_parent
())
...
@@ -252,23 +265,23 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
...
@@ -252,23 +265,23 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
PARTITION_2_GROUP_2
=
22
PARTITION_2_GROUP_2
=
22
PARENT_CHILD_PAIRS
=
(
PARENT_CHILD_PAIRS
=
(
ddt_named
(
'section
'
,
'subsec
tion'
),
ddt_named
(
'section
_location'
,
'subsection_loca
tion'
),
ddt_named
(
'section
'
,
'vertical
'
),
ddt_named
(
'section
_location'
,
'vertical_location
'
),
ddt_named
(
'section
'
,
'video
'
),
ddt_named
(
'section
_location'
,
'video_location
'
),
ddt_named
(
'subsection
'
,
'vertical
'
),
ddt_named
(
'subsection
_location'
,
'vertical_location
'
),
ddt_named
(
'subsection
'
,
'video
'
),
ddt_named
(
'subsection
_location'
,
'video_location
'
),
)
)
def
setUp
(
self
):
def
setUp
(
self
):
super
(
XBlockMergedGroupAccessTest
,
self
)
.
setUp
()
super
(
XBlockMergedGroupAccessTest
,
self
)
.
setUp
()
self
.
build_course
()
self
.
build_course
()
def
set_group_access
(
self
,
block
,
access
_dict
):
def
verify_group_access
(
self
,
block_location
,
expected
_dict
):
"""
"""
DRY helper
.
Verify the expected value for the block's group_access
.
"""
"""
block
.
group_access
=
access_dict
block
=
self
.
store
.
get_item
(
block_location
)
block
.
runtime
.
modulestore
.
update_item
(
block
,
1
)
self
.
assertEqual
(
block
.
merged_group_access
,
expected_dict
)
@ddt.data
(
*
PARENT_CHILD_PAIRS
)
@ddt.data
(
*
PARENT_CHILD_PAIRS
)
@ddt.unpack
@ddt.unpack
...
@@ -284,14 +297,8 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
...
@@ -284,14 +297,8 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
self
.
set_group_access
(
parent_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
,
self
.
PARTITION_1_GROUP_2
]})
self
.
set_group_access
(
parent_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
,
self
.
PARTITION_1_GROUP_2
]})
self
.
set_group_access
(
child_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_2
]})
self
.
set_group_access
(
child_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_2
]})
self
.
assertEqual
(
self
.
verify_group_access
(
parent_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
,
self
.
PARTITION_1_GROUP_2
]})
parent_block
.
merged_group_access
,
self
.
verify_group_access
(
child_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_2
]})
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
,
self
.
PARTITION_1_GROUP_2
]},
)
self
.
assertEqual
(
child_block
.
merged_group_access
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_2
]},
)
@ddt.data
(
*
PARENT_CHILD_PAIRS
)
@ddt.data
(
*
PARENT_CHILD_PAIRS
)
@ddt.unpack
@ddt.unpack
...
@@ -306,14 +313,8 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
...
@@ -306,14 +313,8 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
self
.
set_group_access
(
parent_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]})
self
.
set_group_access
(
parent_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]})
self
.
set_group_access
(
child_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_2
]})
self
.
set_group_access
(
child_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_2
]})
self
.
assertEqual
(
self
.
verify_group_access
(
parent_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]})
parent_block
.
merged_group_access
,
self
.
verify_group_access
(
child_block
,
{
self
.
PARTITION_1
:
False
})
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]},
)
self
.
assertEqual
(
child_block
.
merged_group_access
,
{
self
.
PARTITION_1
:
False
},
)
def
test_disjoint_groups_no_override
(
self
):
def
test_disjoint_groups_no_override
(
self
):
"""
"""
...
@@ -321,19 +322,15 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
...
@@ -321,19 +322,15 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
to the block being queried even if blocks further down in the hierarchy
to the block being queried even if blocks further down in the hierarchy
try to override it.
try to override it.
"""
"""
self
.
set_group_access
(
self
.
section
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]})
self
.
set_group_access
(
self
.
section_location
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]})
self
.
set_group_access
(
self
.
subsection
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_2
]})
self
.
set_group_access
(
self
.
subsection_location
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_2
]})
self
.
set_group_access
(
self
.
vertical
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
,
self
.
PARTITION_1_GROUP_2
]})
self
.
set_group_access
(
self
.
vertical_location
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
,
self
.
PARTITION_1_GROUP_2
]}
self
.
assertEqual
(
self
.
vertical
.
merged_group_access
,
{
self
.
PARTITION_1
:
False
},
)
self
.
assertEqual
(
self
.
video
.
merged_group_access
,
{
self
.
PARTITION_1
:
False
},
)
)
self
.
verify_group_access
(
self
.
vertical_location
,
{
self
.
PARTITION_1
:
False
})
self
.
verify_group_access
(
self
.
video_location
,
{
self
.
PARTITION_1
:
False
})
@ddt.data
(
*
PARENT_CHILD_PAIRS
)
@ddt.data
(
*
PARENT_CHILD_PAIRS
)
@ddt.unpack
@ddt.unpack
def
test_union_partitions
(
self
,
parent
,
child
):
def
test_union_partitions
(
self
,
parent
,
child
):
...
@@ -348,11 +345,7 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
...
@@ -348,11 +345,7 @@ class XBlockMergedGroupAccessTest(LmsXBlockMixinTestCase):
self
.
set_group_access
(
parent_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]})
self
.
set_group_access
(
parent_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]})
self
.
set_group_access
(
child_block
,
{
self
.
PARTITION_2
:
[
self
.
PARTITION_1_GROUP_2
]})
self
.
set_group_access
(
child_block
,
{
self
.
PARTITION_2
:
[
self
.
PARTITION_1_GROUP_2
]})
self
.
assertEqual
(
self
.
verify_group_access
(
parent_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]})
parent_block
.
merged_group_access
,
self
.
verify_group_access
(
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
]},
child_block
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
],
self
.
PARTITION_2
:
[
self
.
PARTITION_1_GROUP_2
]}
)
self
.
assertEqual
(
child_block
.
merged_group_access
,
{
self
.
PARTITION_1
:
[
self
.
PARTITION_1_GROUP_1
],
self
.
PARTITION_2
:
[
self
.
PARTITION_1_GROUP_2
]},
)
)
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