コード例 #1
0
    def test_groups_groups_list_missing_relationship_type(self):
        # Create test groups
        from_group = GroupFactory.create()
        to_group = GroupFactory.create()

        # Test with missing relationship_type in the request data
        test_uri = '{}/{}/groups/'.format(self.base_groups_uri, from_group.id)
        response = self.do_post(test_uri, {"group_id": to_group.id})
        self.assertEqual(response.status_code, 400)
コード例 #2
0
    def test_access_denied_fragment_for_masquerading(self):
        """
        Test that a global staff sees gated content flag when viewing course as `Learner in Audit`
        Note: Global staff doesn't require to be enrolled in course.
        """
        mock_request = RequestFactory().get('/')
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(
            course_key=mock_course.id)))
        mock_course_masquerade = Mock(
            role='student',
            user_partition_id=ENROLLMENT_TRACK_PARTITION_ID,
            group_id=settings.COURSE_ENROLLMENT_MODES['audit']['id'],
            user_name=None)
        CourseModeFactory.create(course_id=mock_course.id,
                                 mode_slug='verified')

        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=False,
                                               studio_override_enabled=True)

        partition = create_content_gating_partition(mock_course)

        with patch(
                'courseware.masquerade.get_course_masquerade',
                return_value=mock_course_masquerade
        ), patch(
                'openedx.features.content_type_gating.partitions.get_course_masquerade',
                return_value=mock_course_masquerade), patch(
                    'crum.get_current_request', return_value=mock_request):
            fragment = partition.access_denied_fragment(
                mock_block, global_staff, GroupFactory(), 'test_allowed_group')

        self.assertIsNotNone(fragment)
コード例 #3
0
    def test_acess_denied_fragment_for_null_request(self):
        """
        Verifies the access denied fragment is visible when HTTP request is not available.

        Given the HTTP request instance is None
        Then set the mobile_app context variable to False
        And the fragment should be created successfully
        """
        mock_request = None
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(
            course_key=mock_course.id)))
        CourseModeFactory.create(course_id=mock_course.id,
                                 mode_slug='verified')
        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=True,
                                               enabled_as_of=datetime(
                                                   2018, 1, 1))
        partition = create_content_gating_partition(mock_course)

        with patch(
                'crum.get_current_request', return_value=mock_request
        ), patch(
                'openedx.features.content_type_gating.partitions.ContentTypeGatingPartition._is_audit_enrollment',
                return_value=True):
            fragment = partition.access_denied_fragment(
                mock_block, global_staff, GroupFactory(), 'test_allowed_group')

        self.assertIsNotNone(fragment)
コード例 #4
0
    def test_organizations_groups_users_delete(self):
        organization = self.setup_test_organization()
        organization_two = self.setup_test_organization()
        groups = GroupFactory.create_batch(2)
        users = UserFactory.create_batch(5)
        groups[0].organizations.add(organization['id'])
        groups[0].organizations.add(organization_two['id'])
        for user in users:
            OrganizationGroupUser.objects.create(
                organization_id=organization['id'], group=groups[0], user=user)
            OrganizationGroupUser.objects.create(
                organization_id=organization_two['id'],
                group=groups[0],
                user=user)

        # test for invalid user id
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization['id'],
                                                 groups[1].id)
        data = {'users': '1,qwerty'}
        response = self.do_delete(test_uri, data)
        self.assertEqual(response.status_code, 400)

        # group does not belong to organization
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization['id'],
                                                 groups[1].id)
        data = {'users': ','.join([str(user.id) for user in users])}
        response = self.do_delete(test_uri, data)
        self.assertEqual(response.status_code, 404)
        expected_response = "Group {} does not belong to organization {}".format(
            groups[1].id, organization['id'])
        self.assertEqual(response.data['detail'], expected_response)

        # group belong to organization but users does not exit
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization['id'],
                                                 groups[0].id)
        data = {'users': '1234,9912,9800'}
        response = self.do_delete(test_uri, data)
        self.assertEqual(response.status_code, 204)

        # organization group user relationship exists for users
        data = {'users': ','.join([str(user.id) for user in users])}
        response = self.do_delete(test_uri, data)
        self.assertEqual(response.status_code, 200)
        user_ids = ', '.join([str(user.id) for user in users])
        expected_response = "user id(s) {} removed from organization {}'s group {}".format(
            user_ids, organization['id'], groups[0].id)
        self.assertEqual(response.data['detail'], expected_response)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)
        # test users were not removed from organization_two group relation
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization_two['id'],
                                                 groups[0].id)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), len(users))
コード例 #5
0
    def test_organizations_groups_users_get(self):
        organization = self.setup_test_organization()
        organization_two = self.setup_test_organization()
        group = GroupFactory.create()
        users = UserFactory.create_batch(5)
        group.organizations.add(organization['id'])
        group.organizations.add(organization_two['id'])
        for user in users:
            OrganizationGroupUser.objects.create(
                organization_id=organization['id'], group=group, user=user)

        # test when organization group have no users
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization['id'], 1234)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        # test when organization group have users
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization['id'], group.id)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), len(users))
        for i, user in enumerate(response.data):
            self.assertEqual(user['id'], users[i].id)

        # test organization_two group users
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization_two['id'],
                                                 group.id)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)
    def create_course_reference_data(course_key):
        """
        Populates DB with test data
        """
        user = UserFactory()
        group = GroupFactory()
        CourseGroupRelationship(course_id=course_key, group=group).save()
        StudentGradebook(
            user=user,
            course_id=course_key,
            grade=0.9,
            proforma_grade=0.91,
            progress_summary='test',
            grade_summary='test',
            grading_policy='test',
        ).save()
        StudentProgress(user=user, course_id=course_key, completions=1).save()
        CourseModuleCompletion(user=user, course_id=course_key, content_id='test', stage='test').save()
        CourseEnrollment(user=user, course_id=course_key).save()
        CourseAccessRole(user=user, course_id=course_key, org='test', role='TA').save()
        handouts_usage_key = course_key.make_usage_key('course_info', 'handouts')
        StudentModule(student=user, course_id=course_key, module_state_key=handouts_usage_key).save()
        CourseAggregatedMetaData(id=course_key, total_assessments=10, total_modules=20).save()

        structure_json = '{"test": true}'
        course_structure, created = CourseStructure.objects.get_or_create(
            course_id=course_key,
            defaults={'structure_json': structure_json}
        )
        if not created:
            course_structure.structure_json = structure_json
            course_structure.save()

        CourseOverview.get_from_id(course_key)
コード例 #7
0
    def test_groups_groups_detail_invalid_group_id(self):
        related_group = GroupFactory.create()

        # Test with invalid from_group
        test_uri = '{}/{}/groups/{}'.format(self.base_groups_uri, '1234567',
                                            related_group.id)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 404)
コード例 #8
0
    def test_groups_groups_list_missing_group_id(self):
        # Create test group
        from_group = GroupFactory.create()

        # Test with missing group_id in the request data
        test_uri = '{}/{}/groups/'.format(self.base_groups_uri, from_group.id)
        response = self.do_post(test_uri, {})
        self.assertEqual(response.status_code, 400)
コード例 #9
0
    def test_groups_users_list_missing_user_id(self):
        # Create a test group
        group = GroupFactory.create()

        # Test with user_id missing in request data
        test_uri = '{}/{}/users/'.format(self.base_groups_uri, group.id)
        response = self.do_post(test_uri, {})
        self.assertEqual(response.status_code, 400)
コード例 #10
0
    def test_organizations_groups_users_post(self):
        organization = self.setup_test_organization()
        organization_two = self.setup_test_organization()
        groups = GroupFactory.create_batch(2)
        users = UserFactory.create_batch(5)
        groups[0].organizations.add(organization['id'])
        groups[0].organizations.add(organization_two['id'])

        # test for invalid user id
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization['id'],
                                                 groups[1].id)
        data = {'users': '1,qwerty'}
        response = self.do_delete(test_uri, data)
        self.assertEqual(response.status_code, 400)

        # group does not belong to organization
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization['id'],
                                                 groups[1].id)
        data = {'users': ','.join([str(user.id) for user in users])}
        response = self.do_post(test_uri, data)
        self.assertEqual(response.status_code, 404)
        expected_response = "Group {} does not belong to organization {}".format(
            groups[1].id, organization['id'])
        self.assertEqual(response.data['detail'], expected_response)

        # group belong to organization but users does not exit
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization['id'],
                                                 groups[0].id)
        data = {'users': '1234,9912,9800'}
        response = self.do_post(test_uri, data)
        self.assertEqual(response.status_code, 204)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        # group belong to organization and users exist
        data = {'users': ','.join([str(user.id) for user in users])}
        response = self.do_post(test_uri, data)
        self.assertEqual(response.status_code, 201)
        user_ids = ', '.join([str(user.id) for user in users])
        expected_response = "user id(s) {} added to organization {}'s group {}".format(
            user_ids, organization['id'], groups[0].id)
        self.assertEqual(response.data['detail'], expected_response)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), len(users))
        for i, user in enumerate(response.data):
            self.assertEqual(user['id'], users[i].id)
        # test users were not added to organization_two group relation
        test_uri = '{}{}/groups/{}/users'.format(self.base_organizations_uri,
                                                 organization_two['id'],
                                                 groups[0].id)
        response = self.do_get(test_uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)
コード例 #11
0
    def test_groups_courses_list_missing_course_id(self):

        # Create test group
        test_group = GroupFactory.create()

        # Test with missing course_id in the request data
        test_uri = '{}/{}/courses/'.format(self.base_groups_uri, test_group.id)
        data = {"course_id": ""}
        response = self.do_post(test_uri, data)
        self.assertEqual(response.status_code, 400)
コード例 #12
0
    def setUp(self):
        self.course = CourseFactory.create()
        self.instructor = UserFactory.create(username="******",
                                             email="*****@*****.**")
        # Create instructor group for course
        instructor_group = GroupFactory.create(
            name="instructor_MITx/999/Robot_Super_Course")
        instructor_group.user_set.add(self.instructor)

        # Create staff
        self.staff = [UserFactory() for _ in xrange(STAFF_COUNT)]
        staff_group = GroupFactory()
        for staff in self.staff:
            staff_group.user_set.add(staff)  # pylint: disable=E1101

        # Create students
        self.students = [UserFactory() for _ in xrange(STUDENT_COUNT)]
        for student in self.students:
            CourseEnrollmentFactory.create(user=student,
                                           course_id=self.course.id)

        # load initial content (since we don't run migrations as part of tests):
        call_command("loaddata", "course_email_template.json")

        self.client.login(username=self.instructor.username, password="******")

        # Pull up email view on instructor dashboard
        self.url = reverse('instructor_dashboard',
                           kwargs={'course_id': self.course.id})
        response = self.client.get(self.url)
        email_link = '<a href="#" onclick="goto(\'Email\')" class="None">Email</a>'
        # If this fails, it is likely because ENABLE_INSTRUCTOR_EMAIL is set to False
        self.assertTrue(email_link in response.content)

        # Select the Email view of the instructor dash
        session = self.client.session
        session['idash_mode'] = 'Email'
        session.save()
        response = self.client.get(self.url)
        selected_email_link = '<a href="#" onclick="goto(\'Email\')" class="selectedmode">Email</a>'
        self.assertTrue(selected_email_link in response.content)
コード例 #13
0
    def test_edly_panel_user_has_edly_org_access(self):
        """
        Test if a user is edly panel user or edly panel admin user.
        """
        self._create_edly_sub_organization()
        create_user_link_with_edly_sub_organization(self.request,
                                                    self.request.user)

        assert not edly_panel_user_has_edly_org_access(self.request)

        edly_panel_user_group = GroupFactory(
            name=settings.EDLY_PANEL_USERS_GROUP)
        self.request.user.groups.add(edly_panel_user_group)
        assert edly_panel_user_has_edly_org_access(self.request)
コード例 #14
0
ファイル: test_email.py プロジェクト: SarthakDev/edx-platform
    def setUp(self):
        self.course = CourseFactory.create()
        self.instructor = UserFactory.create(username="******", email="*****@*****.**")
        # Create instructor group for course
        instructor_group = GroupFactory.create(name="instructor_MITx/999/Robot_Super_Course")
        instructor_group.user_set.add(self.instructor)

        # Create staff
        self.staff = [UserFactory() for _ in xrange(STAFF_COUNT)]
        staff_group = GroupFactory()
        for staff in self.staff:
            staff_group.user_set.add(staff)  # pylint: disable=E1101

        # Create students
        self.students = [UserFactory() for _ in xrange(STUDENT_COUNT)]
        for student in self.students:
            CourseEnrollmentFactory.create(user=student, course_id=self.course.id)

        # load initial content (since we don't run migrations as part of tests):
        call_command("loaddata", "course_email_template.json")

        self.client.login(username=self.instructor.username, password="******")

        # Pull up email view on instructor dashboard
        self.url = reverse('instructor_dashboard', kwargs={'course_id': self.course.id})
        response = self.client.get(self.url)
        email_link = '<a href="#" onclick="goto(\'Email\')" class="None">Email</a>'
        # If this fails, it is likely because ENABLE_INSTRUCTOR_EMAIL is set to False
        self.assertTrue(email_link in response.content)

        # Select the Email view of the instructor dash
        session = self.client.session
        session['idash_mode'] = 'Email'
        session.save()
        response = self.client.get(self.url)
        selected_email_link = '<a href="#" onclick="goto(\'Email\')" class="selectedmode">Email</a>'
        self.assertTrue(selected_email_link in response.content)