""" Bok choy acceptance tests for problems in the LMS """ from textwrap import dedent from common.test.acceptance.fixtures.course import CourseFixture, XBlockFixtureDesc from common.test.acceptance.pages.common.auto_auth import AutoAuthPage from common.test.acceptance.pages.lms.courseware import CoursewarePage from common.test.acceptance.pages.lms.problem import ProblemPage from common.test.acceptance.tests.helpers import UniqueCourseTest from openedx.core.lib.tests import attr class ProblemsTest(UniqueCourseTest): """ Base class for tests of problems in the LMS. """ def setUp(self): super().setUp() self.username = "test_student_{uuid}".format(uuid=self.unique_id[0:8]) self.email = f"{self.username}@example.com" self.password = "keep it secret; keep it safe." self.xqueue_grade_response = None self.courseware_page = CoursewarePage(self.browser, self.course_id) # Install a course with a hierarchy and problems course_fixture = CourseFixture( self.course_info['org'], self.course_info['number'], self.course_info['run'], self.course_info['display_name'] ) problem = self.get_problem() sequential = self.get_sequential() course_fixture.add_children( XBlockFixtureDesc('chapter', 'Test Section').add_children( sequential.add_children(problem) ) ).install() # Auto-auth register for the course. AutoAuthPage( self.browser, username=self.username, email=self.email, password=self.password, course_id=self.course_id, staff=True ).visit() def get_problem(self): """ Subclasses should override this to complete the fixture """ raise NotImplementedError() def get_sequential(self): """ Subclasses can override this to add a sequential with metadata """ return XBlockFixtureDesc('sequential', 'Test Subsection') class CAPAProblemA11yBaseTestMixin: """Base TestCase Class to verify CAPA problem accessibility.""" def test_a11y(self): """ Verifies that there are no accessibility issues for a particular problem type """ self.courseware_page.visit() problem_page = ProblemPage(self.browser) # Set the scope to the problem question problem_page.a11y_audit.config.set_scope( include=['.wrapper-problem-response'] ) # Run the accessibility audit. problem_page.a11y_audit.check_for_accessibility_errors() @attr('a11y') class CAPAProblemChoiceA11yTest(CAPAProblemA11yBaseTestMixin, ProblemsTest): """TestCase Class to verify accessibility for checkboxes and multiplechoice CAPA problems.""" def get_problem(self): """ Problem structure. """ xml = dedent(""" description 2 text 1 description 2 text 2 True False description 2 text 1 description 2 text 2 Alpha A hint Beta """) return XBlockFixtureDesc('problem', 'Problem A11Y TEST', data=xml) @attr('a11y') class ProblemTextInputA11yTest(CAPAProblemA11yBaseTestMixin, ProblemsTest): """TestCase Class to verify TextInput problem accessibility.""" def get_problem(self): """ TextInput problem XML. """ xml = dedent(""" Appear weak when you are strong, and strong when you are weak. In the midst of chaos, there is also opportunity. The supreme art of war is to subdue the enemy without fighting. Great results, can be achieved with small forces. """) return XBlockFixtureDesc('problem', 'TEXTINPUT PROBLEM', data=xml) @attr('a11y') class CAPAProblemDropDownA11yTest(CAPAProblemA11yBaseTestMixin, ProblemsTest): """TestCase Class to verify accessibility for dropdowns(optioninput) CAPA problems.""" def get_problem(self): """ Problem structure. """ xml = dedent("""

You can use this template as a guide to the simple editor markdown and OLX markup to use for dropdown problems. Edit this component to replace this template with your own assessment.

Choose wisely
""") return XBlockFixtureDesc('problem', 'Problem A11Y TEST', data=xml) @attr('a11y') class ProblemNumericalInputA11yTest(CAPAProblemA11yBaseTestMixin, ProblemsTest): """Tests NumericalInput accessibility.""" def get_problem(self): """NumericalInput problem XML.""" xml = dedent(""" Use scientific notation to answer. """) return XBlockFixtureDesc('problem', 'NUMERICALINPUT PROBLEM', data=xml) @attr('a11y') class ProblemMathExpressionInputA11yTest(CAPAProblemA11yBaseTestMixin, ProblemsTest): """Tests MathExpressionInput accessibility.""" def get_problem(self): """MathExpressionInput problem XML.""" xml = dedent(r""" Enter the equation """) return XBlockFixtureDesc('problem', 'MATHEXPRESSIONINPUT PROBLEM', data=xml)