def test_staff_masquerading_added_to_group(self):
        """
        Tests that initializer sets masquerading for a staff user in a group.
        """
        # Verify that there is no masquerading group initially
        _, filter_directory, _ = LmsSearchFilterGenerator.generate_field_filters(  # pylint: disable=unused-variable
            user=self.global_staff,
            course_id=unicode(self.course.id)
        )
        # User is staff by default, no content groups filter is set - see all
        self.assertNotIn('content_groups', filter_directory)

        # Install a masquerading group
        request = self._create_mock_json_request(
            self.global_staff,
            body='{"role": "student", "user_partition_id": 0, "group_id": 1}'
        )
        handle_ajax(request, unicode(self.course.id))

        # Call initializer
        LmsSearchInitializer.set_search_enviroment(
            request=request,
            course_id=unicode(self.course.id)
        )

        # Verify that there is masquerading group after masquerade
        _, filter_directory, _ = LmsSearchFilterGenerator.generate_field_filters(  # pylint: disable=unused-variable
            user=self.global_staff,
            course_id=unicode(self.course.id)
        )
        self.assertEqual(filter_directory['content_groups'], [unicode(1)])
    def test_staff_masquerading_added_to_group(self):
        """
        Tests that initializer sets masquerading for a staff user in a group.
        """
        # Verify that there is no masquerading group initially
        _, filter_directory, _ = LmsSearchFilterGenerator.generate_field_filters(  # pylint: disable=unused-variable
            user=self.global_staff,
            course_id=unicode(self.course.id))
        # User is staff by default, no content groups filter is set - see all
        self.assertNotIn('content_groups', filter_directory)

        # Install a masquerading group
        request = self._create_mock_json_request(
            self.global_staff,
            body='{"role": "student", "user_partition_id": 0, "group_id": 1}')
        handle_ajax(request, unicode(self.course.id))

        # Call initializer
        LmsSearchInitializer.set_search_enviroment(request=request,
                                                   course_id=unicode(
                                                       self.course.id))

        # Verify that there is masquerading group after masquerade
        _, filter_directory, _ = LmsSearchFilterGenerator.generate_field_filters(  # pylint: disable=unused-variable
            user=self.global_staff,
            course_id=unicode(self.course.id))
        self.assertEqual(filter_directory['content_groups'], [unicode(1)])
    def test_invalid_course_key(self):
        """
        Test system raises an error if no course found.
        """

        self.add_seq_with_content_groups()
        with self.assertRaises(InvalidKeyError):
            LmsSearchFilterGenerator.generate_field_filters(user=self.user, course_id="this_is_false_course_id")
    def test_invalid_course_key(self):
        """
        Test system raises an error if no course found.
        """

        self.add_seq_with_content_groups()
        with self.assertRaises(InvalidKeyError):
            LmsSearchFilterGenerator.generate_field_filters(
                user=self.user, course_id='this_is_false_course_id')
    def test_content_multiple_groups_id_provided(self):
        """
        Tests that we get content groups IDs when course is assigned to cohort
        which is assigned to multiple content groups.
        """
        self.add_seq_with_content_groups()
        self.add_user_to_cohort_group()

        # Second cohort link
        link_cohort_to_partition_group(
            self.second_cohort,
            self.user_partition.id,
            self.groups[0].id,
        )

        self.courses[0].save()
        modulestore().update_item(self.courses[0], self.user.id)

        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user,
            course_id=unicode(self.courses[0].id)
        )

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[0].id), field_dictionary['course'])
        # returns only first group, relevant to current user
        self.assertEqual([unicode(self.content_groups[0])], filter_dictionary['content_groups'])
Beispiel #6
0
 def test_excludes_microsite(self):
     """ By default there is the test microsite to exclude """
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     self.assertIn('org', exclude_dictionary)
     exclude_orgs = exclude_dictionary['org']
     self.assertEqual(1, len(exclude_orgs))
     self.assertEqual('TestMicrositeX', exclude_orgs[0])
    def test_content_multiple_groups_id_provided(self):
        """
        Tests that we get content groups IDs when course is assigned to cohort
        which is assigned to multiple content groups.
        """
        self.add_seq_with_content_groups()
        self.add_user_to_cohort_group()

        # Second cohort link
        link_cohort_to_partition_group(
            self.second_cohort,
            self.user_partition.id,
            self.groups[0].id,
        )

        self.courses[0].save()
        modulestore().update_item(self.courses[0], self.user.id)

        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=unicode(self.courses[0].id))

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[0].id),
                         field_dictionary['course'])
        # returns only first group, relevant to current user
        self.assertEqual([unicode(self.content_groups[0])],
                         filter_dictionary['content_groups'])
Beispiel #8
0
    def test_user_not_provided(self):
        """
        Tests that we get empty list of courses in case the user is not provided
        """
        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters()

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(0, len(field_dictionary['course']))
Beispiel #9
0
 def test_excludes_multi_microsites(self):
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     self.assertIn('org', exclude_dictionary)
     exclude_orgs = exclude_dictionary['org']
     self.assertEqual(4, len(exclude_orgs))
     self.assertIn('TestMicrosite1', exclude_orgs)
     self.assertIn('TestMicrosite2', exclude_orgs)
     self.assertIn('TestMicrosite3', exclude_orgs)
     self.assertIn('TestMicrosite4', exclude_orgs)
Beispiel #10
0
    def test_user_not_provided(self):
        """
        Tests that we get empty dict in case the user is not provided
        """
        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
        )

        self.assertIn('start_date', filter_dictionary)
        self.assertEqual({}, field_dictionary)
Beispiel #11
0
    def test_course_id_not_provided(self):
        """
        Tests that we get the list of IDs of courses the user is enrolled in when the course ID is null or not provided
        """
        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(user=self.user)

        self.assertTrue('start_date' in filter_dictionary)
        self.assertIn(unicode(self.courses[0].id), field_dictionary['course'])
        self.assertIn(unicode(self.courses[1].id), field_dictionary['course'])
 def test_excludes_multi_microsites(self):
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     self.assertIn("org", exclude_dictionary)
     exclude_orgs = exclude_dictionary["org"]
     self.assertEqual(4, len(exclude_orgs))
     self.assertIn("TestMicrosite1", exclude_orgs)
     self.assertIn("TestMicrosite2", exclude_orgs)
     self.assertIn("TestMicrosite3", exclude_orgs)
     self.assertIn("TestMicrosite4", exclude_orgs)
Beispiel #13
0
    def test_course_id_provided(self):
        """
        Tests that we get the course ID when the course ID is provided
        """
        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=str(self.courses[0].id))

        assert 'start_date' in filter_dictionary
        assert str(self.courses[0].id) == field_dictionary['course']
 def test_excludes_multi_orgs(self):
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     assert 'org' in exclude_dictionary
     exclude_orgs = exclude_dictionary['org']
     assert 4 == len(exclude_orgs)
     assert 'TestSite1' in exclude_orgs
     assert 'TestSite2' in exclude_orgs
     assert 'TestSite3' in exclude_orgs
     assert 'TestSite4' in exclude_orgs
Beispiel #15
0
 def test_excludes_site_org(self):
     """
     By default site orgs not belonging to current site org should be excluded.
     """
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     self.assertIn('org', exclude_dictionary)
     exclude_orgs = exclude_dictionary['org']
     self.assertEqual(2, len(exclude_orgs))
     self.assertEqual('LogistrationX', exclude_orgs[0])
     self.assertEqual('TestSiteX', exclude_orgs[1])
    def test_course_id_provided(self):
        """
        Tests that we get the course ID when the course ID is provided
        """
        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=unicode(self.courses[0].id)
        )

        self.assertTrue("start_date" in filter_dictionary)
        self.assertEqual(unicode(self.courses[0].id), field_dictionary["course"])
    def test_course_id_provided(self):
        """
        Tests that we get the course ID when the course ID is provided
        """
        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=unicode(self.courses[0].id))

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[0].id),
                         field_dictionary['course'])
 def test_excludes_site_org(self):
     """
     By default site orgs not belonging to current site org should be excluded.
     """
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     assert 'org' in exclude_dictionary
     exclude_orgs = exclude_dictionary['org']
     assert 2 == len(exclude_orgs)
     assert 'LogistrationX' == exclude_orgs[0]
     assert 'TestSiteX' == exclude_orgs[1]
 def test_excludes_site_org(self):
     """
     By default site orgs not belonging to current site org should be excluded.
     """
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     self.assertIn('org', exclude_dictionary)
     exclude_orgs = exclude_dictionary['org']
     self.assertEqual(2, len(exclude_orgs))
     self.assertEqual('LogistrationX', exclude_orgs[0])
     self.assertEqual('TestSiteX', exclude_orgs[1])
    def test_content_group_with_cohort_not_provided(self):
        """
        Tests that we don't get content group ID when course has no cohorts
        """
        self.add_seq_with_content_groups()

        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=unicode(self.courses[0].id))

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[0].id),
                         field_dictionary['course'])
        self.assertEqual(None, filter_dictionary['content_groups'])
    def test_content_group_with_cohort_not_provided(self):
        """
        Tests that we don't get content group ID when course has no cohorts
        """
        self.add_seq_with_content_groups()

        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=unicode(self.courses[0].id)
        )

        self.assertTrue("start_date" in filter_dictionary)
        self.assertEqual(unicode(self.courses[0].id), field_dictionary["course"])
        self.assertEqual(None, filter_dictionary["content_groups"])
    def test_split_test_with_user_groups_user_not_assigned(self):
        """
        Tests that we don't get user group ID when user is not assigned to a split test group
        """
        self.add_split_test()

        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=unicode(self.courses[1].id))

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[1].id),
                         field_dictionary['course'])
        self.assertEqual(None, filter_dictionary['content_groups'])
    def test_content_group_id_provided(self):
        """
        Tests that we get the content group ID when course is assigned to cohort
        which is assigned content group.
        """
        self.add_seq_with_content_groups()
        self.add_user_to_cohort_group()
        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=unicode(self.courses[0].id)
        )

        self.assertTrue("start_date" in filter_dictionary)
        self.assertEqual(unicode(self.courses[0].id), field_dictionary["course"])
        self.assertEqual(unicode(self.content_groups[0]), filter_dictionary["content_groups"])
    def test_split_test_with_user_groups_user_not_assigned(self):
        """
        Tests that we don't get user group ID when user is not assigned to a split test group
        """
        self.add_split_test()

        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user,
            course_id=unicode(self.courses[1].id)
        )

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[1].id), field_dictionary['course'])
        self.assertEqual(None, filter_dictionary['content_groups'])
    def test_content_group_id_not_provided(self):
        """
        Tests that we don't get content group ID when course is assigned a cohort
        but cohort is not assigned to content group.
        """
        self.add_seq_with_content_groups(groups=[])

        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user,
            course_id=unicode(self.courses[0].id)
        )

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[0].id), field_dictionary['course'])
        self.assertEqual(None, filter_dictionary['content_groups'])
    def test_content_group_id_provided(self):
        """
        Tests that we get the content group ID when course is assigned to cohort
        which is assigned content group.
        """
        self.add_seq_with_content_groups()
        self.add_user_to_cohort_group()
        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=unicode(self.courses[0].id))

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[0].id),
                         field_dictionary['course'])
        self.assertEqual([unicode(self.content_groups[0])],
                         filter_dictionary['content_groups'])
    def test_staff_masquerading_as_a_staff_user(self):
        """
        Tests that initializer sets masquerading for a staff user as staff.
        """

        # Install a masquerading group
        request = self._create_mock_json_request(self.global_staff,
                                                 body='{"role": "staff"}')
        handle_ajax(request, unicode(self.course.id))

        # Call initializer
        LmsSearchInitializer.set_search_enviroment(request=request,
                                                   course_id=unicode(
                                                       self.course.id))

        # Verify that there is masquerading group after masquerade
        _, filter_directory, _ = LmsSearchFilterGenerator.generate_field_filters(  # pylint: disable=unused-variable
            user=self.global_staff,
            course_id=unicode(self.course.id))
        self.assertNotIn('content_groups', filter_directory)
    def test_split_test_with_user_groups_user_assigned(self):
        """
        Tests that we get user group ID when user is assigned to a split test group
        """
        self.add_split_test()
        self.add_user_to_splittest_group()

        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user, course_id=unicode(self.courses[1].id))

        partition_group = self.split_test_user_partition.scheme.get_group_for_user(
            CourseKey.from_string(unicode(self.courses[1].id)),
            self.user,
            self.split_test_user_partition,
            assign=False,
        )

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[1].id),
                         field_dictionary['course'])
        self.assertEqual([unicode(partition_group.id)],
                         filter_dictionary['content_groups'])
    def test_split_test_with_user_groups_user_assigned(self):
        """
        Tests that we get user group ID when user is assigned to a split test group
        """
        self.add_split_test()
        self.add_user_to_splittest_group()

        field_dictionary, filter_dictionary, _ = LmsSearchFilterGenerator.generate_field_filters(
            user=self.user,
            course_id=unicode(self.courses[1].id)
        )

        partition_group = self.split_test_user_partition.scheme.get_group_for_user(
            CourseKey.from_string(unicode(self.courses[1].id)),
            self.user,
            self.split_test_user_partition,
            assign=False,
        )

        self.assertTrue('start_date' in filter_dictionary)
        self.assertEqual(unicode(self.courses[1].id), field_dictionary['course'])
        self.assertEqual([unicode(partition_group.id)], filter_dictionary['content_groups'])
    def test_staff_masquerading_as_a_student_user(self):
        """
        Tests that initializer sets masquerading for a staff user as student.
        """

        # Install a masquerading group
        request = self._create_mock_json_request(
            self.global_staff,
            body='{"role": "student"}'
        )
        handle_ajax(request, unicode(self.course.id))

        # Call initializer
        LmsSearchInitializer.set_search_enviroment(
            request=request,
            course_id=unicode(self.course.id)
        )

        # Verify that there is masquerading group after masquerade
        _, filter_directory, _ = LmsSearchFilterGenerator.generate_field_filters(  # pylint: disable=unused-variable
            user=self.global_staff,
            course_id=unicode(self.course.id)
        )
        self.assertEqual(filter_directory['content_groups'], None)
Beispiel #31
0
 def test_no_excludes_with_no_orgs(self):
     """ Test when no org is present - nothing to exclude """
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(
         user=self.user)
     assert 'org' not in exclude_dictionary
 def test_excludes_no_microsite(self):
     """ Test when no microsite is present - nothing to exclude """
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     self.assertNotIn('org', exclude_dictionary)
 def test_excludes_multi_orgs_within(self):
     field_dictionary, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     self.assertNotIn('org', exclude_dictionary)
     self.assertIn('org', field_dictionary)
     self.assertEqual(['TestSite3'], field_dictionary['org'])
Beispiel #34
0
 def test_excludes_org_within(self):
     field_dictionary, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(
         user=self.user)
     self.assertNotIn('org', exclude_dictionary)
     self.assertIn('org', field_dictionary)
     self.assertEqual(['TestSiteX'], field_dictionary['org'])
 def test_excludes_multi_microsites_within(self):
     field_dictionary, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     self.assertNotIn("org", exclude_dictionary)
     self.assertIn("org", field_dictionary)
     self.assertEqual("TestMicrosite3", field_dictionary["org"])
Beispiel #36
0
 def test_excludes_multi_orgs_within(self):
     field_dictionary, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(
         user=self.user)
     assert 'org' not in exclude_dictionary
     assert 'org' in field_dictionary
     assert ['TestSite3'] == field_dictionary['org']
 def test_excludes_microsite_within(self):
     field_dictionary, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(user=self.user)
     self.assertNotIn('org', exclude_dictionary)
     self.assertIn('org', field_dictionary)
     self.assertEqual('TestMicrositeX', field_dictionary['org'])
 def test_excludes_multi_microsites_within(self):
     field_dictionary, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(
         user=self.user)
     self.assertNotIn('org', exclude_dictionary)
     self.assertIn('org', field_dictionary)
     self.assertEqual('TestMicrosite3', field_dictionary['org'])
 def test_excludes_no_microsite(self):
     """ Test when no microsite is present - nothing to exclude """
     _, _, exclude_dictionary = LmsSearchFilterGenerator.generate_field_filters(
         user=self.user)
     self.assertNotIn('org', exclude_dictionary)