Commit b7c4ada9 by Nimisha Asthagiri

fixup! course_blocks unit tests

parent a47f86e5
......@@ -23,26 +23,32 @@ LMS_COURSE_TRANSFORMERS = [
]
_cache = None
_COURSE_BLOCKS_CACHE = None
def _get_cache():
global _cache
if not _cache:
_cache = get_cache('lms.course_blocks')
return _cache
global _COURSE_BLOCKS_CACHE
if not _COURSE_BLOCKS_CACHE:
_COURSE_BLOCKS_CACHE = get_cache('lms.course_blocks')
return _COURSE_BLOCKS_CACHE
def get_course_blocks(
user,
root_usage_key,
transformers=LMS_COURSE_TRANSFORMERS,
root_usage_key=None,
course_key=None,
transformers=None,
):
store = modulestore()
if transformers is None:
transformers = LMS_COURSE_TRANSFORMERS
if root_usage_key is None:
root_usage_key = store.make_course_usage_key(course_key)
return get_blocks(
_get_cache(), modulestore(), CourseUserInfo(root_usage_key.course_key, user), root_usage_key, transformers,
_get_cache(), store, CourseUserInfo(root_usage_key.course_key, user), root_usage_key, transformers,
)
......
......@@ -97,7 +97,6 @@ class ContentLibraryTransformer(BlockStructureTransformer):
selected_children.append(usage_key)
# Check and remove all non-selected children from course structure.
if not user_info.has_staff_access:
block_structure.remove_block_if(
check_child_removal
)
......@@ -160,17 +160,6 @@ class CourseStructureTestCase(ModuleStoreTestCase):
xblocks = (blocks[ref] for ref in refs)
return set([xblock.location for xblock in xblocks])
def assert_staff_access_to_all_blocks(self, course, blocks, transformer):
"""
Assert staff users have access to all blocks
"""
trans_block_structure = get_course_blocks(
self.staff,
course.location,
transformers={transformer}
)
self.assertEqual(len(list(trans_block_structure.get_block_keys())), len(blocks))
class BlockParentsMapTestCase(ModuleStoreTestCase):
"""
......
......@@ -156,6 +156,3 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
'html1'
)
)
def test_staff_user(self):
self.assert_staff_access_to_all_blocks(self.course, self.blocks, self.transformer)
......@@ -214,13 +214,13 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
self.course.location,
transformers={self.transformer},
)
# with check_mongo_calls(0): TODO - debug issue with pickling
# block_structure2 = get_course_blocks(
# self.user,
# self.course.location,
# transformers={self.transformer},
# )
# self.assertEqual(
# set(block_structure1.get_block_keys()),
# set(block_structure2.get_block_keys()),
# )
with check_mongo_calls(0):
block_structure2 = get_course_blocks(
self.user,
self.course.location,
transformers={self.transformer},
)
self.assertEqual(
set(block_structure1.get_block_keys()),
set(block_structure2.get_block_keys()),
)
......@@ -184,6 +184,3 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
set(trans_block_structure.get_block_keys()),
self.get_block_key_set(self.blocks, *expected_blocks)
)
def test_staff_user(self):
self.assert_staff_access_to_all_blocks(self.course, self.blocks, self.transformer)
......@@ -195,13 +195,12 @@ class UserPartitionTransformer(BlockStructureTransformer):
user_partitions = block_structure.get_transformer_data(self, 'user_partitions')
if not user_partitions or user_info.has_staff_access:
if not user_partitions:
return
user_groups = get_user_partition_groups(
user_info.course_key, user_partitions, user_info.user
)
# TODO test this when deserializing across processes
block_structure.remove_block_if(
lambda block_key: not block_structure.get_transformer_block_data(
block_key, self, 'merged_group_access'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment