Commit b7c4ada9 by Nimisha Asthagiri

fixup! course_blocks unit tests

parent a47f86e5
...@@ -23,26 +23,32 @@ LMS_COURSE_TRANSFORMERS = [ ...@@ -23,26 +23,32 @@ LMS_COURSE_TRANSFORMERS = [
] ]
_cache = None _COURSE_BLOCKS_CACHE = None
def _get_cache(): def _get_cache():
global _cache global _COURSE_BLOCKS_CACHE
if not _cache: if not _COURSE_BLOCKS_CACHE:
_cache = get_cache('lms.course_blocks') _COURSE_BLOCKS_CACHE = get_cache('lms.course_blocks')
return _cache return _COURSE_BLOCKS_CACHE
def get_course_blocks( def get_course_blocks(
user, user,
root_usage_key, root_usage_key=None,
transformers=LMS_COURSE_TRANSFORMERS, course_key=None,
transformers=None,
): ):
store = modulestore()
if transformers is None: if transformers is None:
transformers = LMS_COURSE_TRANSFORMERS transformers = LMS_COURSE_TRANSFORMERS
if root_usage_key is None:
root_usage_key = store.make_course_usage_key(course_key)
return get_blocks( 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): ...@@ -97,7 +97,6 @@ class ContentLibraryTransformer(BlockStructureTransformer):
selected_children.append(usage_key) selected_children.append(usage_key)
# Check and remove all non-selected children from course structure. # Check and remove all non-selected children from course structure.
if not user_info.has_staff_access: block_structure.remove_block_if(
block_structure.remove_block_if( check_child_removal
check_child_removal )
)
...@@ -160,17 +160,6 @@ class CourseStructureTestCase(ModuleStoreTestCase): ...@@ -160,17 +160,6 @@ class CourseStructureTestCase(ModuleStoreTestCase):
xblocks = (blocks[ref] for ref in refs) xblocks = (blocks[ref] for ref in refs)
return set([xblock.location for xblock in xblocks]) 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): class BlockParentsMapTestCase(ModuleStoreTestCase):
""" """
......
...@@ -156,6 +156,3 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase): ...@@ -156,6 +156,3 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
'html1' '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): ...@@ -214,13 +214,13 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
self.course.location, self.course.location,
transformers={self.transformer}, transformers={self.transformer},
) )
# with check_mongo_calls(0): TODO - debug issue with pickling with check_mongo_calls(0):
# block_structure2 = get_course_blocks( block_structure2 = get_course_blocks(
# self.user, self.user,
# self.course.location, self.course.location,
# transformers={self.transformer}, transformers={self.transformer},
# ) )
# self.assertEqual( self.assertEqual(
# set(block_structure1.get_block_keys()), set(block_structure1.get_block_keys()),
# set(block_structure2.get_block_keys()), set(block_structure2.get_block_keys()),
# ) )
...@@ -184,6 +184,3 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase): ...@@ -184,6 +184,3 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
set(trans_block_structure.get_block_keys()), set(trans_block_structure.get_block_keys()),
self.get_block_key_set(self.blocks, *expected_blocks) 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): ...@@ -195,13 +195,12 @@ class UserPartitionTransformer(BlockStructureTransformer):
user_partitions = block_structure.get_transformer_data(self, 'user_partitions') 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 return
user_groups = get_user_partition_groups( user_groups = get_user_partition_groups(
user_info.course_key, user_partitions, user_info.user user_info.course_key, user_partitions, user_info.user
) )
# TODO test this when deserializing across processes
block_structure.remove_block_if( block_structure.remove_block_if(
lambda block_key: not block_structure.get_transformer_block_data( lambda block_key: not block_structure.get_transformer_block_data(
block_key, self, 'merged_group_access' 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