Commit 183f2f82 by Nimisha Asthagiri

fixup! split_test, user_partitions.

parent 57ed7983
"""
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):
......@@ -28,7 +24,6 @@ def get_user_partition_groups(course_key, user_partitions, user):
course_key,
user,
partition,
**({'assign': False} if partition.scheme in SCHEME_SUPPORTS_ASSIGNMENT else {})
)
if group is not None:
partition_groups[partition.id] = group
......
......@@ -97,10 +97,9 @@ class CourseStructureTestCase(ModuleStoreTestCase):
xblocks = (self.blocks[ref] for ref in refs)
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
and is viewed by staff user.
Assert staff users have access to all blocks
"""
raw_block_structure = get_course_blocks(
staff,
......
......@@ -155,9 +155,5 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
)
)
def test_course_structure_with_staff_user(self):
"""
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)
def test_staff_user(self):
self.assert_staff_access_to_all_blocks(self.staff, self.course, self.blocks, self.transformer)
......@@ -118,38 +118,14 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
]
}
def test_user_not_assigned(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,
)
def test_user(self):
trans_block_structure = get_course_blocks(
self.user,
self.course.location,
transformers={self.transformer}
transformers={self.transformer},
)
# user was randomly assigned to one of the groups
user_groups = get_user_partition_groups(
self.course.id, [self.split_test_user_partition], self.user
)
......@@ -164,9 +140,14 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
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):
"""
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)
# calling again should result in the same block set
reloaded_structure = get_course_blocks(
self.user,
self.course.location,
transformers={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):
self.get_block_key_set('course', 'chapter1', 'lesson1', 'vertical1', 'html2')
)
def test_course_structure_with_staff_user(self):
"""
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)
def test_staff_user(self):
self.assert_staff_access_to_all_blocks(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