Commit 183f2f82 by Nimisha Asthagiri

fixup! split_test, user_partitions.

parent 57ed7983
""" """
Transformers helpers functions. Transformers helpers functions.
""" """
from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme
from openedx.core.djangoapps.course_groups.partition_scheme import CohortPartitionScheme
SCHEME_SUPPORTS_ASSIGNMENT = [RandomUserPartitionScheme, ]
def get_user_partition_groups(course_key, user_partitions, user): def get_user_partition_groups(course_key, user_partitions, user):
...@@ -28,7 +24,6 @@ def get_user_partition_groups(course_key, user_partitions, user): ...@@ -28,7 +24,6 @@ def get_user_partition_groups(course_key, user_partitions, user):
course_key, course_key,
user, user,
partition, partition,
**({'assign': False} if partition.scheme in SCHEME_SUPPORTS_ASSIGNMENT else {})
) )
if group is not None: if group is not None:
partition_groups[partition.id] = group partition_groups[partition.id] = group
......
...@@ -97,10 +97,9 @@ class CourseStructureTestCase(ModuleStoreTestCase): ...@@ -97,10 +97,9 @@ class CourseStructureTestCase(ModuleStoreTestCase):
xblocks = (self.blocks[ref] for ref in refs) xblocks = (self.blocks[ref] for ref in refs)
return set([xblock.location for xblock in xblocks]) return set([xblock.location for xblock in xblocks])
def assert_course_structure_staff_user(self, staff, course, blocks, transformer): def assert_staff_access_to_all_blocks(self, staff, course, blocks, transformer):
""" """
Assert course structure integrity if block structure has transformer applied Assert staff users have access to all blocks
and is viewed by staff user.
""" """
raw_block_structure = get_course_blocks( raw_block_structure = get_course_blocks(
staff, staff,
......
...@@ -155,9 +155,5 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase): ...@@ -155,9 +155,5 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
) )
) )
def test_course_structure_with_staff_user(self): def test_staff_user(self):
""" self.assert_staff_access_to_all_blocks(self.staff, self.course, self.blocks, self.transformer)
Test course structure integrity if block structure has transformer applied
and is viewed by staff user.
"""
self.assert_course_structure_staff_user(self.staff, self.course, self.blocks, self.transformer)
...@@ -118,38 +118,14 @@ class SplitTestTransformerTestCase(CourseStructureTestCase): ...@@ -118,38 +118,14 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
] ]
} }
def test_user_not_assigned(self): def test_user(self):
"""
Test when user is not assigned to any group in user partition.
"""
trans_block_structure = get_course_blocks(
self.user,
self.course.location,
transformers={self.transformer}
)
self.assertEqual(
set(trans_block_structure.get_block_keys()),
self.get_block_key_set('course', 'chapter1', 'lesson1', 'vertical1', 'split_test1')
)
def test_user_assigned(self):
"""
Test when user is assigned to any group in user partition.
"""
# Add user to split test.
self.split_test_user_partition.scheme.get_group_for_user(
CourseKey.from_string(unicode(self.course.id)),
self.user,
self.split_test_user_partition,
)
trans_block_structure = get_course_blocks( trans_block_structure = get_course_blocks(
self.user, self.user,
self.course.location, self.course.location,
transformers={self.transformer} transformers={self.transformer},
) )
# user was randomly assigned to one of the groups
user_groups = get_user_partition_groups( user_groups = get_user_partition_groups(
self.course.id, [self.split_test_user_partition], self.user self.course.id, [self.split_test_user_partition], self.user
) )
...@@ -164,9 +140,14 @@ class SplitTestTransformerTestCase(CourseStructureTestCase): ...@@ -164,9 +140,14 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
self.assertEqual(set(trans_block_structure.get_block_keys()), set(self.get_block_key_set(*expected_blocks))) self.assertEqual(set(trans_block_structure.get_block_keys()), set(self.get_block_key_set(*expected_blocks)))
def test_course_structure_with_staff_user(self): # calling again should result in the same block set
""" reloaded_structure = get_course_blocks(
Test course structure integrity if block structure has transformer applied self.user,
and is viewed by staff user. self.course.location,
""" transformers={self.transformer}
self.assert_course_structure_staff_user(self.staff, self.course, self.blocks, self.transformer) )
self.assertEqual(set(reloaded_structure.get_block_keys()), set(self.get_block_key_set(*expected_blocks)))
def test_staff_user(self):
self.assert_staff_access_to_all_blocks(self.staff, self.course, self.blocks, self.transformer)
...@@ -122,9 +122,5 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase): ...@@ -122,9 +122,5 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
self.get_block_key_set('course', 'chapter1', 'lesson1', 'vertical1', 'html2') self.get_block_key_set('course', 'chapter1', 'lesson1', 'vertical1', 'html2')
) )
def test_course_structure_with_staff_user(self): def test_staff_user(self):
""" self.assert_staff_access_to_all_blocks(self.staff, self.course, self.blocks, self.transformer)
Test course structure integrity if block structure has transformer applied
and is viewed by staff user.
"""
self.assert_course_structure_staff_user(self.staff, self.course, self.blocks, self.transformer)
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