コード例 #1
0
    def test_content_library(self):
        """
        Test when course has content library section.
        First test user can't see any content library section,
        and after that mock response from MySQL db.
        Check user can see mocked sections in content library.
        """
        raw_block_structure = get_course_blocks(
            self.user,
            self.course.location,
            transformers=BlockStructureTransformers(),
        )
        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,
            self.transformers,
        )

        # Should dynamically assign a block to student
        trans_keys = set(trans_block_structure.get_block_keys())
        block_key_set = self.get_block_key_set(
            self.blocks, 'course', 'chapter1', 'lesson1', 'vertical1', 'library_content1'
        )
        for key in block_key_set:
            self.assertIn(key, trans_keys)

        vertical2_selected = self.get_block_key_set(self.blocks, 'vertical2').pop() in trans_keys
        vertical3_selected = self.get_block_key_set(self.blocks, 'vertical3').pop() in trans_keys

        self.assertNotEqual(vertical2_selected, vertical3_selected)  # only one of them should be selected
        selected_vertical = 'vertical2' if vertical2_selected else 'vertical3'
        selected_child = 'html1' if vertical2_selected else 'html2'

        # Check course structure again.
        clear_course_from_cache(self.course.id)
        for i in range(5):
            trans_block_structure = get_course_blocks(
                self.user,
                self.course.location,
                self.transformers,
            )
            self.assertEqual(
                set(trans_block_structure.get_block_keys()),
                self.get_block_key_set(
                    self.blocks,
                    'course',
                    'chapter1',
                    'lesson1',
                    'vertical1',
                    'library_content1',
                    selected_vertical,
                    selected_child,
                ),
                u"Expected 'selected' equality failed in iteration {}.".format(i)
            )
コード例 #2
0
    def test_content_library(self):
        """
        Test when course has content library section.
        First test user can't see any content library section,
        and after that mock response from MySQL db.
        Check user can see mocked sections in content library.
        """
        raw_block_structure = get_course_blocks(
            self.user,
            self.course.location,
            transformers=BlockStructureTransformers(),
        )
        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,
            self.transformers,
        )

        # Should dynamically assign a block to student
        trans_keys = set(trans_block_structure.get_block_keys())
        block_key_set = self.get_block_key_set(
            self.blocks, 'course', 'chapter1', 'lesson1', 'vertical1', 'library_content1'
        )
        for key in block_key_set:
            self.assertIn(key, trans_keys)

        vertical2_selected = self.get_block_key_set(self.blocks, 'vertical2').pop() in trans_keys
        vertical3_selected = self.get_block_key_set(self.blocks, 'vertical3').pop() in trans_keys

        self.assertNotEquals(vertical2_selected, vertical3_selected)  # only one of them should be selected
        selected_vertical = 'vertical2' if vertical2_selected else 'vertical3'
        selected_child = 'html1' if vertical2_selected else 'html2'

        # Check course structure again.
        clear_course_from_cache(self.course.id)
        for i in range(5):
            trans_block_structure = get_course_blocks(
                self.user,
                self.course.location,
                self.transformers,
            )
            self.assertEqual(
                set(trans_block_structure.get_block_keys()),
                self.get_block_key_set(
                    self.blocks,
                    'course',
                    'chapter1',
                    'lesson1',
                    'vertical1',
                    'library_content1',
                    selected_vertical,
                    selected_child,
                ),
                "Expected 'selected' equality failed in iteration {}.".format(i)
            )
コード例 #3
0
    def test_content_library(self):
        """
        Test when course has content library section.
        First test user can't see any content library section,
        and after that mock response from MySQL db.
        Check user can see mocked sections in content library.
        """
        raw_block_structure = get_course_blocks(
            self.user,
            self.course.location,
            transformers=BlockStructureTransformers(),
        )
        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,
            self.transformers,
        )

        # Should dynamically assign a block to student
        trans_keys = set(trans_block_structure.get_block_keys())
        block_key_set = self.get_block_key_set(
            self.blocks, 'course', 'chapter1', 'lesson1', 'vertical1', 'library_content1'
        )
        for key in block_key_set:
            self.assertIn(key, trans_keys)

        vertical2_selected = self.get_block_key_set(self.blocks, 'vertical2').pop() in trans_keys
        vertical3_selected = self.get_block_key_set(self.blocks, 'vertical3').pop() in trans_keys
        self.assertTrue(vertical2_selected or vertical3_selected)

        # Check course structure again, with mocked selected modules for a user.
        with mock.patch(
            'lms.djangoapps.course_blocks.transformers.library_content.ContentLibraryTransformer._get_student_module',
            return_value=MockedModule('{"selected": [["vertical", "vertical_vertical2"]]}'),
        ):
            clear_course_from_cache(self.course.id)
            trans_block_structure = get_course_blocks(
                self.user,
                self.course.location,
                self.transformers,
            )
            self.assertEqual(
                set(trans_block_structure.get_block_keys()),
                self.get_block_key_set(
                    self.blocks,
                    'course',
                    'chapter1',
                    'lesson1',
                    'vertical1',
                    'library_content1',
                    'vertical2',
                    'html1'
                )
            )
コード例 #4
0
 def test_query_counts_uncached(self, store_type_tuple, with_storage_backing):
     store_type, expected_mongo_queries = store_type_tuple
     with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
         course = self._create_course(store_type)
         clear_course_from_cache(course.id)
         self._get_blocks(
             course,
             expected_mongo_queries,
             expected_sql_queries=14 if with_storage_backing else 6,
         )
コード例 #5
0
ファイル: test_api.py プロジェクト: haritshah33/edxplatform
 def test_query_counts_uncached(self, store_type_tuple, with_storage_backing):
     store_type, expected_mongo_queries = store_type_tuple
     with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
         course = self._create_course(store_type)
         clear_course_from_cache(course.id)
         self._get_blocks(
             course,
             expected_mongo_queries,
             expected_sql_queries=14 if with_storage_backing else 6,
         )
コード例 #6
0
    def test_content_library(self):
        """
        Test when course has content library section.
        First test user can't see any content library section,
        and after that mock response from MySQL db.
        Check user can see mocked sections in content library.
        """
        raw_block_structure = get_course_blocks(
            self.user,
            self.course.location,
            transformers=BlockStructureTransformers(),
        )
        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,
            self.transformers,
        )

        # Should dynamically assign a block to student
        trans_keys = set(trans_block_structure.get_block_keys())
        block_key_set = self.get_block_key_set(self.blocks, 'course',
                                               'chapter1', 'lesson1',
                                               'vertical1', 'library_content1')
        for key in block_key_set:
            self.assertIn(key, trans_keys)

        vertical2_selected = self.get_block_key_set(
            self.blocks, 'vertical2').pop() in trans_keys
        vertical3_selected = self.get_block_key_set(
            self.blocks, 'vertical3').pop() in trans_keys
        self.assertTrue(vertical2_selected or vertical3_selected)

        # Check course structure again, with mocked selected modules for a user.
        with mock.patch(
                'lms.djangoapps.course_blocks.transformers.library_content.ContentLibraryTransformer._get_student_module',
                return_value=MockedModule(
                    '{"selected": [["vertical", "vertical_vertical2"]]}'),
        ):
            clear_course_from_cache(self.course.id)
            trans_block_structure = get_course_blocks(
                self.user,
                self.course.location,
                self.transformers,
            )
            self.assertEqual(
                set(trans_block_structure.get_block_keys()),
                self.get_block_key_set(self.blocks, 'course', 'chapter1',
                                       'lesson1', 'vertical1',
                                       'library_content1', 'vertical2',
                                       'html1'))
コード例 #7
0
ファイル: test_api.py プロジェクト: edx/edx-platform
    def test_query_counts_uncached(self, store_type, expected_mongo_queries,
                                   with_storage_backing, num_sql_queries):
        with override_waffle_switch(STORAGE_BACKING_FOR_CACHE,
                                    active=with_storage_backing):
            course = self._create_course(store_type)
            clear_course_from_cache(course.id)

            self._get_blocks(
                course,
                expected_mongo_queries,
                expected_sql_queries=num_sql_queries,
            )
コード例 #8
0
    def setUp(self):
        """
        Setup course structure and create user for content library order transformer test.
        """
        super(ContentLibraryOrderTransformerTestCase, self).setUp()
        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)

        # Enroll user in course.
        CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True)
コード例 #9
0
    def setUp(self):
        """
        Setup course structure and create user for content library order transformer test.
        """
        super(ContentLibraryOrderTransformerTestCase, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
        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)

        # Enroll user in course.
        CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id, is_active=True)
コード例 #10
0
    def setUp(self):
        """
        Setup course structure and create user for content library order transformer test.
        """
        super().setUp()
        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)

        # Enroll user in course.
        CourseEnrollmentFactory.create(user=self.user,
                                       course_id=self.course.id,
                                       is_active=True)
コード例 #11
0
 def test_modulestore_performance(self, store_type, expected_mongo_queries):
     """
     Test that a constant number of mongo calls are made regardless of how
     many grade-related blocks are in the course.
     """
     course = [
         {
             u'org': u'GradesTestOrg',
             u'course': u'GB101',
             u'run': u'cannonball',
             u'metadata': {
                 u'format': u'homework'
             },
             u'#type': u'course',
             u'#ref': u'course',
             u'#children': [],
         },
     ]
     for problem_number in xrange(random.randrange(10, 20)):
         course[0][u'#children'].append({
             u'metadata': {
                 u'graded':
                 True,
                 u'weight':
                 1,
                 u'due':
                 datetime.datetime(2099, 3, 15, 12, 30, 0, tzinfo=pytz.utc),
             },
             u'#type':
             u'problem',
             u'#ref':
             u'problem_{}'.format(problem_number),
             u'data':
             u'''
                     <problem>
                         <numericalresponse answer="{number}">
                             <textline label="1*{number}" />
                         </numericalresponse>
                     </problem>'''.format(number=problem_number),
         })
     with self.store.default_store(store_type):
         blocks = self.build_course(course)
     clear_course_from_cache(blocks[u'course'].id)
     with check_mongo_calls(expected_mongo_queries):
         get_course_blocks(self.student, blocks[u'course'].location,
                           self.transformers)
コード例 #12
0
ファイル: views.py プロジェクト: harambee-sa/edx-platform
    def post(self, request, format=None):

        courses_id = request.data.get('courses_id', None)
        success_clear_cache_courses = []
        error_clear_cache_courses = []
        if courses_id and len(courses_id) > 0:
            for course_id in courses_id:
                try:
                    course_key = CourseKey.from_string(course_id)
                    clear_course_from_cache(course_key)
                    success_clear_cache_courses.append(course_id)
                except InvalidKeyError as e:
                    LOGGER.error(str(e))
                    error_clear_cache_courses.append(course_id)

        return Response(
            {
                "success_clear_cache_courses": success_clear_cache_courses,
                "error_clear_cache_courses": error_clear_cache_courses
            },
            status=status.HTTP_200_OK)
コード例 #13
0
ファイル: test_api.py プロジェクト: AlexxNica/edx-platform
    def test_query_counts_uncached(self, store_type_tuple, with_storage_backing):
        store_type, expected_mongo_queries = store_type_tuple
        with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
            course = self._create_course(store_type)
            clear_course_from_cache(course.id)

            if with_storage_backing:
                # TODO: Remove Django 1.11 upgrade shim
                # SHIM: Django 1.11 results in a few more SAVEPOINTs due to:
                # https://github.com/django/django/commit/d44afd88#diff-5b0dda5eb9a242c15879dc9cd2121379L485
                if django.VERSION >= (1, 11):
                    num_sql_queries = 17
                else:
                    num_sql_queries = 15
            else:
                num_sql_queries = 7

            self._get_blocks(
                course,
                expected_mongo_queries,
                expected_sql_queries=num_sql_queries,
            )
コード例 #14
0
 def test_modulestore_performance(self, store_type, expected_mongo_queries):
     """
     Test that a constant number of mongo calls are made regardless of how
     many grade-related blocks are in the course.
     """
     course = [
         {
             u'org': u'GradesTestOrg',
             u'course': u'GB101',
             u'run': u'cannonball',
             u'metadata': {u'format': u'homework'},
             u'#type': u'course',
             u'#ref': u'course',
             u'#children': [],
         },
     ]
     for problem_number in xrange(random.randrange(10, 20)):
         course[0][u'#children'].append(
             {
                 u'metadata': {
                     u'graded': True,
                     u'weight': 1,
                     u'due': datetime.datetime(2099, 3, 15, 12, 30, 0, tzinfo=pytz.utc),
                 },
                 u'#type': u'problem',
                 u'#ref': u'problem_{}'.format(problem_number),
                 u'data': u'''
                     <problem>
                         <numericalresponse answer="{number}">
                             <textline label="1*{number}" />
                         </numericalresponse>
                     </problem>'''.format(number=problem_number),
             }
         )
     with self.store.default_store(store_type):
         blocks = self.build_course(course)
     clear_course_from_cache(blocks[u'course'].id)
     with check_mongo_calls(expected_mongo_queries):
         get_course_blocks(self.student, blocks[u'course'].location, self.transformers)
コード例 #15
0
    def test_query_counts_uncached(self, store_type_tuple, with_storage_backing):
        store_type, expected_mongo_queries = store_type_tuple
        with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
            course = self._create_course(store_type)
            clear_course_from_cache(course.id)

            if with_storage_backing:
                # TODO: Remove Django 1.11 upgrade shim
                # SHIM: Django 1.11 results in a few more SAVEPOINTs due to:
                # https://github.com/django/django/commit/d44afd88#diff-5b0dda5eb9a242c15879dc9cd2121379L485
                if django.VERSION >= (1, 11):
                    num_sql_queries = 16
                else:
                    num_sql_queries = 14
            else:
                num_sql_queries = 6

            self._get_blocks(
                course,
                expected_mongo_queries,
                expected_sql_queries=num_sql_queries,
            )
コード例 #16
0
ファイル: test_api.py プロジェクト: edx/edx-platform
 def test_query_counts_uncached(self, store_type, expected_mongo_queries):
     course = self._create_course(store_type)
     clear_course_from_cache(course.id)
     self._get_blocks(course, expected_mongo_queries)
コード例 #17
0
 def test_query_counts_uncached(self, store_type, expected_mongo_queries):
     course = self._create_course(store_type)
     clear_course_from_cache(course.id)
     self._get_blocks(course, expected_mongo_queries)