Commit 29be1288 by Sarina Canelake

Clean up quality violations in split_test module

parent bf754c86
...@@ -14,6 +14,7 @@ from user_api.models import UserCourseTag ...@@ -14,6 +14,7 @@ from user_api.models import UserCourseTag
# global tags (e.g. using the existing UserPreferences table)) # global tags (e.g. using the existing UserPreferences table))
COURSE_SCOPE = 'course' COURSE_SCOPE = 'course'
def get_course_tag(user, course_id, key): def get_course_tag(user, course_id, key):
""" """
Gets the value of the user's course tag for the specified key in the specified Gets the value of the user's course tag for the specified key in the specified
......
...@@ -5,7 +5,7 @@ Test the partitions and partitions service ...@@ -5,7 +5,7 @@ Test the partitions and partitions service
from collections import defaultdict from collections import defaultdict
from unittest import TestCase from unittest import TestCase
from mock import Mock, MagicMock from mock import Mock
from xmodule.partitions.partitions import Group, UserPartition from xmodule.partitions.partitions import Group, UserPartition
from xmodule.partitions.partitions_service import PartitionService from xmodule.partitions.partitions_service import PartitionService
......
...@@ -40,7 +40,7 @@ class SplitTestFields(object): ...@@ -40,7 +40,7 @@ class SplitTestFields(object):
) )
@XBlock.needs('user_tags') @XBlock.needs('user_tags') # pylint: disable=abstract-method
@XBlock.needs('partitions') @XBlock.needs('partitions')
class SplitTestModule(SplitTestFields, XModule): class SplitTestModule(SplitTestFields, XModule):
""" """
...@@ -196,7 +196,7 @@ class SplitTestModule(SplitTestFields, XModule): ...@@ -196,7 +196,7 @@ class SplitTestModule(SplitTestFields, XModule):
return progress return progress
@XBlock.needs('user_tags') @XBlock.needs('user_tags') # pylint: disable=abstract-method
@XBlock.needs('partitions') @XBlock.needs('partitions')
class SplitTestDescriptor(SplitTestFields, SequenceDescriptor): class SplitTestDescriptor(SplitTestFields, SequenceDescriptor):
# the editing interface can be the same as for sequences -- just a container # the editing interface can be the same as for sequences -- just a container
...@@ -223,4 +223,3 @@ class SplitTestDescriptor(SplitTestFields, SequenceDescriptor): ...@@ -223,4 +223,3 @@ class SplitTestDescriptor(SplitTestFields, SequenceDescriptor):
makes it use module.get_child_descriptors(). makes it use module.get_child_descriptors().
""" """
return True return True
...@@ -44,9 +44,10 @@ class SplitTestModuleTest(XModuleXmlImportTest): ...@@ -44,9 +44,10 @@ class SplitTestModuleTest(XModuleXmlImportTest):
self.module_system = get_test_system() self.module_system = get_test_system()
def get_module(descriptor): def get_module(descriptor):
"""Mocks module_system get_module function"""
module_system = get_test_system() module_system = get_test_system()
module_system.get_module = get_module module_system.get_module = get_module
descriptor.bind_for_student(module_system, descriptor._field_data) descriptor.bind_for_student(module_system, descriptor._field_data) # pylint: disable=protected-access
return descriptor return descriptor
self.module_system.get_module = get_module self.module_system.get_module = get_module
...@@ -67,8 +68,7 @@ class SplitTestModuleTest(XModuleXmlImportTest): ...@@ -67,8 +68,7 @@ class SplitTestModuleTest(XModuleXmlImportTest):
self.module_system._services['partitions'] = self.partitions_service # pylint: disable=protected-access self.module_system._services['partitions'] = self.partitions_service # pylint: disable=protected-access
self.split_test_module = course_seq.get_children()[0] self.split_test_module = course_seq.get_children()[0]
self.split_test_module.bind_for_student(self.module_system, self.split_test_module._field_data) self.split_test_module.bind_for_student(self.module_system, self.split_test_module._field_data) # pylint: disable=protected-access
@ddt.data(('0', 'split_test_cond0'), ('1', 'split_test_cond1')) @ddt.data(('0', 'split_test_cond0'), ('1', 'split_test_cond1'))
@ddt.unpack @ddt.unpack
...@@ -83,7 +83,7 @@ class SplitTestModuleTest(XModuleXmlImportTest): ...@@ -83,7 +83,7 @@ class SplitTestModuleTest(XModuleXmlImportTest):
@ddt.data(('0',), ('1',)) @ddt.data(('0',), ('1',))
@ddt.unpack @ddt.unpack
def test_child_old_tag_value(self, user_tag): def test_child_old_tag_value(self, _user_tag):
# If user_tag has a stale value, we should still get back a valid child url # If user_tag has a stale value, we should still get back a valid child url
self.tags_service.set_tag( self.tags_service.set_tag(
self.tags_service.COURSE_SCOPE, self.tags_service.COURSE_SCOPE,
...@@ -109,13 +109,13 @@ class SplitTestModuleTest(XModuleXmlImportTest): ...@@ -109,13 +109,13 @@ class SplitTestModuleTest(XModuleXmlImportTest):
@ddt.data(('0',), ('1',)) @ddt.data(('0',), ('1',))
@ddt.unpack @ddt.unpack
def test_child_missing_tag_value(self, user_tag): def test_child_missing_tag_value(self, _user_tag):
# If user_tag has a missing value, we should still get back a valid child url # If user_tag has a missing value, we should still get back a valid child url
self.assertIn(self.split_test_module.child_descriptor.url_name, ['split_test_cond0', 'split_test_cond1']) self.assertIn(self.split_test_module.child_descriptor.url_name, ['split_test_cond0', 'split_test_cond1'])
@ddt.data(('100',), ('200',), ('300',), ('400',), ('500',), ('600',), ('700',), ('800',), ('900',), ('1000',)) @ddt.data(('100',), ('200',), ('300',), ('400',), ('500',), ('600',), ('700',), ('800',), ('900',), ('1000',))
@ddt.unpack @ddt.unpack
def test_child_persist_new_tag_value_when_tag_missing(self, user_tag): def test_child_persist_new_tag_value_when_tag_missing(self, _user_tag):
# If a user_tag has a missing value, a group should be saved/persisted for that user. # If a user_tag has a missing value, a group should be saved/persisted for that user.
# So, we check that we get the same url_name when we call on the url_name twice. # So, we check that we get the same url_name when we call on the url_name twice.
# We run the test ten times so that, if our storage is failing, we'll be most likely to notice it. # We run the test ten times so that, if our storage is failing, we'll be most likely to notice it.
......
...@@ -146,6 +146,7 @@ class SequenceFactory(XmlImportFactory): ...@@ -146,6 +146,7 @@ class SequenceFactory(XmlImportFactory):
"""Factory for <sequential> nodes""" """Factory for <sequential> nodes"""
tag = 'sequential' tag = 'sequential'
class VerticalFactory(XmlImportFactory): class VerticalFactory(XmlImportFactory):
"""Factory for <vertical> nodes""" """Factory for <vertical> nodes"""
tag = 'vertical' tag = 'vertical'
......
""" """
Test for split test XModule Test for split test XModule
""" """
import ddt
from mock import MagicMock, patch, Mock
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
from student.tests.factories import UserFactory, CourseEnrollmentFactory, AdminFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.partitions.partitions import Group, UserPartition from xmodule.partitions.partitions import Group, UserPartition
from xmodule.partitions.test_partitions import StaticPartitionService
from user_api.tests.factories import UserCourseTagFactory from user_api.tests.factories import UserCourseTagFactory
from xmodule.partitions.partitions import Group, UserPartition
@override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MIXED_MODULESTORE)
class SplitTestBase(ModuleStoreTestCase): class SplitTestBase(ModuleStoreTestCase):
"""
Sets up a basic course and user for split test testing.
Also provides tests of rendered HTML for two user_tag conditions, 0 and 1.
"""
__test__ = False __test__ = False
COURSE_NUMBER = 'split-test-base'
ICON_CLASSES = None
TOOLTIPS = None
HIDDEN_CONTENT = None
VISIBLE_CONTENT = None
def setUp(self): def setUp(self):
self.partition = UserPartition( self.partition = UserPartition(
...@@ -53,6 +58,10 @@ class SplitTestBase(ModuleStoreTestCase): ...@@ -53,6 +58,10 @@ class SplitTestBase(ModuleStoreTestCase):
self.client.login(username=self.student.username, password='test') self.client.login(username=self.student.username, password='test')
def _video(self, parent, group): def _video(self, parent, group):
"""
Returns a video component with parent ``parent``
that is intended to be displayed to group ``group``.
"""
return ItemFactory.create( return ItemFactory.create(
parent_location=parent.location, parent_location=parent.location,
category="video", category="video",
...@@ -60,6 +69,10 @@ class SplitTestBase(ModuleStoreTestCase): ...@@ -60,6 +69,10 @@ class SplitTestBase(ModuleStoreTestCase):
) )
def _problem(self, parent, group): def _problem(self, parent, group):
"""
Returns a problem component with parent ``parent``
that is intended to be displayed to group ``group``.
"""
return ItemFactory.create( return ItemFactory.create(
parent_location=parent.location, parent_location=parent.location,
category="problem", category="problem",
...@@ -68,6 +81,10 @@ class SplitTestBase(ModuleStoreTestCase): ...@@ -68,6 +81,10 @@ class SplitTestBase(ModuleStoreTestCase):
) )
def _html(self, parent, group): def _html(self, parent, group):
"""
Returns an html component with parent ``parent``
that is intended to be displayed to group ``group``.
"""
return ItemFactory.create( return ItemFactory.create(
parent_location=parent.location, parent_location=parent.location,
category="html", category="html",
...@@ -82,21 +99,23 @@ class SplitTestBase(ModuleStoreTestCase): ...@@ -82,21 +99,23 @@ class SplitTestBase(ModuleStoreTestCase):
self._check_split_test(1) self._check_split_test(1)
def _check_split_test(self, user_tag): def _check_split_test(self, user_tag):
tag_factory = UserCourseTagFactory( """Checks that the right compentents are rendered for user with ``user_tag``"""
# This explicitly sets the user_tag for self.student to ``user_tag``
UserCourseTagFactory(
user=self.student, user=self.student,
course_id=self.course.id, course_id=self.course.id,
key='xblock.partition_service.partition_{0}'.format(self.partition.id), key='xblock.partition_service.partition_{0}'.format(self.partition.id),
value=str(user_tag) value=str(user_tag)
) )
resp = self.client.get(reverse('courseware_section', resp = self.client.get(reverse(
'courseware_section',
kwargs={'course_id': self.course.id, kwargs={'course_id': self.course.id,
'chapter': self.chapter.url_name, 'chapter': self.chapter.url_name,
'section': self.sequential.url_name} 'section': self.sequential.url_name}
)) ))
content = resp.content content = resp.content
print content
# Assert we see the proper icon in the top display # Assert we see the proper icon in the top display
self.assertIn('<a class="{} inactive progress-0"'.format(self.ICON_CLASSES[user_tag]), content) self.assertIn('<a class="{} inactive progress-0"'.format(self.ICON_CLASSES[user_tag]), content)
...@@ -118,7 +137,7 @@ class TestVertSplitTestVert(SplitTestBase): ...@@ -118,7 +137,7 @@ class TestVertSplitTestVert(SplitTestBase):
""" """
__test__ = True __test__ = True
COURSE_NUMBER='vert-split-vert' COURSE_NUMBER = 'vert-split-vert'
ICON_CLASSES = [ ICON_CLASSES = [
'seq_problem', 'seq_problem',
...@@ -141,6 +160,8 @@ class TestVertSplitTestVert(SplitTestBase): ...@@ -141,6 +160,8 @@ class TestVertSplitTestVert(SplitTestBase):
] ]
def setUp(self): def setUp(self):
# We define problem compenents that we need but don't explicitly call elsewhere.
# pylint: disable=unused-variable
super(TestVertSplitTestVert, self).setUp() super(TestVertSplitTestVert, self).setUp()
# vert <- split_test # vert <- split_test
...@@ -151,6 +172,7 @@ class TestVertSplitTestVert(SplitTestBase): ...@@ -151,6 +172,7 @@ class TestVertSplitTestVert(SplitTestBase):
category="vertical", category="vertical",
display_name="Split test vertical", display_name="Split test vertical",
) )
# pylint: disable=protected-access
c0_url = self.course.location._replace(category="vertical", name="split_test_cond0") c0_url = self.course.location._replace(category="vertical", name="split_test_cond0")
c1_url = self.course.location._replace(category="vertical", name="split_test_cond1") c1_url = self.course.location._replace(category="vertical", name="split_test_cond1")
...@@ -210,10 +232,13 @@ class TestSplitTestVert(SplitTestBase): ...@@ -210,10 +232,13 @@ class TestSplitTestVert(SplitTestBase):
] ]
def setUp(self): def setUp(self):
# We define problem compenents that we need but don't explicitly call elsewhere.
# pylint: disable=unused-variable
super(TestSplitTestVert, self).setUp() super(TestSplitTestVert, self).setUp()
# split_test cond 0 = vert <- {video, problem} # split_test cond 0 = vert <- {video, problem}
# split_test cond 1 = vert <- {video, html} # split_test cond 1 = vert <- {video, html}
# pylint: disable=protected-access
c0_url = self.course.location._replace(category="vertical", name="split_test_cond0") c0_url = self.course.location._replace(category="vertical", name="split_test_cond0")
c1_url = self.course.location._replace(category="vertical", name="split_test_cond1") c1_url = self.course.location._replace(category="vertical", name="split_test_cond1")
......
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