Exemple #1
0
    def setUpClass(cls):
        super().setUpClass()
        cls.store = modulestore()
        cls.course = ToyCourseFactory.create(
            end=datetime(2028, 1, 1, 1, 1, 1),
            enrollment_start=datetime(2020, 1, 1, 1, 1, 1),
            enrollment_end=datetime(2028, 1, 1, 1, 1, 1),
            emit_signals=True,
            modulestore=cls.store,
            certificate_available_date=_NEXT_WEEK,
            certificates_display_behavior=CertificatesDisplayBehaviors.
            END_WITH_DATE)
        cls.chapter = ItemFactory(parent=cls.course, category='chapter')
        cls.sequence = ItemFactory(parent=cls.chapter,
                                   category='sequential',
                                   display_name='sequence')
        cls.unit = ItemFactory.create(parent=cls.sequence,
                                      category='vertical',
                                      display_name="Vertical")

        cls.user = UserFactory(username='******',
                               email='*****@*****.**',
                               password='******',
                               is_staff=False)
        cls.instructor = UserFactory(username='******',
                                     email='*****@*****.**',
                                     password='******',
                                     is_staff=False)
        CourseInstructorRole(cls.course.id).add_users(cls.instructor)
        cls.url = f'/api/courseware/course/{cls.course.id}'
    def setUp(self):
        """
        Regenerate a course with cohort configuration, partition and groups,
        and a student for each test.
        """
        super(TestGetCohortedUserPartition, self).setUp()
        self.course_key = ToyCourseFactory.create().id
        self.course = modulestore().get_course(self.course_key)
        self.student = UserFactory.create()

        self.random_user_partition = UserPartition(
            1,
            'Random Partition',
            'Should not be returned',
            [Group(0, 'Group 0'), Group(1, 'Group 1')],
            scheme=RandomUserPartitionScheme
        )

        self.cohort_user_partition = UserPartition(
            0,
            'Cohort Partition 1',
            'Should be returned',
            [Group(10, 'Group 10'), Group(20, 'Group 20')],
            scheme=CohortPartitionScheme
        )

        self.second_cohort_user_partition = UserPartition(
            2,
            'Cohort Partition 2',
            'Should not be returned',
            [Group(10, 'Group 10'), Group(1, 'Group 1')],
            scheme=CohortPartitionScheme
        )
Exemple #3
0
 def setUp(self):
     super(TestStudentViewTransformer, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.course_key = ToyCourseFactory.create().id
     self.course_usage_key = self.store.make_course_usage_key(
         self.course_key)
     self.block_structure = BlockStructureFactory.create_from_modulestore(
         self.course_usage_key, self.store)
    def setUp(self):
        """
        Regenerate a course with cohort configuration, partition and groups,
        and a student for each test.
        """
        super(TestGetCohortedUserPartition, self).setUp()
        self.course_key = ToyCourseFactory.create().id
        self.course = modulestore().get_course(self.course_key)
        self.student = UserFactory.create()

        self.random_user_partition = UserPartition(
            1,
            'Random Partition',
            'Should not be returned',
            [Group(0, 'Group 0'), Group(1, 'Group 1')],
            scheme=RandomUserPartitionScheme)

        self.cohort_user_partition = UserPartition(
            0,
            'Cohort Partition 1',
            'Should be returned',
            [Group(10, 'Group 10'),
             Group(20, 'Group 20')],
            scheme=CohortPartitionScheme)

        self.second_cohort_user_partition = UserPartition(
            2,
            'Cohort Partition 2',
            'Should not be returned',
            [Group(10, 'Group 10'), Group(1, 'Group 1')],
            scheme=CohortPartitionScheme)
Exemple #5
0
    def setUpClass(cls):
        super().setUpClass()
        cls.store = modulestore()
        cls.course = ToyCourseFactory.create(
            end=datetime(2028, 1, 1, 1, 1, 1),
            enrollment_start=datetime(2020, 1, 1, 1, 1, 1),
            enrollment_end=datetime(2028, 1, 1, 1, 1, 1),
            emit_signals=True,
            modulestore=cls.store,
        )
        cls.chapter = ItemFactory(parent=cls.course, category='chapter')
        cls.sequence = ItemFactory(parent=cls.chapter,
                                   category='sequential',
                                   display_name='sequence')
        cls.unit = ItemFactory.create(parent=cls.sequence,
                                      category='vertical',
                                      display_name="Vertical")

        cls.user = UserFactory(username='******',
                               email=u'*****@*****.**',
                               password='******',
                               is_staff=False)
        cls.instructor = UserFactory(username='******',
                                     email=u'*****@*****.**',
                                     password='******',
                                     is_staff=False)
        CourseInstructorRole(cls.course.id).add_users(cls.instructor)
        cls.url = '/api/courseware/course/{}'.format(cls.course.id)
    def test_parents(self, modulestore_type):
        with self.store.default_store(modulestore_type):

            # setting up our own local course tree here, since it needs to be
            # created with the correct modulestore type.

            if modulestore_type == 'xml':
                course_key = self.store.make_course_key('edX', 'toy', '2012_Fall')
            else:
                course_key = ToyCourseFactory.create(run='2012_Fall_copy').id
            course = self.store.get_course(course_key)

            self.assertIsNone(course.get_parent())

            def recurse(parent):
                """
                Descend the course tree and ensure the result of get_parent()
                is the expected one.
                """
                visited = []
                for child in parent.get_children():
                    self.assertEqual(parent.location, child.get_parent().location)
                    visited.append(child)
                    visited += recurse(child)
                return visited

            visited = recurse(course)
            self.assertEqual(len(visited), 28)
    def test_discussion_student_view_data(self):
        """
        Tests that course block api returns student_view_data for discussion module
        """
        course_key = ToyCourseFactory.create().id
        course_usage_key = self.store.make_course_usage_key(course_key)
        user = UserFactory.create()
        self.client.login(username=user.username, password='******')
        CourseEnrollmentFactory.create(user=user, course_id=course_key)
        discussion_id = "test_discussion_module_id"
        ItemFactory.create(
            parent_location=course_usage_key,
            category='discussion',
            discussion_id=discussion_id,
            discussion_category='Category discussion',
            discussion_target='Target Discussion',
        )

        url = reverse('blocks_in_block_tree', kwargs={'usage_key_string': unicode(course_usage_key)})
        query_params = {
            'depth': 'all',
            'username': user.username,
            'block_types_filter': 'discussion',
            'student_view_data': 'discussion'
        }
        response = self.client.get(url, query_params)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(response.data['root'], unicode(course_usage_key))  # pylint: disable=no-member
        for block_key_string, block_data in response.data['blocks'].iteritems():  # pylint: disable=no-member
            block_key = deserialize_usage_key(block_key_string, course_key)
            self.assertEquals(block_data['id'], block_key_string)
            self.assertEquals(block_data['type'], block_key.block_type)
            self.assertEquals(block_data['display_name'], self.store.get_item(block_key).display_name or '')
            self.assertEqual(block_data['student_view_data'], {"topic_id": discussion_id})
Exemple #8
0
    def test_parents(self, modulestore_type):
        with self.store.default_store(modulestore_type):

            # setting up our own local course tree here, since it needs to be
            # created with the correct modulestore type.

            course_key = ToyCourseFactory.create().id
            course = self.store.get_course(course_key)
            self.assertIsNone(course.get_parent())

            def recurse(parent):
                """
                Descend the course tree and ensure the result of get_parent()
                is the expected one.
                """
                visited = []
                for child in parent.get_children():
                    self.assertEqual(parent.location,
                                     child.get_parent().location)
                    visited.append(child)
                    visited += recurse(child)
                return visited

            visited = recurse(course)
            self.assertEqual(len(visited), 28)
Exemple #9
0
    def test_rerun(self, pacing_type, expected_self_paced_value):
        course_run = ToyCourseFactory()
        start = datetime.datetime.now(pytz.UTC).replace(microsecond=0)
        end = start + datetime.timedelta(days=30)
        user = UserFactory()
        role = 'instructor'
        run = '3T2017'
        url = reverse('api:v1:course_run-rerun', kwargs={'pk': str(course_run.id)})
        data = {
            'run': run,
            'schedule': {
                'start': serialize_datetime(start),
                'end': serialize_datetime(end),
            },
            'team': [
                {
                    'user': user.username,
                    'role': role,
                }
            ],
            'pacing_type': pacing_type,
        }
        response = self.client.post(url, data, format='json')
        assert response.status_code == 201

        course_run_key = CourseKey.from_string(response.data['id'])
        course_run = modulestore().get_course(course_run_key)
        assert course_run.id.run == run
        assert course_run.self_paced is expected_self_paced_value
        self.assert_course_run_schedule(course_run, start, end)
        self.assert_access_role(course_run, user, role)
        self.assert_course_access_role_count(course_run, 1)
 def setUp(self):
     super().setUp()
     self.course_key = ToyCourseFactory.create().id
     self.course_usage_key = self.store.make_course_usage_key(
         self.course_key)
     self.block_structure = BlockStructureFactory.create_from_modulestore(
         self.course_usage_key, self.store)
 def setUpClass(cls):
     super(TestCohortOauth, cls).setUpClass()
     cls.user = UserFactory(username=USERNAME,
                            email=USER_MAIL,
                            password=cls.password)
     cls.staff_user = UserFactory(is_staff=True, password=cls.password)
     cls.course_key = ToyCourseFactory.create().id
     cls.course_str = unicode(cls.course_key)
Exemple #12
0
 def test_rerun_duplicate_run(self):
     course_run = ToyCourseFactory()
     url = reverse('api:v1:course_run-rerun', kwargs={'pk': str(course_run.id)})
     data = {
         'run': course_run.id.run,
     }
     response = self.client.post(url, data, format='json')
     assert response.status_code == 400
     assert response.data == {'run': ['Course run {key} already exists'.format(key=course_run.id)]}
Exemple #13
0
    def create_course(**kwargs):
        """
        Create a course for use in test cases
        """

        return ToyCourseFactory.create(
            end=datetime(2015, 9, 19, 18, 0, 0),
            enrollment_start=datetime(2015, 6, 15, 0, 0, 0),
            enrollment_end=datetime(2015, 7, 15, 0, 0, 0),
            **kwargs)
    def setUpClass(cls):
        super(TestBlockSerializerBase, cls).setUpClass()

        cls.course = ToyCourseFactory.create()

        # Hide the html block
        key = cls.course.id.make_usage_key('html', 'secret:toylab')
        cls.html_block = cls.store.get_item(key)
        cls.html_block.visible_to_staff_only = True
        cls.store.update_item(cls.html_block, ModuleStoreEnum.UserID.test)
    def setUpClass(cls):
        super(TestBlockSerializerBase, cls).setUpClass()

        cls.course = ToyCourseFactory.create()

        # Hide the html block
        key = cls.course.id.make_usage_key('html', 'secret:toylab')
        cls.html_block = cls.store.get_item(key)
        cls.html_block.visible_to_staff_only = True
        cls.store.update_item(cls.html_block, ModuleStoreEnum.UserID.test)
Exemple #16
0
 def setUpClass(cls):
     """
     Set up a course for use in these tests
     """
     super().setUpClass()
     with cls.store.default_store(ModuleStoreEnum.Type.split):
         cls.course = ToyCourseFactory.create(modulestore=cls.store)
     assert str(cls.course.id).startswith(
         "course-v1:"), "This test is for split mongo course exports only"
     cls.unit_key = cls.course.id.make_usage_key('vertical',
                                                 'vertical_test')
Exemple #17
0
    def create_course(**kwargs):
        """
        Create a course for use in test cases
        """

        return ToyCourseFactory.create(
            end=datetime(2015, 9, 19, 18, 0, 0),
            enrollment_start=datetime(2015, 6, 15, 0, 0, 0),
            enrollment_end=datetime(2015, 7, 15, 0, 0, 0),
            **kwargs
        )
    def setUpClass(cls):
        super(TestBlocksView, cls).setUpClass()

        # create a toy course
        cls.course_key = ToyCourseFactory.create().id
        cls.course_usage_key = cls.store.make_course_usage_key(cls.course_key)
        cls.non_orphaned_block_usage_keys = set(
            unicode(item.location)
            for item in cls.store.get_items(cls.course_key)
            # remove all orphaned items in the course, except for the root 'course' block
            if cls.store.get_parent_location(item.location)
            or item.category == 'course')
 def setUp(self):
     super(TestOverrideDataTransformer, self).setUp()
     self.course_key = ToyCourseFactory.create().id
     self.course_usage_key = self.store.make_course_usage_key(self.course_key)
     self.block_structure = BlockStructureFactory.create_from_modulestore(self.course_usage_key, self.store)
     self.course = course = modulestore().get_course(self.course_key)
     section = course.get_children()[0]
     subsection = section.get_children()[0]
     self.block = self.store.create_child(
         self.learner.id, subsection.location, 'html', 'new_component'
     )
     CourseEnrollmentFactory.create(user=self.learner, course_id=self.course_key, is_active=True)
Exemple #20
0
 def test_rerun_invalid_number(self):
     course_run = ToyCourseFactory()
     url = reverse('api:v1:course_run-rerun', kwargs={'pk': str(course_run.id)})
     data = {
         'run': '2T2019',
         'number': '!@#$%^&*()',
     }
     response = self.client.post(url, data, format='json')
     assert response.status_code == 400
     assert response.data == {'non_field_errors': [
         'Invalid key supplied. Ensure there are no special characters in the Course Number.'
     ]}
Exemple #21
0
    def setUpClass(cls):
        super(TestBlocksView, cls).setUpClass()

        # create a toy course
        cls.course_key = ToyCourseFactory.create().id
        cls.course_usage_key = cls.store.make_course_usage_key(cls.course_key)
        cls.non_orphaned_block_usage_keys = set(
            unicode(item.location)
            for item in cls.store.get_items(cls.course_key)
            # remove all orphaned items in the course, except for the root 'course' block
            if cls.store.get_parent_location(item.location) or item.category == 'course'
        )
Exemple #22
0
    def setup_course(cls):
        """
        Create a sample course
        """
        cls.course_key = ToyCourseFactory.create().id

        cls.non_orphaned_block_usage_keys = set(
            unicode(item.location)
            for item in cls.store.get_items(cls.course_key)
            # remove all orphaned items in the course, except for the root 'course' block
            if cls.store.get_parent_location(item.location)
            or item.category == 'course')
    def setup_course(cls):
        """
        Create a sample course
        """
        cls.course_key = ToyCourseFactory.create().id

        cls.non_orphaned_block_usage_keys = set(
            unicode(item.location)
            for item in cls.store.get_items(cls.course_key)
            # remove all orphaned items in the course, except for the root 'course' block
            if cls.store.get_parent_location(item.location) or item.category == 'course'
        )
    def test_rerun(self, pacing_type, expected_self_paced_value, number):
        original_course_run = ToyCourseFactory()
        add_organization({
            'name': 'Test Organization',
            'short_name': original_course_run.id.org,
            'description': 'Testing Organization Description',
        })
        start = datetime.datetime.now(pytz.UTC).replace(microsecond=0)
        end = start + datetime.timedelta(days=30)
        user = UserFactory()
        role = 'instructor'
        run = '3T2017'
        url = reverse('api:v1:course_run-rerun',
                      kwargs={'pk': str(original_course_run.id)})
        data = {
            'run': run,
            'schedule': {
                'start': serialize_datetime(start),
                'end': serialize_datetime(end),
            },
            'team': [{
                'user': user.username,
                'role': role,
            }],
            'pacing_type': pacing_type,
        }
        # If number is supplied, this should become the course number used in the course run key
        # If not, it should default to the original course run number that the rerun is based on.
        if number:
            data.update({'number': number})
        response = self.client.post(url, data, format='json')
        assert response.status_code == 201

        course_run_key = CourseKey.from_string(response.data['id'])
        course_run = modulestore().get_course(course_run_key)

        assert course_run.id.run == run
        assert course_run.self_paced is expected_self_paced_value

        if number:
            assert course_run.id.course == number
            assert course_run.id.course != original_course_run.id.course
        else:
            assert course_run.id.course == original_course_run.id.course

        self.assert_course_run_schedule(course_run, start, end)
        self.assert_access_role(course_run, user, role)
        self.assert_course_access_role_count(course_run, 1)
        course_orgs = get_course_organizations(course_run_key)
        self.assertEqual(len(course_orgs), 1)
        self.assertEqual(course_orgs[0]['short_name'],
                         original_course_run.id.org)
Exemple #25
0
    def setUp(self):
        super(RoleClassTestCase, self).setUp()

        # For course ID, syntax edx/classname/classdate is important
        # because xmodel.course_module.id_to_location looks for a string to split

        self.course_id = ToyCourseFactory.create().id
        self.student_role = models.Role.objects.get_or_create(name="Student", course_id=self.course_id)[0]
        self.student_role.add_permission("delete_thread")
        self.student_2_role = models.Role.objects.get_or_create(name="Student", course_id=self.course_id)[0]
        self.TA_role = models.Role.objects.get_or_create(name="Community TA", course_id=self.course_id)[0]
        self.course_id_2 = CourseKey.from_string("edX/6.002x/2012_Fall")
        self.TA_role_2 = models.Role.objects.get_or_create(name="Community TA", course_id=self.course_id_2)[0]
    def setUp(self):
        """
        Regenerate a test course and cohorts for each test
        """
        super(TestCohortsAndPartitionGroups, self).setUp()

        self.test_course_key = ToyCourseFactory.create().id
        self.course = modulestore().get_course(self.test_course_key)

        self.first_cohort = CohortFactory(course_id=self.course.id, name="FirstCohort")
        self.second_cohort = CohortFactory(course_id=self.course.id, name="SecondCohort")

        self.partition_id = 1
        self.group1_id = 10
        self.group2_id = 20
Exemple #27
0
    def setUp(self):
        """
        Regenerate a test course and cohorts for each test
        """
        super(TestCohortsAndPartitionGroups, self).setUp()

        self.test_course_key = ToyCourseFactory.create().id
        self.course = modulestore().get_course(self.test_course_key)

        self.first_cohort = CohortFactory(course_id=self.course.id, name="FirstCohort")
        self.second_cohort = CohortFactory(course_id=self.course.id, name="SecondCohort")

        self.partition_id = 1
        self.group1_id = 10
        self.group2_id = 20
Exemple #28
0
 def setUpClass(cls):
     super().setUpClass()
     cls.store = modulestore()
     cls.course = ToyCourseFactory.create(
         end=datetime(2028, 1, 1, 1, 1, 1),
         enrollment_start=datetime(2020, 1, 1, 1, 1, 1),
         enrollment_end=datetime(2028, 1, 1, 1, 1, 1),
         emit_signals=True,
         modulestore=cls.store,
     )
     cls.user = UserFactory(username='******',
                            email=u'*****@*****.**',
                            password='******',
                            is_staff=False)
     cls.url = '/api/courseware/course/{}'.format(cls.course.id)
    def test_permissions_query_load(self):
        """
        Tests that the permissions queries are cached when rendering numerous discussion XBlocks.
        """
        user = UserFactory()
        course = ToyCourseFactory()
        course_key = course.id
        course_usage_key = self.store.make_course_usage_key(course_key)
        discussions = []

        for counter in range(5):
            discussion_id = 'test_discussion_{}'.format(counter)
            discussions.append(
                ItemFactory.create(
                    parent_location=course_usage_key,
                    category='discussion',
                    discussion_id=discussion_id,
                    discussion_category='Category discussion',
                    discussion_target='Target Discussion',
                ))

        # 2 queries are required to do first discussion xblock render:
        # * django_comment_client_role
        # * lms_xblock_xblockasidesconfig
        # If the query for roles returned a non-empty result set, there would be
        # an additional query against django_comment_client_permission, but there
        # are no roles associated with this test.
        num_queries = 2
        for discussion in discussions:
            discussion_xblock = get_module_for_descriptor_internal(
                user=user,
                descriptor=discussion,
                student_data=mock.Mock(name='student_data'),
                course_id=course.id,
                track_function=mock.Mock(name='track_function'),
                xqueue_callback_url_prefix=mock.Mock(
                    name='xqueue_callback_url_prefix'),
                request_token='request_token',
            )
            with self.assertNumQueries(num_queries):
                fragment = discussion_xblock.render('student_view')

            # Permissions are cached, so no queries required for subsequent renders
            num_queries = 0

            html = fragment.content
            self.assertIn('data-user-create-comment="false"', html)
            self.assertIn('data-user-create-subcomment="false"', html)
    def test_permissions_query_load(self):
        """
        Tests that the permissions queries are cached when rendering numerous discussion XBlocks.
        """
        user = UserFactory()
        course = ToyCourseFactory()
        course_key = course.id
        course_usage_key = self.store.make_course_usage_key(course_key)
        discussions = []

        for counter in range(5):
            discussion_id = f'test_discussion_{counter}'
            discussions.append(
                ItemFactory.create(
                    parent_location=course_usage_key,
                    category='discussion',
                    discussion_id=discussion_id,
                    discussion_category='Category discussion',
                    discussion_target='Target Discussion',
                ))

        # 7 queries are required to do first discussion xblock render:
        # * split_modulestore_django_splitmodulestorecourseindex x2
        # * waffle_utils_wafflecourseoverridemodel
        # * waffle_utils_waffleorgoverridemodel
        # * waffle_flag
        # * django_comment_client_role
        # * lms_xblock_xblockasidesconfig
        num_queries = 7
        for discussion in discussions:
            discussion_xblock = get_module_for_descriptor_internal(
                user=user,
                descriptor=discussion,
                student_data=mock.Mock(name='student_data'),
                course_id=course.id,
                track_function=mock.Mock(name='track_function'),
                request_token='request_token',
            )
            with self.assertNumQueries(num_queries):
                fragment = discussion_xblock.render('student_view')

            # Permissions are cached, so only 1  query required for subsequent renders
            # to check the waffle flag
            num_queries = 1

            html = fragment.content
            assert 'data-user-create-comment="false"' in html
            assert 'data-user-create-subcomment="false"' in html
Exemple #31
0
    def setUpClass(cls):
        super(TestBlocksView, cls).setUpClass()

        # create a toy course
        cls.course = ToyCourseFactory.create(
            modulestore=cls.store,
            due=datetime(3013, 9, 18, 11, 30, 00),
        )
        cls.course_key = cls.course.id
        cls.course_usage_key = cls.store.make_course_usage_key(cls.course_key)

        cls.non_orphaned_block_usage_keys = set(
            str(item.location) for item in cls.store.get_items(cls.course_key)
            # remove all orphaned items in the course, except for the root 'course' block
            if cls.store.get_parent_location(item.location)
            or item.category == 'course')
    def setUp(self):
        """
        Regenerate a course with cohort configuration, partition and groups,
        and a student for each test.
        """
        super(TestCohortPartitionScheme, self).setUp()

        self.course_key = ToyCourseFactory.create().id
        self.course = modulestore().get_course(self.course_key)
        config_course_cohorts(self.course, is_cohorted=True)

        self.groups = [Group(10, "Group 10"), Group(20, "Group 20")]
        self.user_partition = UserPartition(
            0, "Test Partition", "for testing purposes", self.groups, scheme=CohortPartitionScheme
        )
        self.student = UserFactory.create()
    def test_permissions_query_load(self):
        """
        Tests that the permissions queries are cached when rendering numerous discussion XBlocks.
        """
        user = UserFactory.create()
        course = ToyCourseFactory.create()
        course_key = course.id
        course_usage_key = self.store.make_course_usage_key(course_key)
        discussions = []

        for counter in range(5):
            discussion_id = "test_discussion_{}".format(counter)
            discussions.append(
                ItemFactory.create(
                    parent_location=course_usage_key,
                    category="discussion",
                    discussion_id=discussion_id,
                    discussion_category="Category discussion",
                    discussion_target="Target Discussion",
                )
            )

        # 3 queries are required to do first discussion xblock render:
        # * django_comment_client_role
        # * django_comment_client_permission
        # * lms_xblock_xblockasidesconfig
        num_queries = 3
        for discussion in discussions:
            discussion_xblock = get_module_for_descriptor_internal(
                user=user,
                descriptor=discussion,
                student_data=mock.Mock(name="student_data"),
                course_id=course.id,
                track_function=mock.Mock(name="track_function"),
                xqueue_callback_url_prefix=mock.Mock(name="xqueue_callback_url_prefix"),
                request_token="request_token",
            )
            with self.assertNumQueries(num_queries):
                fragment = discussion_xblock.render("student_view")

            # Permissions are cached, so no queries required for subsequent renders
            num_queries = 0

            html = fragment.content
            self.assertIn('data-user-create-comment="false"', html)
            self.assertIn('data-user-create-subcomment="false"', html)
Exemple #34
0
    def setUpClass(cls):
        super(TestBlocksView, cls).setUpClass()

        # create a toy course
        cls.course = ToyCourseFactory.create(
            modulestore=cls.store,
            due=datetime(3013, 9, 18, 11, 30, 00),
        )
        cls.course_key = cls.course.id
        cls.course_usage_key = cls.store.make_course_usage_key(cls.course_key)

        cls.non_orphaned_block_usage_keys = set(
            six.text_type(item.location)
            for item in cls.store.get_items(cls.course_key)
            # remove all orphaned items in the course, except for the root 'course' block
            if cls.store.get_parent_location(item.location) or item.category == 'course'
        )
Exemple #35
0
    def setUp(self):
        super(RoleClassTestCase, self).setUp()

        # For course ID, syntax edx/classname/classdate is important
        # because xmodel.course_module.id_to_location looks for a string to split

        self.course_id = ToyCourseFactory.create().id
        self.student_role = models.Role.objects.get_or_create(name="Student",
                                                              course_id=self.course_id)[0]
        self.student_role.add_permission("delete_thread")
        self.student_2_role = models.Role.objects.get_or_create(name="Student",
                                                                course_id=self.course_id)[0]
        self.TA_role = models.Role.objects.get_or_create(name="Community TA",
                                                         course_id=self.course_id)[0]
        self.course_id_2 = CourseKey.from_string("edX/6.002x/2012_Fall")
        self.TA_role_2 = models.Role.objects.get_or_create(name="Community TA",
                                                           course_id=self.course_id_2)[0]
    def setUp(self):
        """
        Regenerate a course with cohort configuration, partition and groups,
        and a student for each test.
        """
        super(TestCohortPartitionScheme, self).setUp()

        self.course_key = ToyCourseFactory.create().id
        self.course = modulestore().get_course(self.course_key)
        config_course_cohorts(self.course, is_cohorted=True)

        self.groups = [Group(10, 'Group 10'), Group(20, 'Group 20')]
        self.user_partition = UserPartition(0,
                                            'Test Partition',
                                            'for testing purposes',
                                            self.groups,
                                            scheme=CohortPartitionScheme)
        self.student = UserFactory.create()
Exemple #37
0
 def setUpClass(cls):
     """
     Set up a user, course, and discussion XBlock for use by tests.
     """
     super(TestXBlockInCourse, cls).setUpClass()
     cls.user = UserFactory.create()
     cls.course = ToyCourseFactory.create()
     cls.course_key = cls.course.id
     cls.course_usage_key = cls.store.make_course_usage_key(cls.course_key)
     cls.discussion_id = "test_discussion_xblock_id"
     cls.discussion = ItemFactory.create(
         parent_location=cls.course_usage_key,
         category='discussion',
         discussion_id=cls.discussion_id,
         discussion_category='Category discussion',
         discussion_target='Target Discussion',
     )
     CourseEnrollmentFactory.create(user=cls.user, course_id=cls.course_key)
    def test_discussion_student_view_data(self):
        """
        Tests that course block api returns student_view_data for discussion module
        """
        course_key = ToyCourseFactory.create().id
        course_usage_key = self.store.make_course_usage_key(course_key)
        user = UserFactory.create()
        self.client.login(username=user.username, password='******')
        CourseEnrollmentFactory.create(user=user, course_id=course_key)
        discussion_id = "test_discussion_module_id"
        ItemFactory.create(
            parent_location=course_usage_key,
            category='discussion',
            discussion_id=discussion_id,
            discussion_category='Category discussion',
            discussion_target='Target Discussion',
        )

        url = reverse('blocks_in_block_tree',
                      kwargs={'usage_key_string': unicode(course_usage_key)})
        query_params = {
            'depth': 'all',
            'username': user.username,
            'block_types_filter': 'discussion',
            'student_view_data': 'discussion'
        }
        response = self.client.get(url, query_params)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(response.data['root'], unicode(course_usage_key))  # pylint: disable=no-member
        for block_key_string, block_data in response.data['blocks'].iteritems(
        ):  # pylint: disable=no-member
            block_key = deserialize_usage_key(block_key_string, course_key)
            self.assertEquals(block_data['id'], block_key_string)
            self.assertEquals(block_data['type'], block_key.block_type)
            self.assertEquals(
                block_data['display_name'],
                self.store.get_item(block_key).display_name or '')
            self.assertEqual(block_data['student_view_data'],
                             {"topic_id": discussion_id})
Exemple #39
0
    def setup_course_metadata(self, request):
        """
        Setup course metadata and related database entries for provider state setup.
        """
        course_key = CourseKey.from_string(self.COURSE_KEY)

        self.clean_db(request.user, course_key)
        self.start_modulestore_isolation()

        demo_course = ToyCourseFactory.create(
            org=course_key.org,
            course=course_key.course,
            run=course_key.run,
            display_name="Demonstration Course",
            modulestore=self.store,
            start=datetime(2024, 1, 1, 1, 1, 1),
            end=datetime(2028, 1, 1, 1, 1, 1),
            enrollment_start=datetime(2020, 1, 1, 1, 1, 1),
            enrollment_end=datetime(2028, 1, 1, 1, 1, 1),
            license="all-rights-reserved",
        )

        CourseModeFactory(
            course_id=demo_course.id,
            mode_slug=CourseMode.AUDIT,
        )

        CourseModeFactory(
            course_id=demo_course.id,
            mode_slug=CourseMode.VERIFIED,
            expiration_datetime=datetime(3028, 1, 1),
            min_price=149,
            sku='ABCD1234',
        )

        CourseEnrollment.enroll(request.user, demo_course.id, CourseMode.AUDIT)
        CourseDurationLimitConfig.objects.create(enabled=True,
                                                 enabled_as_of=datetime(
                                                     2018, 1, 1))
Exemple #40
0
 def setUp(self):
     super(TestMongoCoursesLoad, self).setUp()
     self.setup_user()
     self.toy_course_key = ToyCourseFactory.create().id
 def setUp(self):
     """
     Make sure that course is reloaded every time--clear out the modulestore.
     """
     super(TestCohorts, self).setUp()
     self.toy_course_key = ToyCourseFactory.create().id
 def setUp(self):
     super(TestStudentViewTransformer, self).setUp()
     self.course_key = ToyCourseFactory.create().id
     self.course_usage_key = self.store.make_course_usage_key(self.course_key)
     self.block_structure = BlockStructureFactory.create_from_modulestore(self.course_usage_key, self.store)
    def setUpClass(cls):
        super(TestBlockSerializerBase, cls).setUpClass()

        cls.course = ToyCourseFactory.create()
Exemple #44
0
 def setUp(self):
     super(TestMongoCoursesLoad, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.setup_user()
     self.toy_course_key = ToyCourseFactory.create().id
 def setUpClass(cls):
     super(TestCohortOauth, cls).setUpClass()
     cls.user = UserFactory(username=USERNAME, email=USER_MAIL, password=cls.password)
     cls.staff_user = UserFactory(is_staff=True, password=cls.password)
     cls.course_key = ToyCourseFactory.create().id
     cls.course_str = unicode(cls.course_key)
Exemple #46
0
 def setUp(self):
     """
     Make sure that course is reloaded every time--clear out the modulestore.
     """
     super(TestCohorts, self).setUp()
     self.toy_course_key = ToyCourseFactory.create().id
Exemple #47
0
 def setUp(self):
     super(TestMongoCoursesLoad, self).setUp()
     self.setup_user()
     self.toy_course_key = ToyCourseFactory.create().id