Commit 6c602dee by Dino Cikatic Committed by Nimisha Asthagiri

fixup! SplitTest.. Remove Include_schemes and add staff user tests

parent d96fa776
......@@ -3,8 +3,7 @@ Transformers helpers functions.
"""
from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme
from openedx.core.djangoapps.course_groups.partition_scheme import CohortPartitionScheme
# TODO 8874: Make it so we support all schemes instead of manually declaring them here.
INCLUDE_SCHEMES = [CohortPartitionScheme, RandomUserPartitionScheme, ]
SCHEME_SUPPORTS_ASSIGNMENT = [RandomUserPartitionScheme, ]
......@@ -25,8 +24,6 @@ def get_user_partition_groups(course_key, user_partitions, user):
"""
partition_groups = {}
for partition in user_partitions:
if partition.scheme not in INCLUDE_SCHEMES:
continue
group = partition.scheme.get_group_for_user(
course_key,
user,
......
......@@ -17,6 +17,16 @@ class CourseStructureTestCase(ModuleStoreTestCase):
"""
blocks = []
def setUp(self):
"""
Create users.
"""
super(CourseStructureTestCase, self).setUp()
# Set up users.
self.password = 'test'
self.user = UserFactory.create(password=self.password)
self.staff = UserFactory.create(password=self.password, is_staff=True)
def build_course(self, course_hierarchy):
"""
Build a hierarchy of XBlocks.
......@@ -87,6 +97,28 @@ 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):
"""
Assert course structure integrity if block structure has transformer applied
and is viewed by staff user.
"""
raw_block_structure = get_course_blocks(
staff,
course.location,
transformers={}
)
self.assertEqual(len(list(raw_block_structure.get_block_keys())), len(blocks))
trans_block_structure = get_course_blocks(
staff,
course.location,
transformers={transformer}
)
self.assertEqual(
len(list(raw_block_structure.get_block_keys())),
len(list(trans_block_structure.get_block_keys()))
)
class BlockParentsMapTestCase(ModuleStoreTestCase):
# Tree formed by parent_map:
......
......@@ -2,7 +2,6 @@
Tests for ContentLibraryTransformer.
"""
import mock
from student.tests.factories import UserFactory
from student.tests.factories import CourseEnrollmentFactory
from course_blocks.transformers.library_content import ContentLibraryTransformer
......@@ -33,20 +32,18 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
super(ContentLibraryTransformerTestCase, self).setUp()
# Build course.
self.course_hierarchy = self.get_test_course_hierarchy()
self.course_hierarchy = self.get_course_hierarchy()
self.blocks = self.build_course(self.course_hierarchy)
self.course = self.blocks['course']
clear_course_from_cache(self.course.id)
# Set up user and enroll in course.
self.password = 'test'
self.user = UserFactory.create(password=self.password)
# Enroll user in course.
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True)
self.selected_modules = [MockedModules('{"selected": [["vertical", "vertical_vertical2"]]}')]
self.transformer = []
self.transformer = ContentLibraryTransformer()
def get_test_course_hierarchy(self):
def get_course_hierarchy(self):
"""
Get a course hierarchy to test with.
"""
......@@ -115,8 +112,6 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
and after that mock response from MySQL db.
Check user can see mocked sections in content library.
"""
self.transformer = ContentLibraryTransformer()
raw_block_structure = get_course_blocks(
self.user,
self.course.location,
......@@ -159,3 +154,10 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
'html1'
)
)
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)
......@@ -3,7 +3,6 @@ Tests for SplitTestTransformer.
"""
from openedx.core.djangoapps.user_api.partition_schemes import RandomUserPartitionScheme
from opaque_keys.edx.keys import CourseKey
from student.tests.factories import UserFactory
from student.tests.factories import CourseEnrollmentFactory
from xmodule.modulestore.django import modulestore
from xmodule.partitions.partitions import Group, UserPartition
......@@ -38,18 +37,17 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
self.split_test_user_partition.scheme.name = "random"
# Build course.
self.course_hierarchy = self.get_test_course_hierarchy()
self.course_hierarchy = self.get_course_hierarchy()
self.blocks = self.build_course(self.course_hierarchy)
self.course = self.blocks['course']
clear_course_from_cache(self.course.id)
# Set up user and enroll in course.
self.password = 'test'
self.user = UserFactory.create(password=self.password)
# Enroll user in course.
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True)
self.transformation = []
self.transformer = SplitTestTransformer()
def get_test_course_hierarchy(self):
def get_course_hierarchy(self):
"""
Get a course hierarchy to test with.
......@@ -141,8 +139,6 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
Test course structure integrity if course has split test section
and user is not assigned to any group in user partition.
"""
self.transformation = SplitTestTransformer()
# Add user to split test.
self.add_user_to_splittest_group(assign=False)
......@@ -157,7 +153,7 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
trans_block_structure = get_course_blocks(
self.user,
self.course.location,
transformers={self.transformation}
transformers={self.transformer}
)
self.assertEqual(
......@@ -170,8 +166,6 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
Test course structure integrity if course has split test section
and user is assigned to any group in user partition.
"""
self.transformation = SplitTestTransformer()
# Add user to split test.
self.add_user_to_splittest_group()
......@@ -186,7 +180,7 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
trans_block_structure = get_course_blocks(
self.user,
self.course.location,
transformers={self.transformation}
transformers={self.transformer}
)
user_groups = get_user_partition_groups(
......@@ -219,3 +213,10 @@ class SplitTestTransformerTestCase(CourseStructureTestCase):
'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)
......@@ -6,7 +6,6 @@ from openedx.core.djangoapps.course_groups.partition_scheme import CohortPartiti
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory, config_course_cohorts
from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort
from openedx.core.djangoapps.course_groups.views import link_cohort_to_partition_group
from student.tests.factories import UserFactory
from student.tests.factories import CourseEnrollmentFactory
from xmodule.partitions.partitions import Group, UserPartition
......@@ -36,31 +35,30 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
scheme=CohortPartitionScheme
)
self.user_partition.scheme.name = "cohort"
# Build course.
self.course_hierarchy = self.get_test_course_hierarchy()
self.course_hierarchy = self.get_course_hierarchy()
self.blocks = self.build_course(self.course_hierarchy)
self.course = self.blocks['course']
clear_course_from_cache(self.course.id)
# Set up user and enroll in course.
self.password = 'test'
self.user = UserFactory.create(password=self.password)
# Enroll user in course.
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True)
# Set up cohorts.
config_course_cohorts(self.course, is_cohorted=True)
self.cohorts = [CohortFactory(course_id=self.course.id) for __ in enumerate(self.groups)]
self.add_user_to_cohort_group(self.cohorts[0], self.groups[0])
self.transformer = UserPartitionTransformer()
def get_test_course_hierarchy(self):
def get_course_hierarchy(self):
"""
Get a course hierarchy to test with.
Assumes self.user_partition has already been initialized.
"""
return {
'org': 'UserPartitionTransformation',
'org': 'UserPartitionTransformer',
'course': 'UP101F',
'run': 'test_run',
'user_partitions': [self.user_partition],
......@@ -116,8 +114,6 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
Test course structure integrity if course has user partition section
and user is assigned to group in user partition.
"""
self.transformation = UserPartitionTransformer()
raw_block_structure = get_course_blocks(
self.user,
self.course.location,
......@@ -125,13 +121,19 @@ class UserPartitionTransformerTestCase(CourseStructureTestCase):
)
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(
self.user,
self.course.location,
transformers={self.transformation}
transformers={self.transformer}
)
self.assertSetEqual(
set(trans_block_structure.get_block_keys()),
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)
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