Commit 57ed7983 by Nimisha Asthagiri

fixup! SplitTest and UserPartitions.

parent 6c602dee
...@@ -45,10 +45,10 @@ class SplitTestTransformer(BlockStructureTransformer): ...@@ -45,10 +45,10 @@ class SplitTestTransformer(BlockStructureTransformer):
user_partitions = getattr(xblock, 'user_partitions', []) user_partitions = getattr(xblock, 'user_partitions', [])
split_test_partitions = getattr(xblock, 'split_test_partition', []) or [] split_test_partitions = getattr(xblock, 'split_test_partition', []) or []
# For each block, check if there is an split_test block. # For each block, check if it is a split_test block.
# If split_test is found, check it's user_partition value and get children. # If split_test is found, check its user_partition value and get children.
# Set split_test_group on each of the children for fast retrival in transform phase. # Set split_test_group on each of the children for fast retrieval in transform phase.
# Add same group to childrens children, because due to structure restrictions first level # Add same group to children's children, because due to structure restrictions first level
# children are verticals. # children are verticals.
for block_key in block_structure.topological_traversal(): for block_key in block_structure.topological_traversal():
xblock = block_structure.get_xblock(block_key) xblock = block_structure.get_xblock(block_key)
...@@ -96,11 +96,11 @@ class SplitTestTransformer(BlockStructureTransformer): ...@@ -96,11 +96,11 @@ class SplitTestTransformer(BlockStructureTransformer):
if not user_partitions: if not user_partitions:
return return
user_groups = get_user_partition_groups(
user_info.course_key, user_partitions, user_info.user
)
if not user_info.has_staff_access: if not user_info.has_staff_access:
user_groups = get_user_partition_groups(
user_info.course_key, user_partitions, user_info.user
)
block_structure.remove_block_if( block_structure.remove_block_if(
lambda block_key: not SplitTestTransformer.check_split_access( lambda block_key: not SplitTestTransformer.check_split_access(
block_structure.get_transformer_block_data( block_structure.get_transformer_block_data(
......
...@@ -4,7 +4,6 @@ Tests for SplitTestTransformer. ...@@ -4,7 +4,6 @@ Tests for SplitTestTransformer.
from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from student.tests.factories import CourseEnrollmentFactory from student.tests.factories import CourseEnrollmentFactory
from xmodule.modulestore.django import modulestore
from xmodule.partitions.partitions import Group, UserPartition from xmodule.partitions.partitions import Group, UserPartition
from course_blocks.transformers.split_test import SplitTestTransformer from course_blocks.transformers.split_test import SplitTestTransformer
...@@ -27,8 +26,9 @@ class SplitTestTransformerTestCase(CourseStructureTestCase): ...@@ -27,8 +26,9 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
# Set up user partitions and groups. # Set up user partitions and groups.
self.groups = [Group(3, 'Group A'), Group(4, 'Group B')] self.groups = [Group(3, 'Group A'), Group(4, 'Group B')]
self.content_groups = [3, 4] self.content_groups = [3, 4]
self.split_test_user_partition_id = 0
self.split_test_user_partition = UserPartition( self.split_test_user_partition = UserPartition(
id=0, id=self.split_test_user_partition_id,
name='Partition 2', name='Partition 2',
description='This is partition 2', description='This is partition 2',
groups=self.groups, groups=self.groups,
...@@ -40,7 +40,6 @@ class SplitTestTransformerTestCase(CourseStructureTestCase): ...@@ -40,7 +40,6 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
self.course_hierarchy = self.get_course_hierarchy() self.course_hierarchy = self.get_course_hierarchy()
self.blocks = self.build_course(self.course_hierarchy) self.blocks = self.build_course(self.course_hierarchy)
self.course = self.blocks['course'] self.course = self.blocks['course']
clear_course_from_cache(self.course.id)
# Enroll user in course. # Enroll user in course.
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True) CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True)
...@@ -119,37 +118,10 @@ class SplitTestTransformerTestCase(CourseStructureTestCase): ...@@ -119,37 +118,10 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
] ]
} }
def add_user_to_splittest_group(self, assign=True): def test_user_not_assigned(self):
""" """
Add user to split test, get group for him and update blocks. Test when user is not assigned to any group in user partition.
""" """
self.split_test_user_partition.scheme.get_group_for_user(
CourseKey.from_string(unicode(self.course.id)),
self.user,
self.split_test_user_partition,
assign=assign,
)
store = modulestore()
for __, block in self.blocks.iteritems():
block.save()
store.update_item(block, self.user.id)
def test_course_structure_with_user_split_test(self):
"""
Test course structure integrity if course has split test section
and user is not assigned to any group in user partition.
"""
# Add user to split test.
self.add_user_to_splittest_group(assign=False)
raw_block_structure = get_course_blocks(
self.user,
self.course.location,
transformers={}
)
self.assertEqual(len(list(raw_block_structure.get_block_keys())), len(self.blocks))
clear_course_from_cache(self.course.id)
trans_block_structure = get_course_blocks( trans_block_structure = get_course_blocks(
self.user, self.user,
self.course.location, self.course.location,
...@@ -161,22 +133,17 @@ class SplitTestTransformerTestCase(CourseStructureTestCase): ...@@ -161,22 +133,17 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
self.get_block_key_set('course', 'chapter1', 'lesson1', 'vertical1', 'split_test1') self.get_block_key_set('course', 'chapter1', 'lesson1', 'vertical1', 'split_test1')
) )
def test_course_structure_with_user_split_test_group_assigned(self): def test_user_assigned(self):
""" """
Test course structure integrity if course has split test section Test when user is assigned to any group in user partition.
and user is assigned to any group in user partition.
""" """
# Add user to split test. # Add user to split test.
self.add_user_to_splittest_group() self.split_test_user_partition.scheme.get_group_for_user(
CourseKey.from_string(unicode(self.course.id)),
raw_block_structure = get_course_blocks(
self.user, self.user,
self.course.location, self.split_test_user_partition,
transformers={}
) )
self.assertEqual(len(list(raw_block_structure.get_block_keys())), len(self.blocks))
clear_course_from_cache(self.course.id)
trans_block_structure = get_course_blocks( trans_block_structure = get_course_blocks(
self.user, self.user,
self.course.location, self.course.location,
...@@ -186,33 +153,16 @@ class SplitTestTransformerTestCase(CourseStructureTestCase): ...@@ -186,33 +153,16 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
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
) )
for group in user_groups.itervalues(): self.assertEquals(len(user_groups), 1)
if group.id == 3: group = user_groups[self.split_test_user_partition_id]
self.assertEqual(
set(trans_block_structure.get_block_keys()), expected_blocks = ['course', 'chapter1', 'lesson1', 'vertical1', 'split_test1']
self.get_block_key_set( if group.id == 3:
'course', expected_blocks += ['vertical2', 'html1']
'chapter1', else:
'lesson1', expected_blocks += ['vertical3', 'html2']
'vertical1',
'split_test1', self.assertEqual(set(trans_block_structure.get_block_keys()), set(self.get_block_key_set(*expected_blocks)))
'vertical2',
'html1'
)
)
else:
self.assertEqual(
set(trans_block_structure.get_block_keys()),
self.get_block_key_set(
'course',
'chapter1',
'lesson1',
'vertical1',
'split_test1',
'vertical3',
'html2'
)
)
def test_course_structure_with_staff_user(self): def test_course_structure_with_staff_user(self):
""" """
......
...@@ -40,7 +40,6 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase): ...@@ -40,7 +40,6 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
self.course_hierarchy = self.get_course_hierarchy() self.course_hierarchy = self.get_course_hierarchy()
self.blocks = self.build_course(self.course_hierarchy) self.blocks = self.build_course(self.course_hierarchy)
self.course = self.blocks['course'] self.course = self.blocks['course']
clear_course_from_cache(self.course.id)
# Enroll user in course. # Enroll user in course.
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True) CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True)
...@@ -109,18 +108,10 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase): ...@@ -109,18 +108,10 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
group.id, group.id,
) )
def test_course_structure_with_user_partition(self): def test_user_assigned(self):
""" """
Test course structure integrity if course has user partition section Test when user is assigned to group in user partition.
and user is assigned to group in user partition.
""" """
raw_block_structure = get_course_blocks(
self.user,
self.course.location,
transformers={}
)
self.assertEqual(len(list(raw_block_structure.get_block_keys())), len(self.blocks))
trans_block_structure = get_course_blocks( trans_block_structure = get_course_blocks(
self.user, self.user,
self.course.location, self.course.location,
......
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