Skip to content

Commit 6cbcc8d

Browse files
committed
fix: enable extracted problem block tests
1 parent 2f9fb4f commit 6cbcc8d

6 files changed

Lines changed: 264 additions & 36 deletions

File tree

lms/djangoapps/courseware/tests/test_submitting_problems.py

Lines changed: 119 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# pylint: disable=attribute-defined-outside-init
66

7-
7+
from xmodule.capa_block import reset_class # pylint: disable=wrong-import-order
88
import json
99
import os
1010
from datetime import datetime
@@ -18,6 +18,7 @@
1818
from django.db import connections
1919
from django.test import TestCase
2020
from django.test.client import RequestFactory
21+
from django.test.utils import override_settings
2122
from django.urls import reverse
2223
from django.utils.timezone import now
2324
from submissions import api as submissions_api
@@ -44,10 +45,16 @@
4445
from xmodule.partitions.partitions import Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order
4546

4647

47-
class ProblemSubmissionTestMixin(TestCase):
48+
class BaseProblemSubmissionTestMixin(TestCase):
4849
"""
4950
TestCase mixin that provides functions to submit answers to problems.
5051
"""
52+
__test__ = False
53+
54+
def setUp(self):
55+
reset_class()
56+
super().setUp()
57+
5158
def refresh_course(self):
5259
"""
5360
Re-fetch the course from the database so that the object being dealt with has everything added to it.
@@ -135,7 +142,19 @@ def show_question_answer(self, problem_url_name):
135142
return resp
136143

137144

138-
class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase, ProblemSubmissionTestMixin):
145+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
146+
class ProblemSubmissionTestMixinBuiltin(BaseProblemSubmissionTestMixin):
147+
"""Run tests against the built-in problem block."""
148+
__test__ = True
149+
150+
151+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
152+
class ProblemSubmissionTestMixinExtracted(BaseProblemSubmissionTestMixin):
153+
"""Run tests against the extracted problem block."""
154+
__test__ = True
155+
156+
157+
class BaseTestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase, BaseProblemSubmissionTestMixin):
139158
"""
140159
Check that a course gets graded properly.
141160
"""
@@ -149,7 +168,10 @@ class TestSubmittingProblems(ModuleStoreTestCase, LoginEnrollmentTestCase, Probl
149168
ENABLED_CACHES = ['default', 'mongo_metadata_inheritance', 'loc_cache']
150169
ENABLED_SIGNALS = ['course_published']
151170

171+
__test__ = False
172+
152173
def setUp(self):
174+
reset_class()
153175
super().setUp()
154176

155177
# create a test student
@@ -306,11 +328,26 @@ def score_for_hw(self, hw_url_name):
306328
return [s.earned for s in self.hw_grade(hw_url_name).problem_scores.values()]
307329

308330

309-
class TestCourseGrades(TestSubmittingProblems):
331+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
332+
class TestSubmittingProblemsBuiltin(BaseTestSubmittingProblems):
333+
"""Run tests against the built-in problem block."""
334+
__test__ = True
335+
336+
337+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
338+
class TestSubmittingProblemsExtracted(BaseTestSubmittingProblems):
339+
"""Run tests against the extracted problem block."""
340+
__test__ = True
341+
342+
343+
class BaseTestCourseGrades(BaseTestSubmittingProblems):
310344
"""
311345
Tests grades are updated correctly when manipulating problems.
312346
"""
347+
__test__ = False
348+
313349
def setUp(self):
350+
reset_class()
314351
super().setUp()
315352
self.homework = self.add_graded_section_to_course('homework')
316353
self.problem = self.add_dropdown_to_section(self.homework.location, 'p1', 1)
@@ -341,13 +378,30 @@ def test_problem_reset(self):
341378
self._verify_grade(expected_problem_score=(0.0, 1.0), expected_hw_grade=(0.0, 1.0))
342379

343380

381+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
382+
class TestCourseGradesBuiltin(BaseTestCourseGrades):
383+
"""Run tests against the built-in problem block."""
384+
__test__ = True
385+
386+
387+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
388+
class TestCourseGradesExtracted(BaseTestCourseGrades):
389+
"""Run tests against the extracted problem block."""
390+
__test__ = True
391+
392+
344393
@ddt.ddt
345-
class TestCourseGrader(TestSubmittingProblems):
394+
class BaseTestCourseGrader(BaseTestSubmittingProblems):
346395
"""
347396
Suite of tests for the course grader.
348397
"""
349398
# Tell Django to clean out all databases, not just default
350399
databases = set(connections)
400+
__test__ = False
401+
402+
def setUp(self):
403+
reset_class()
404+
super().setUp()
351405

352406
def basic_setup(self, late=False, reset=False, showanswer=False):
353407
"""
@@ -757,12 +811,27 @@ def test_min_grade_credit_requirements_status(self, mode):
757811
assert req_status[0]['status'] == 'satisfied'
758812

759813

760-
class ProblemWithUploadedFilesTest(TestSubmittingProblems):
814+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
815+
class TestCourseGraderBuiltin(BaseTestCourseGrader):
816+
"""Run tests against the built-in problem block."""
817+
__test__ = True
818+
819+
820+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
821+
class TestCourseGraderExtracted(BaseTestCourseGrader):
822+
"""Run tests against the extracted problem block."""
823+
__test__ = True
824+
825+
826+
class BaseProblemWithUploadedFilesTest(BaseTestSubmittingProblems):
761827
"""Tests of problems with uploaded files."""
762828
# Tell Django to clean out all databases, not just default
763829
databases = set(connections)
764830

831+
__test__ = False
832+
765833
def setUp(self):
834+
reset_class()
766835
super().setUp()
767836
self.section = self.add_graded_section_to_course('section')
768837

@@ -811,8 +880,20 @@ def test_three_files(self, mock_xqueue_post):
811880
self.assertEqual(list(kwargs['files'].keys()), filenames.split())
812881

813882

883+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
884+
class ProblemWithUploadedFilesTestBuiltin(BaseProblemWithUploadedFilesTest):
885+
"""Run tests against the built-in problem block."""
886+
__test__ = True
887+
888+
889+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
890+
class ProblemWithUploadedFilesTestExtracted(BaseProblemWithUploadedFilesTest):
891+
"""Run tests against the extracted problem block."""
892+
__test__ = True
893+
894+
814895
@UseUnsafeCodejail()
815-
class TestPythonGradedResponse(TestSubmittingProblems):
896+
class BaseTestPythonGradedResponse(BaseTestSubmittingProblems):
816897
"""
817898
Check that we can submit a schematic and custom response, and it answers properly.
818899
"""
@@ -907,7 +988,10 @@ def strip_q(x):
907988
COMPUTED_ANSWER_CORRECT = "a shout in the street"
908989
COMPUTED_ANSWER_INCORRECT = "because we never let them in"
909990

991+
__test__ = False
992+
910993
def setUp(self):
994+
reset_class()
911995
super().setUp()
912996
self.section = self.add_graded_section_to_course('section')
913997
self.correct_responses = {}
@@ -1059,16 +1143,31 @@ def test_computed_reset(self):
10591143
self._check_ireset(name)
10601144

10611145

1062-
class TestConditionalContent(TestSubmittingProblems):
1146+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
1147+
class TestPythonGradedResponseBuiltin(BaseTestPythonGradedResponse):
1148+
"""Run tests against the built-in problem block."""
1149+
__test__ = True
1150+
1151+
1152+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
1153+
class TestPythonGradedResponseExtracted(BaseTestPythonGradedResponse):
1154+
"""Run tests against the extracted problem block."""
1155+
__test__ = True
1156+
1157+
1158+
class BaseTestConditionalContent(BaseTestSubmittingProblems):
10631159
"""
10641160
Check that conditional content works correctly with grading.
10651161
"""
1162+
__test__ = False
1163+
10661164
def setUp(self):
10671165
"""
10681166
Set up a simple course with a grading policy, a UserPartition, and 2 sections, both graded as "homework".
10691167
One section is pre-populated with a problem (with 2 inputs), visible to all students.
10701168
The second section is empty. Test cases should add conditional content to it.
10711169
"""
1170+
reset_class()
10721171
super().setUp()
10731172

10741173
self.user_partition_group_0 = 0
@@ -1265,3 +1364,15 @@ def test_split_one_group_no_problems_group_1(self):
12651364
# homework_2_score = 1.0 / 1
12661365
# round((homework_1_score + homework_2_score) / 2) == .75
12671366
self.check_grade_percent(.75)
1367+
1368+
1369+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
1370+
class TestConditionalContentBuiltin(BaseTestConditionalContent):
1371+
"""Run tests against the built-in problem block."""
1372+
__test__ = True
1373+
1374+
1375+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
1376+
class TestConditionalContentExtracted(BaseTestConditionalContent):
1377+
"""Run tests against the extracted problem block."""
1378+
__test__ = True

lms/djangoapps/grades/tests/integration/test_problems.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# lint-amnesty, pylint: disable=missing-module-docstring
2+
from xmodule.capa_block import reset_class # pylint: disable=wrong-import-order
23
import datetime
34
import itertools
45

56
import ddt
67
import pytz
78
from crum import set_current_request
9+
from django.test.utils import override_settings
810
from xmodule.graders import ProblemScore
911
from xmodule.modulestore import ModuleStoreEnum
1012
from xmodule.modulestore.tests.django_utils import (
@@ -25,10 +27,11 @@
2527

2628

2729
@ddt.ddt
28-
class TestMultipleProblemTypesSubsectionScores(SharedModuleStoreTestCase):
30+
class BaseTestMultipleProblemTypesSubsectionScores(SharedModuleStoreTestCase):
2931
"""
3032
Test grading of different problem types.
3133
"""
34+
__test__ = False
3235
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
3336

3437
SCORED_BLOCK_COUNT = 7
@@ -42,6 +45,7 @@ def setUpClass(cls):
4245
cls.seq1 = chapter1.get_children()[0]
4346

4447
def setUp(self):
48+
reset_class()
4549
super().setUp()
4650
self.student = UserFactory.create(is_staff=False, username='test_student', password=self.TEST_PASSWORD)
4751
self.client.login(username=self.student.username, password=self.TEST_PASSWORD)
@@ -98,12 +102,25 @@ def test_score_submission_for_all_problems(self):
98102
assert score.all_total.possible == (possible_per_block * block_count)
99103

100104

105+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
106+
class TestMultipleProblemTypesSubsectionScoresBuiltin(BaseTestMultipleProblemTypesSubsectionScores):
107+
"""Run rescoring tests against the built-in problem block."""
108+
__test__ = True
109+
110+
111+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
112+
class TestMultipleProblemTypesSubsectionScoresExtracted(BaseTestMultipleProblemTypesSubsectionScores):
113+
"""Run rescoring tests against the extracted problem block."""
114+
__test__ = True
115+
116+
101117
@ddt.ddt
102-
class TestVariedMetadata(ProblemSubmissionTestMixin, ModuleStoreTestCase):
118+
class BaseTestVariedMetadata(ProblemSubmissionTestMixin, ModuleStoreTestCase):
103119
"""
104120
Test that changing the metadata on a block has the desired effect on the
105121
persisted score.
106122
"""
123+
__test__ = False
107124
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
108125

109126
default_problem_metadata = {
@@ -113,6 +130,7 @@ class TestVariedMetadata(ProblemSubmissionTestMixin, ModuleStoreTestCase):
113130
}
114131

115132
def setUp(self):
133+
reset_class()
116134
super().setUp()
117135
self.course = CourseFactory.create()
118136
with self.store.bulk_operations(self.course.id):
@@ -209,11 +227,24 @@ def test_graded_metadata_alterations(self, alterations, expected_earned, expecte
209227
assert score.graded_total.possible == expected_possible
210228

211229

230+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
231+
class TestVariedMetadataBuiltin(BaseTestVariedMetadata):
232+
"""Run rescoring tests against the built-in problem block."""
233+
__test__ = True
234+
235+
236+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
237+
class TestVariedMetadataExtracted(BaseTestVariedMetadata):
238+
"""Run rescoring tests against the extracted problem block."""
239+
__test__ = True
240+
241+
212242
@ddt.ddt
213-
class TestWeightedProblems(SharedModuleStoreTestCase):
243+
class BaseTestWeightedProblems(SharedModuleStoreTestCase):
214244
"""
215245
Test scores and grades with various problem weight values.
216246
"""
247+
__test__ = False
217248
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
218249

219250
@classmethod
@@ -237,6 +268,7 @@ def setUpClass(cls):
237268
)
238269

239270
def setUp(self):
271+
reset_class()
240272
super().setUp()
241273
self.user = UserFactory()
242274
self.addCleanup(set_current_request, None)
@@ -315,3 +347,15 @@ def test_problem_weight(self, raw_earned, raw_possible, weight):
315347
first_attempted=datetime.datetime(2010, 1, 1),
316348
)
317349
self._verify_grades(raw_earned, raw_possible, weight, expected_score)
350+
351+
352+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=False)
353+
class TestWeightedProblemsBuiltin(BaseTestWeightedProblems):
354+
"""Run rescoring tests against the built-in problem block."""
355+
__test__ = True
356+
357+
358+
@override_settings(USE_EXTRACTED_PROBLEM_BLOCK=True)
359+
class TestWeightedProblemsExtracted(BaseTestWeightedProblems):
360+
"""Run rescoring tests against the extracted problem block."""
361+
__test__ = True

0 commit comments

Comments
 (0)