From 92ed01ef4ffc35601e1e49715ae41f0be28da3b4 Mon Sep 17 00:00:00 2001 From: Qubad786 Date: Thu, 30 Jun 2016 23:34:30 +0500 Subject: [PATCH 1/2] filter inactive user partitions in user partition transformer. --- .../tests/test_user_partitions.py | 41 +++++++++++++++---- .../transformers/user_partitions.py | 6 ++- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py b/lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py index e5cea4ae0d..511b8f7016 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_user_partitions.py @@ -5,6 +5,7 @@ Tests for UserPartitionTransformer. from collections import namedtuple import ddt from nose.plugins.attrib import attr +import string from openedx.core.djangoapps.course_groups.partition_scheme import CohortPartitionScheme from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory, config_course_cohorts @@ -25,7 +26,7 @@ class UserPartitionTestMixin(object): """ TRANSFORMER_CLASS_TO_TEST = UserPartitionTransformer - def setup_groups_partitions(self, num_user_partitions=1, num_groups=4): + def setup_groups_partitions(self, num_user_partitions=1, num_groups=4, active=True): """ Sets up groups and user partitions for testing. """ @@ -42,7 +43,8 @@ class UserPartitionTestMixin(object): name='Partition ' + unicode(user_partition_num), description='This is partition ' + unicode(user_partition_num), groups=self.groups, - scheme=CohortPartitionScheme + scheme=CohortPartitionScheme, + active=active, ) user_partition.scheme.name = "cohort" self.user_partitions.append(user_partition) @@ -72,15 +74,16 @@ class UserPartitionTransformerTestCase(UserPartitionTestMixin, CourseStructureTe """ UserPartitionTransformer Test """ - def setUp(self): + def setup_partitions_and_course(self, active=True): """ Setup course structure and create user for user partition transformer test. + Args: + active: boolean representing if the user partitions are + active or not """ - super(UserPartitionTransformerTestCase, self).setUp() - # Set up user partitions and groups. - self.setup_groups_partitions() + self.setup_groups_partitions(active=active) self.user_partition = self.user_partitions[0] # Build course. @@ -89,7 +92,9 @@ class UserPartitionTransformerTestCase(UserPartitionTestMixin, CourseStructureTe self.course = self.blocks['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 + ) # Set up cohorts. self.setup_cohorts(self.course) @@ -199,6 +204,7 @@ class UserPartitionTransformerTestCase(UserPartitionTestMixin, CourseStructureTe ) @ddt.unpack def test_transform(self, group_id, expected_blocks): + self.setup_partitions_and_course() if group_id: cohort = self.partition_cohorts[self.user_partition.id - 1][group_id - 1] add_user_to_cohort(cohort, self.user.username) @@ -213,6 +219,27 @@ class UserPartitionTransformerTestCase(UserPartitionTestMixin, CourseStructureTe self.get_block_key_set(self.blocks, *expected_blocks) ) + def test_transform_on_inactive_partition(self): + """ + Tests UserPartitionTransformer for inactive UserPartition. + """ + self.setup_partitions_and_course(active=False) + + # we expect to find all blocks because the UserPartitions are all + # inactive + expected_blocks = ('course',) + tuple(string.ascii_uppercase[:15]) + + trans_block_structure = get_course_blocks( + self.user, + self.course.location, + self.transformers, + ) + + self.assertSetEqual( + set(trans_block_structure.get_block_keys()), + self.get_block_key_set(self.blocks, *expected_blocks) + ) + @attr('shard_3') @ddt.ddt diff --git a/lms/djangoapps/course_blocks/transformers/user_partitions.py b/lms/djangoapps/course_blocks/transformers/user_partitions.py index 86d8eec833..e3f5ddb4cd 100644 --- a/lms/djangoapps/course_blocks/transformers/user_partitions.py +++ b/lms/djangoapps/course_blocks/transformers/user_partitions.py @@ -42,7 +42,11 @@ class UserPartitionTransformer(BlockStructureTransformer): # Because user partitions are course-wide, only store data for # them on the root block. root_block = block_structure.get_xblock(block_structure.root_block_usage_key) - user_partitions = getattr(root_block, 'user_partitions', []) or [] + user_partitions = [ + user_partition + for user_partition in getattr(root_block, 'user_partitions', []) + if user_partition.active + ] block_structure.set_transformer_data(cls, 'user_partitions', user_partitions) # If there are no user partitions, this transformation is a From 2e095e155748231e18ab5cfb62bce170dac7939e Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Fri, 8 Jul 2016 12:49:53 -0400 Subject: [PATCH 2/2] mark StudioHelpTest.test_studio_help_links as flaky --- common/test/acceptance/tests/studio/test_studio_help.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/test/acceptance/tests/studio/test_studio_help.py b/common/test/acceptance/tests/studio/test_studio_help.py index 4561019396..799913cc7d 100644 --- a/common/test/acceptance/tests/studio/test_studio_help.py +++ b/common/test/acceptance/tests/studio/test_studio_help.py @@ -2,6 +2,8 @@ Test the Studio help links. """ +from flaky import flaky + from .base_studio_test import StudioCourseTest from ...pages.studio.index import DashboardPage from ...pages.studio.utils import click_studio_help, studio_help_links @@ -10,6 +12,7 @@ from ...pages.studio.utils import click_studio_help, studio_help_links class StudioHelpTest(StudioCourseTest): """Tests for Studio help.""" + @flaky # TODO: TNL-4954 def test_studio_help_links(self): """Test that the help links are present and have the correct content.""" page = DashboardPage(self.browser)