Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/tests/test_contentstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ def test_prefetch_children(self):
# so we don't need to make an extra query to compute it.
# set the branch to 'publish' in order to prevent extra lookups of draft versions
with self.store.branch_setting(ModuleStoreEnum.Branch.published_only, self.course.id):
with check_mongo_calls(3):
with check_mongo_calls(4):
course = self.store.get_course(self.course.id, depth=2)

# make sure we pre-fetched a known sequential which should be at depth=2
Expand All @@ -1133,7 +1133,7 @@ def test_prefetch_children(self):
# Now, test with the branch set to draft. No extra round trips b/c it doesn't go deep enough to get
# beyond direct only categories
with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
with check_mongo_calls(3):
with check_mongo_calls(4):
self.store.get_course(self.course.id, depth=2)

def _check_verticals(self, locations):
Expand Down
2 changes: 2 additions & 0 deletions cms/djangoapps/contentstore/tests/test_courseware_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from xmodule.modulestore.tests.django_utils import ( # lint-amnesty, pylint: disable=wrong-import-order
ModuleStoreTestCase,
TEST_DATA_MONGO_MODULESTORE,
TEST_DATA_SPLIT_MODULESTORE,
SharedModuleStoreTestCase,
)
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -868,6 +869,7 @@ class GroupConfigurationSearchSplit(CourseTestCase, MixedWithOptionsTestCase):
"""
CREATE_USER = True
INDEX_NAME = CoursewareSearchIndexer.INDEX_NAME
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE

def setUp(self):
super().setUp()
Expand Down
16 changes: 0 additions & 16 deletions cms/djangoapps/contentstore/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import check_exact_number_of_calls, check_number_of_calls
from xmodule.modulestore.xml_importer import import_course_from_xml

TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
Expand Down Expand Up @@ -175,21 +174,6 @@ def test_tab_name_imports_correctly(self):
print(f"course tabs = {course.tabs}")
self.assertEqual(course.tabs[1]['name'], 'Syllabus')

def test_import_performance_mongo(self):
store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo)

# we try to refresh the inheritance tree for each update_item in the import
with check_exact_number_of_calls(store, 'refresh_cached_metadata_inheritance_tree', 28):

# _get_cached_metadata_inheritance_tree should be called once
with check_exact_number_of_calls(store, '_get_cached_metadata_inheritance_tree', 1):

# with bulk-edit in progress, the inheritance tree should be recomputed only at the end of the import
# NOTE: On Jenkins, with memcache enabled, the number of calls here is 1.
# Locally, without memcache, the number of calls is 1 (publish no longer counted)
with check_number_of_calls(store, '_compute_metadata_inheritance_tree', 1):
self.load_test_import_course(create_if_not_present=False, module_store=store)

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_reimport(self, default_ms_type):
with modulestore().default_store(default_ms_type):
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/tests/test_orphan.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_get_orphans(self, default_store):

@ddt.data(
(ModuleStoreEnum.Type.split, 5, 3),
(ModuleStoreEnum.Type.mongo, 34, 12),
(ModuleStoreEnum.Type.mongo, 34, 11),
)
@ddt.unpack
def test_delete_orphans(self, default_store, max_mongo_calls, min_mongo_calls):
Expand Down
31 changes: 1 addition & 30 deletions cms/djangoapps/contentstore/views/tests/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,35 +167,6 @@ def _get_container_preview_with_error(self, usage_key, expected_code, data=None,
self.assertContains(resp, content_contains, status_code=expected_code)
return resp

@ddt.data(
(1, 17, 15, 16, 12),
(2, 17, 15, 16, 12),
(3, 17, 15, 16, 12),
)
@ddt.unpack
def test_get_query_count(self, branching_factor, chapter_queries, section_queries, unit_queries, problem_queries):
self.populate_course(branching_factor)
# Retrieve it
with check_mongo_calls(chapter_queries):
self.client.get(reverse_usage_url('xblock_handler', self.populated_usage_keys['chapter'][-1]))
with check_mongo_calls(section_queries):
self.client.get(reverse_usage_url('xblock_handler', self.populated_usage_keys['sequential'][-1]))
with check_mongo_calls(unit_queries):
self.client.get(reverse_usage_url('xblock_handler', self.populated_usage_keys['vertical'][-1]))
with check_mongo_calls(problem_queries):
self.client.get(reverse_usage_url('xblock_handler', self.populated_usage_keys['problem'][-1]))

@ddt.data(
(1, 30),
(2, 32),
(3, 34),
)
@ddt.unpack
def test_container_get_query_count(self, branching_factor, unit_queries,):
self.populate_course(branching_factor)
with check_mongo_calls(unit_queries):
self.client.get(reverse_usage_url('xblock_container_handler', self.populated_usage_keys['vertical'][-1]))

def test_get_vertical(self):
# Add a vertical
resp = self.create_xblock(category='vertical')
Expand Down Expand Up @@ -2565,7 +2536,7 @@ def test_json_responses(self):

@ddt.data(
(ModuleStoreEnum.Type.split, 3, 3),
(ModuleStoreEnum.Type.mongo, 5, 7),
(ModuleStoreEnum.Type.mongo, 8, 12),
)
@ddt.unpack
def test_xblock_outline_handler_mongo_calls(self, store_type, chapter_queries, chapter_queries_1):
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/course_api/blocks/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def test_query_counts_cached(self, store_type, with_storage_backing):
)

@ddt.data(
(ModuleStoreEnum.Type.mongo, 5, True, 24),
(ModuleStoreEnum.Type.mongo, 5, False, 14),
(ModuleStoreEnum.Type.mongo, 19, True, 24),
(ModuleStoreEnum.Type.mongo, 19, False, 14),
(ModuleStoreEnum.Type.split, 2, True, 24),
(ModuleStoreEnum.Type.split, 2, False, 14),
)
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/course_api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class TestCourseDetailSerializer(TestCourseSerializer): # lint-amnesty, pylint:

"""
# 1 mongo call is made to get the course About overview text.
expected_mongo_calls = 1
expected_mongo_calls = 2
serializer_class = CourseDetailSerializer

def setUp(self):
Expand Down
8 changes: 4 additions & 4 deletions lms/djangoapps/grades/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def test_block_structure_created_only_once(self):
assert mock_block_structure_create.call_count == 1

@ddt.data(
(ModuleStoreEnum.Type.mongo, 1, 41, True),
(ModuleStoreEnum.Type.mongo, 1, 41, False),
(ModuleStoreEnum.Type.mongo, 2, 41, True),
(ModuleStoreEnum.Type.mongo, 2, 41, False),
(ModuleStoreEnum.Type.split, 2, 41, True),
(ModuleStoreEnum.Type.split, 2, 41, False),
)
Expand All @@ -167,7 +167,7 @@ def test_query_counts(self, default_store, num_mongo_calls, num_sql_calls, creat
self._apply_recalculate_subsection_grade()

@ddt.data(
(ModuleStoreEnum.Type.mongo, 1, 41),
(ModuleStoreEnum.Type.mongo, 2, 41),
(ModuleStoreEnum.Type.split, 2, 41),
)
@ddt.unpack
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_other_inaccessible_subsection(self, mock_subsection_signal):
)

@ddt.data(
(ModuleStoreEnum.Type.mongo, 1, 41),
(ModuleStoreEnum.Type.mongo, 2, 41),
(ModuleStoreEnum.Type.split, 2, 41),
)
@ddt.unpack
Expand Down
10 changes: 5 additions & 5 deletions lms/djangoapps/grades/tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytz
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import check_mongo_calls
from xmodule.modulestore.tests.factories import check_mongo_calls_range

from common.djangoapps.student.tests.factories import UserFactory
from lms.djangoapps.course_blocks.api import get_course_blocks
Expand Down Expand Up @@ -429,11 +429,11 @@ def setUp(self):
self.client.login(username=self.student.username, password=password)

@ddt.data(
(ModuleStoreEnum.Type.split, 2),
(ModuleStoreEnum.Type.mongo, 2),
(ModuleStoreEnum.Type.split, 2, 2),
(ModuleStoreEnum.Type.mongo, 22, 15),
)
@ddt.unpack
def test_modulestore_performance(self, store_type, expected_mongo_queries):
def test_modulestore_performance(self, store_type, max_mongo_calls, min_mongo_calls):
"""
Test that a constant number of mongo calls are made regardless of how
many grade-related blocks are in the course.
Expand Down Expand Up @@ -470,5 +470,5 @@ def test_modulestore_performance(self, store_type, expected_mongo_queries):
with self.store.default_store(store_type):
blocks = self.build_course(course)
clear_course_from_cache(blocks['course'].id)
with check_mongo_calls(expected_mongo_queries):
with check_mongo_calls_range(max_mongo_calls, min_mongo_calls):
get_course_blocks(self.student, blocks['course'].location, self.transformers)
8 changes: 3 additions & 5 deletions lms/djangoapps/instructor_task/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,13 @@ def _extract_and_round_numeric_items(dictionary):
"""
csv data may contain numeric values that are converted to strings, and fractional
numbers can be imprecise (e.g. 1 / 6 is sometimes '0.16666666666666666' and other times
'0.166666666667'). This function mutates the provided input (sorry) and returns
a new dictionary that contains only the numerically-valued items from it, rounded
to four decimal places.
'0.166666666667'). This function returns a new dictionary that contains only the
numerically-valued items from it, rounded to four decimal places.
"""
extracted = {}
for key in list(dictionary):
try:
float(dictionary[key])
extracted[key] = round(float(dictionary.pop(key)), 4)
extracted[key] = round(float(dictionary[key]), 4)
except ValueError:
pass
return extracted
Expand Down
5 changes: 2 additions & 3 deletions lms/djangoapps/instructor_task/tests/test_tasks_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def test_certificate_eligibility(self):
self._verify_cell_data_for_user(verified_user.username, course.id, 'Certificate Eligible', 'Y', num_rows=2)

@ddt.data(
(ModuleStoreEnum.Type.mongo, 4, 47),
(ModuleStoreEnum.Type.mongo, 6, 47),
(ModuleStoreEnum.Type.split, 2, 48),
)
@ddt.unpack
Expand Down Expand Up @@ -1779,8 +1779,7 @@ def create_course(self):
self.define_option_problem('Unreleased', parent=self.unreleased_section)

@patch.dict(settings.FEATURES, {'DISABLE_START_DATES': False})
@ddt.data(True, False)
def test_grade_report(self, persistent_grades_enabled):
def test_grade_report(self):
self.submit_student_answer(self.student.username, 'Problem1', ['Option 1'])

with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'):
Expand Down
14 changes: 7 additions & 7 deletions lms/djangoapps/lti_provider/tests/test_outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,15 @@ def test_create_two_lti_consumers_with_empty_instance_guid(self):
assert count == 3

def test_with_no_graded_assignments(self):
with check_mongo_calls(3):
with check_mongo_calls(7):
assignments = outcomes.get_assignments_for_problem(
self.unit, self.user_id, self.course.id
)
assert len(assignments) == 0

def test_with_graded_unit(self):
self.create_graded_assignment(self.unit, 'graded_unit', self.outcome_service)
with check_mongo_calls(3):
with check_mongo_calls(7):
assignments = outcomes.get_assignments_for_problem(
self.unit, self.user_id, self.course.id
)
Expand All @@ -388,7 +388,7 @@ def test_with_graded_unit(self):

def test_with_graded_vertical(self):
self.create_graded_assignment(self.vertical, 'graded_vertical', self.outcome_service)
with check_mongo_calls(3):
with check_mongo_calls(7):
assignments = outcomes.get_assignments_for_problem(
self.unit, self.user_id, self.course.id
)
Expand All @@ -398,7 +398,7 @@ def test_with_graded_vertical(self):
def test_with_graded_unit_and_vertical(self):
self.create_graded_assignment(self.unit, 'graded_unit', self.outcome_service)
self.create_graded_assignment(self.vertical, 'graded_vertical', self.outcome_service)
with check_mongo_calls(3):
with check_mongo_calls(7):
assignments = outcomes.get_assignments_for_problem(
self.unit, self.user_id, self.course.id
)
Expand All @@ -409,7 +409,7 @@ def test_with_graded_unit_and_vertical(self):
def test_with_unit_used_twice(self):
self.create_graded_assignment(self.unit, 'graded_unit', self.outcome_service)
self.create_graded_assignment(self.unit, 'graded_unit2', self.outcome_service)
with check_mongo_calls(3):
with check_mongo_calls(7):
assignments = outcomes.get_assignments_for_problem(
self.unit, self.user_id, self.course.id
)
Expand All @@ -420,7 +420,7 @@ def test_with_unit_used_twice(self):
def test_with_unit_graded_for_different_user(self):
self.create_graded_assignment(self.unit, 'graded_unit', self.outcome_service)
other_user = UserFactory.create()
with check_mongo_calls(3):
with check_mongo_calls(7):
assignments = outcomes.get_assignments_for_problem(
self.unit, other_user.id, self.course.id
)
Expand All @@ -430,7 +430,7 @@ def test_with_unit_graded_for_multiple_consumers(self):
other_outcome_service = self.create_outcome_service('second_consumer')
self.create_graded_assignment(self.unit, 'graded_unit', self.outcome_service)
self.create_graded_assignment(self.unit, 'graded_unit2', other_outcome_service)
with check_mongo_calls(3):
with check_mongo_calls(7):
assignments = outcomes.get_assignments_for_problem(
self.unit, self.user_id, self.course.id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def test_malformed_grading_policy(self):
course_overview = CourseOverview._create_or_update(course) # pylint: disable=protected-access
assert course_overview.lowest_passing_grade is None

@ddt.data((ModuleStoreEnum.Type.mongo, 4, 4), (ModuleStoreEnum.Type.split, 2, 2))
@ddt.data((ModuleStoreEnum.Type.mongo, 5, 5), (ModuleStoreEnum.Type.split, 2, 2))
@ddt.unpack
def test_versioning(self, modulestore_type, min_mongo_calls, max_mongo_calls):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CourseOverviewSignalsTestCase(ModuleStoreTestCase):
TODAY = datetime.datetime.utcnow()
NEXT_WEEK = TODAY + datetime.timedelta(days=7)

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
@ddt.data(ModuleStoreEnum.Type.split)
def test_caching(self, modulestore_type):
"""
Tests that CourseOverview structures are actually getting cached.
Expand Down
Loading