44
55# pylint: disable=attribute-defined-outside-init
66
7-
7+ from xmodule . capa_block import reset_class # pylint: disable=wrong-import-order
88import json
99import os
1010from datetime import datetime
1818from django .db import connections
1919from django .test import TestCase
2020from django .test .client import RequestFactory
21+ from django .test .utils import override_settings
2122from django .urls import reverse
2223from django .utils .timezone import now
2324from submissions import api as submissions_api
4445from 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
0 commit comments