""" Test for split test XModule """ import ddt from mock import MagicMock, patch, Mock from django.core.urlresolvers import reverse from django.test.utils import override_settings from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.partitions.partitions import Group, UserPartition from xmodule.partitions.test_partitions import StaticPartitionService from user_api.tests.factories import UserCourseTagFactory from xmodule.partitions.partitions import Group, UserPartition @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) class SplitTestBase(ModuleStoreTestCase): __test__ = False def setUp(self): self.partition = UserPartition( 0, 'first_partition', 'First Partition', [ Group(0, 'alpha'), Group(1, 'beta') ] ) self.course = CourseFactory.create( number=self.COURSE_NUMBER, user_partitions=[self.partition] ) self.chapter = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name="test chapter", ) self.sequential = ItemFactory.create( parent_location=self.chapter.location, category="sequential", display_name="Split Test Tests", ) self.student = UserFactory.create() CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) self.client.login(username=self.student.username, password='test') def _video(self, parent, group): return ItemFactory.create( parent_location=parent.location, category="video", display_name="Group {} Sees This Video".format(group), ) def _problem(self, parent, group): return ItemFactory.create( parent_location=parent.location, category="problem", display_name="Group {} Sees This Problem".format(group), data="

No Problem Defined Yet!

", ) def _html(self, parent, group): return ItemFactory.create( parent_location=parent.location, category="html", display_name="Group {} Sees This HTML".format(group), data="Some HTML for group {}".format(group), ) def test_split_test_0(self): self._check_split_test(0) def test_split_test_1(self): self._check_split_test(1) def _check_split_test(self, user_tag): tag_factory = UserCourseTagFactory( user=self.student, course_id=self.course.id, key='xblock.partition_service.partition_{0}'.format(self.partition.id), value=str(user_tag) ) resp = self.client.get(reverse('courseware_section', kwargs={'course_id': self.course.id, 'chapter': self.chapter.url_name, 'section': self.sequential.url_name} )) content = resp.content print content # Assert we see the proper icon in the top display self.assertIn('