def create_user_partition_json(partition_id, name, description, groups, scheme="random"): """ Helper method to create user partition JSON. If scheme is not supplied, "random" is used. """ return UserPartition( partition_id, name, description, groups, MockUserPartitionScheme(scheme) ).to_json()
def setUp(self): super(SplitTestModuleTest, self).setUp() self.course_id = 'test_org/test_course_number/test_run' # construct module course = xml.CourseFactory.build() sequence = xml.SequenceFactory.build(parent=course) split_test = SplitTestModuleFactory( parent=sequence, attribs={ 'user_partition_id': '0', 'group_id_to_child': '{"0": "i4x://edX/xml_test_course/html/split_test_cond0", "1":' ' "i4x://edX/xml_test_course/html/split_test_cond1"}' } ) xml.HtmlFactory(parent=split_test, url_name='split_test_cond0', text='HTML FOR GROUP 0') xml.HtmlFactory(parent=split_test, url_name='split_test_cond1', text='HTML FOR GROUP 1') self.course = self.process_xml(course) self.course_sequence = self.course.get_children()[0] self.module_system = get_test_system() self.module_system.descriptor_runtime = self.course._runtime # pylint: disable=protected-access self.course.runtime.export_fs = MemoryFS() # Create mock partition service, as these tests are running with XML in-memory system. self.course.user_partitions = [ self.user_partition, UserPartition( MINIMUM_STATIC_PARTITION_ID, 'second_partition', 'Second Partition', [ Group(six.text_type(MINIMUM_STATIC_PARTITION_ID + 1), 'abel'), Group(six.text_type(MINIMUM_STATIC_PARTITION_ID + 2), 'baker'), Group("103", 'charlie') ], MockUserPartitionScheme() ) ] partitions_service = MockPartitionService( self.course, course_id=self.course.id, ) self.module_system._services['partitions'] = partitions_service # pylint: disable=protected-access # Mock user_service user user_service = Mock() user = Mock(username='******', email='*****@*****.**', is_staff=False, is_active=True) user_service._django_user = user self.module_system._services['user'] = user_service # pylint: disable=protected-access self.split_test_module = self.course_sequence.get_children()[0] self.split_test_module.bind_for_student( self.module_system, user.id ) # Create mock modulestore for getting the course. Needed for rendering the HTML # view, since mock services exist and the rendering code will not short-circuit. mocked_modulestore = Mock() mocked_modulestore.get_course.return_value = self.course self.split_test_module.system.modulestore = mocked_modulestore
def setUp(self): super(SplitTestModuleTest, self).setUp() self.course_id = 'test_org/test_course_number/test_run' # construct module course = xml.CourseFactory.build() sequence = xml.SequenceFactory.build(parent=course) split_test = SplitTestModuleFactory( parent=sequence, attribs={ 'user_partition_id': '0', 'group_id_to_child': '{"0": "i4x://edX/xml_test_course/html/split_test_cond0", "1": "i4x://edX/xml_test_course/html/split_test_cond1"}' }) xml.HtmlFactory(parent=split_test, url_name='split_test_cond0', text='HTML FOR GROUP 0') xml.HtmlFactory(parent=split_test, url_name='split_test_cond1', text='HTML FOR GROUP 1') self.course = self.process_xml(course) self.course_sequence = self.course.get_children()[0] self.module_system = get_test_system() def get_module(descriptor): """Mocks module_system get_module function""" module_system = get_test_system() module_system.get_module = get_module descriptor.bind_for_student(module_system, descriptor._field_data) # pylint: disable=protected-access return descriptor self.module_system.get_module = get_module self.module_system.descriptor_system = self.course.runtime self.course.runtime.export_fs = MemoryFS() self.partitions_service = StaticPartitionService( [ self.user_partition, UserPartition(1, 'second_partition', 'Second Partition', [ Group("0", 'abel'), Group("1", 'baker'), Group("2", 'charlie') ], MockUserPartitionScheme()) ], runtime=self.module_system, track_function=Mock(name='track_function'), ) self.module_system._services['partitions'] = self.partitions_service # pylint: disable=protected-access self.split_test_module = self.course_sequence.get_children()[0] self.split_test_module.bind_for_student( self.module_system, self.split_test_module._field_data) # pylint: disable=protected-access
def setUp(self): super(SplitTestModuleTest, self).setUp() self.course_id = 'test_org/test_course_number/test_run' # construct module course = xml.CourseFactory.build() sequence = xml.SequenceFactory.build(parent=course) split_test = SplitTestModuleFactory( parent=sequence, attribs={ 'user_partition_id': '0', 'group_id_to_child': '{"0": "i4x://edX/xml_test_course/html/split_test_cond0", "1": "i4x://edX/xml_test_course/html/split_test_cond1"}' # pylint: disable=line-too-long } ) xml.HtmlFactory(parent=split_test, url_name='split_test_cond0', text='HTML FOR GROUP 0') xml.HtmlFactory(parent=split_test, url_name='split_test_cond1', text='HTML FOR GROUP 1') self.course = self.process_xml(course) self.course_sequence = self.course.get_children()[0] self.module_system = get_test_system() self.module_system.descriptor_runtime = self.course._runtime # pylint: disable=protected-access self.course.runtime.export_fs = MemoryFS() user = Mock(username='******', email='*****@*****.**', is_staff=False, is_active=True) self.partitions_service = StaticPartitionService( [ self.user_partition, UserPartition( 1, 'second_partition', 'Second Partition', [Group("0", 'abel'), Group("1", 'baker'), Group("2", 'charlie')], MockUserPartitionScheme() ) ], user=user, course_id=self.course.id, track_function=Mock(name='track_function'), ) self.module_system._services['partitions'] = self.partitions_service # pylint: disable=protected-access self.split_test_module = self.course_sequence.get_children()[0] self.split_test_module.bind_for_student( self.module_system, user.id )
def create_user_partition_json(partition_id, name, description, groups): """ Helper method to create user partition JSON. """ return UserPartition(partition_id, name, description, groups, MockUserPartitionScheme("random")).to_json()