feat: AuthZ for course authoring compatibility layer (#38013)
This commit is contained in:
@@ -10,6 +10,7 @@ from django.test.client import RequestFactory
|
||||
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache
|
||||
from openedx.core.djangolib.testing.utils import AUTHZ_TABLES
|
||||
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
|
||||
from xmodule.modulestore.tests.factories import SampleCourseFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order
|
||||
@@ -17,6 +18,8 @@ from xmodule.modulestore.tests.sample_courses import BlockInfo # lint-amnesty,
|
||||
|
||||
from ..api import get_blocks
|
||||
|
||||
QUERY_COUNT_TABLE_IGNORELIST = AUTHZ_TABLES
|
||||
|
||||
|
||||
class TestGetBlocks(SharedModuleStoreTestCase):
|
||||
"""
|
||||
@@ -196,7 +199,7 @@ class TestGetBlocksQueryCountsBase(SharedModuleStoreTestCase):
|
||||
get_blocks on the given course.
|
||||
"""
|
||||
with check_mongo_calls(expected_mongo_queries):
|
||||
with self.assertNumQueries(expected_sql_queries):
|
||||
with self.assertNumQueries(expected_sql_queries, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
|
||||
get_blocks(self.request, course.location, self.user)
|
||||
|
||||
|
||||
@@ -212,11 +215,11 @@ class TestGetBlocksQueryCounts(TestGetBlocksQueryCountsBase):
|
||||
self._get_blocks(
|
||||
course,
|
||||
expected_mongo_queries=0,
|
||||
expected_sql_queries=14,
|
||||
expected_sql_queries=16,
|
||||
)
|
||||
|
||||
@ddt.data(
|
||||
(ModuleStoreEnum.Type.split, 2, 24),
|
||||
(ModuleStoreEnum.Type.split, 2, 26),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_query_counts_uncached(self, store_type, expected_mongo_queries, num_sql_queries):
|
||||
|
||||
@@ -16,10 +16,14 @@ from lms.djangoapps.gating import api as lms_gating_api
|
||||
import openedx.core.djangoapps.content.block_structure.api as bs_api
|
||||
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers
|
||||
from openedx.core.djangoapps.course_apps.toggles import EXAMS_IDA
|
||||
from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES
|
||||
from openedx.core.djangolib.testing.utils import AUTHZ_TABLES
|
||||
from openedx.core.lib.gating import api as gating_api
|
||||
|
||||
from ..milestones import MilestonesAndSpecialExamsTransformer
|
||||
|
||||
QUERY_COUNT_TABLE_IGNORELIST = WAFFLE_TABLES + AUTHZ_TABLES
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_SPECIAL_EXAMS': True})
|
||||
@@ -171,7 +175,7 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM
|
||||
# get data back. This would happen as a part of publishing in a production system.
|
||||
bs_api.update_course_in_cache(self.course.id)
|
||||
|
||||
with self.assertNumQueries(4):
|
||||
with self.assertNumQueries(6, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
|
||||
self.get_blocks_and_check_against_expected(self.user, expected_blocks_before_completion)
|
||||
|
||||
# clear the request cache to simulate a new request
|
||||
@@ -184,7 +188,7 @@ class MilestonesTransformerTestCase(CourseStructureTestCase, MilestonesTestCaseM
|
||||
self.user,
|
||||
)
|
||||
|
||||
with self.assertNumQueries(4):
|
||||
with self.assertNumQueries(4, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
|
||||
self.get_blocks_and_check_against_expected(self.user, self.ALL_BLOCKS_EXCEPT_SPECIAL)
|
||||
|
||||
def test_staff_access(self):
|
||||
|
||||
Reference in New Issue
Block a user