Merge pull request #17451 from mitodl/fix_outline_aq_course_structure_api
Fixed edX block structure api to load override data
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
API function for retrieving course blocks data
|
||||
"""
|
||||
|
||||
from lms.djangoapps.course_blocks.api import COURSE_BLOCK_ACCESS_TRANSFORMERS, get_course_blocks
|
||||
import lms.djangoapps.course_blocks.api as course_blocks_api
|
||||
from lms.djangoapps.course_blocks.transformers.hidden_content import HiddenContentTransformer
|
||||
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers
|
||||
|
||||
@@ -59,7 +59,7 @@ def get_blocks(
|
||||
include_gated_sections = 'show_gated_sections' in requested_fields
|
||||
|
||||
if user is not None:
|
||||
transformers += COURSE_BLOCK_ACCESS_TRANSFORMERS
|
||||
transformers += course_blocks_api.get_course_block_access_transformers()
|
||||
transformers += [MilestonesAndSpecialExamsTransformer(
|
||||
include_special_exams=include_special_exams,
|
||||
include_gated_sections=include_gated_sections)]
|
||||
@@ -77,7 +77,7 @@ def get_blocks(
|
||||
transformers += [BlockCompletionTransformer()]
|
||||
|
||||
# transform
|
||||
blocks = get_course_blocks(user, usage_key, transformers)
|
||||
blocks = course_blocks_api.get_course_blocks(user, usage_key, transformers)
|
||||
|
||||
# filter blocks by types
|
||||
if block_types_filter:
|
||||
|
||||
@@ -7,6 +7,10 @@ from itertools import product
|
||||
import ddt
|
||||
import django
|
||||
from django.test.client import RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
|
||||
import course_blocks.api as course_blocks_api
|
||||
|
||||
from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache
|
||||
from openedx.core.djangoapps.content.block_structure.config import STORAGE_BACKING_FOR_CACHE, waffle
|
||||
from student.tests.factories import UserFactory
|
||||
@@ -14,6 +18,7 @@ from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import SampleCourseFactory, check_mongo_calls
|
||||
|
||||
|
||||
from ..api import get_blocks
|
||||
|
||||
|
||||
@@ -104,14 +109,14 @@ class TestGetBlocks(SharedModuleStoreTestCase):
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestGetBlocksQueryCounts(SharedModuleStoreTestCase):
|
||||
class TestGetBlocksQueryCountsBase(SharedModuleStoreTestCase):
|
||||
"""
|
||||
Tests query counts for the get_blocks function.
|
||||
Base for the get_blocks tests.
|
||||
"""
|
||||
ENABLED_SIGNALS = ['course_published']
|
||||
|
||||
def setUp(self):
|
||||
super(TestGetBlocksQueryCounts, self).setUp()
|
||||
super(TestGetBlocksQueryCountsBase, self).setUp()
|
||||
|
||||
self.user = UserFactory.create()
|
||||
self.request = RequestFactory().get("/dummy")
|
||||
@@ -133,6 +138,12 @@ class TestGetBlocksQueryCounts(SharedModuleStoreTestCase):
|
||||
with self.assertNumQueries(expected_sql_queries):
|
||||
get_blocks(self.request, course.location, self.user)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestGetBlocksQueryCounts(TestGetBlocksQueryCountsBase):
|
||||
"""
|
||||
Tests query counts for the get_blocks function.
|
||||
"""
|
||||
@ddt.data(
|
||||
*product(
|
||||
(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split),
|
||||
@@ -178,3 +189,56 @@ class TestGetBlocksQueryCounts(SharedModuleStoreTestCase):
|
||||
expected_mongo_queries,
|
||||
expected_sql_queries=num_sql_queries,
|
||||
)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@override_settings(FIELD_OVERRIDE_PROVIDERS=(course_blocks_api.INDIVIDUAL_STUDENT_OVERRIDE_PROVIDER, ))
|
||||
class TestQueryCountsWithIndividualOverrideProvider(TestGetBlocksQueryCountsBase):
|
||||
"""
|
||||
Tests query counts for the get_blocks function when IndividualStudentOverrideProvider is set.
|
||||
"""
|
||||
@ddt.data(
|
||||
*product(
|
||||
(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split),
|
||||
(True, False),
|
||||
)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_query_counts_cached(self, store_type, with_storage_backing):
|
||||
with waffle().override(STORAGE_BACKING_FOR_CACHE, active=with_storage_backing):
|
||||
course = self._create_course(store_type)
|
||||
self._get_blocks(
|
||||
course,
|
||||
expected_mongo_queries=0,
|
||||
expected_sql_queries=7 if with_storage_backing else 6,
|
||||
)
|
||||
|
||||
@ddt.data(
|
||||
*product(
|
||||
((ModuleStoreEnum.Type.mongo, 5), (ModuleStoreEnum.Type.split, 3)),
|
||||
(True, False),
|
||||
)
|
||||
)
|
||||
@ddt.unpack
|
||||
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,
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ Tests for Course Blocks serializers
|
||||
"""
|
||||
from mock import MagicMock
|
||||
|
||||
from lms.djangoapps.course_blocks.api import COURSE_BLOCK_ACCESS_TRANSFORMERS, get_course_blocks
|
||||
from lms.djangoapps.course_blocks.api import get_course_block_access_transformers, get_course_blocks
|
||||
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers
|
||||
from student.roles import CourseStaffRole
|
||||
from student.tests.factories import UserFactory
|
||||
@@ -41,7 +41,9 @@ class TestBlockSerializerBase(SharedModuleStoreTestCase):
|
||||
block_types_to_count=['video'],
|
||||
requested_student_view_data=['video'],
|
||||
)
|
||||
self.transformers = BlockStructureTransformers(COURSE_BLOCK_ACCESS_TRANSFORMERS + [blocks_api_transformer])
|
||||
self.transformers = BlockStructureTransformers(
|
||||
get_course_block_access_transformers() + [blocks_api_transformer]
|
||||
)
|
||||
self.block_structure = get_course_blocks(
|
||||
self.user,
|
||||
self.course.location,
|
||||
|
||||
@@ -6,15 +6,13 @@ from completion.test_utils import CompletionWaffleTestMixin
|
||||
from xblock.core import XBlock
|
||||
from xblock.completable import CompletableXBlockMixin, XBlockCompletionMode
|
||||
|
||||
from lms.djangoapps.course_blocks.api import get_course_blocks
|
||||
from lms.djangoapps.course_api.blocks.transformers.block_completion import BlockCompletionTransformer
|
||||
from lms.djangoapps.course_blocks.transformers.tests.helpers import ModuleStoreTestCase, TransformerRegistryTestMixin
|
||||
from student.tests.factories import UserFactory
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
|
||||
|
||||
|
||||
from ...api import get_course_blocks
|
||||
|
||||
|
||||
class StubAggregatorXBlock(XBlock):
|
||||
"""
|
||||
XBlock to test behaviour of BlockCompletionTransformer
|
||||
|
||||
@@ -7,12 +7,12 @@ from mock import Mock, patch
|
||||
from nose.plugins.attrib import attr
|
||||
|
||||
from gating import api as lms_gating_api
|
||||
from lms.djangoapps.course_blocks.api import get_course_blocks
|
||||
from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStructureTestCase
|
||||
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers
|
||||
from openedx.core.lib.gating import api as gating_api
|
||||
from student.tests.factories import CourseEnrollmentFactory
|
||||
|
||||
from ...api import get_course_blocks
|
||||
from ..milestones import MilestonesAndSpecialExamsTransformer
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user