class RadioProblemTypeBase(ProblemTypeTestBase): """ ProblemTypeTestBase specialization for Radio Problem Type """ problem_name = 'RADIO TEST PROBLEM' problem_type = 'radio' partially_correct = False factory = ChoiceResponseXMLFactory() factory_kwargs = { 'question_text': 'The correct answer is Choice 2', 'choice_type': 'radio', 'choices': [False, False, True, False], 'choice_names': ['Choice 0', 'Choice 1', 'Choice 2', 'Choice 3'], } status_indicators = { 'correct': ['label.choicegroup_correct'], 'incorrect': ['label.choicegroup_incorrect', 'span.incorrect'], 'unanswered': ['span.unanswered'], 'submitted': ['label.choicegroup_submitted', 'span.submitted'], } def answer_problem(self, correctness): """ Answer radio problem. """ if correctness == 'correct': self.problem_page.click_choice("choice_2") else: self.problem_page.click_choice("choice_1")
class RadioProblemTypeTest(ProblemTypeTestBase, ProblemTypeTestMixin): """ TestCase Class for Radio Problem Type """ problem_name = 'RADIO TEST PROBLEM' problem_type = 'radio' factory = ChoiceResponseXMLFactory() factory_kwargs = { 'question_text': 'The correct answer is Choice 2', 'choice_type': 'radio', 'choices': [False, False, True, False], 'choice_names': ['Choice 0', 'Choice 1', 'Choice 2', 'Choice 3'], } status_indicators = { 'correct': ['label.choicegroup_correct'], 'incorrect': ['label.choicegroup_incorrect', 'span.incorrect'], 'unanswered': ['span.unanswered'], } def setUp(self, *args, **kwargs): """ Additional setup for RadioProblemTypeTest """ super(RadioProblemTypeTest, self).setUp(*args, **kwargs) def answer_problem(self, correct): """ Answer radio problem. """ if correct: self.problem_page.click_choice("choice_2") else: self.problem_page.click_choice("choice_1")
class CheckboxProblemTypeBase(ProblemTypeTestBase): """ ProblemTypeTestBase specialization Checkbox Problem Type """ problem_name = 'CHECKBOX TEST PROBLEM' problem_type = 'checkbox' partially_correct = True factory = ChoiceResponseXMLFactory() factory_kwargs = { 'question_text': 'The correct answer is Choice 0 and Choice 2, Choice 1 and Choice 3 together are incorrect.', 'choice_type': 'checkbox', 'credit_type': 'edc', 'choices': [True, False, True, False], 'choice_names': ['Choice 0', 'Choice 1', 'Choice 2', 'Choice 3'], 'explanation_text': 'This is explanation text' } def answer_problem(self, correctness): """ Answer checkbox problem. """ if correctness == 'correct': self.problem_page.click_choice("choice_0") self.problem_page.click_choice("choice_2") elif correctness == 'partially-correct': self.problem_page.click_choice("choice_2") else: self.problem_page.click_choice("choice_1") self.problem_page.click_choice("choice_3")
class CheckboxProblemTypeTest(ProblemTypeTestBase, ProblemTypeTestMixin): """ TestCase Class for Checkbox Problem Type """ problem_name = 'CHECKBOX TEST PROBLEM' problem_type = 'checkbox' partially_correct = True factory = ChoiceResponseXMLFactory() factory_kwargs = { 'question_text': 'The correct answer is Choice 0 and Choice 2, Choice 1 and Choice 3 together are incorrect.', 'choice_type': 'checkbox', 'credit_type': 'edc', 'choices': [True, False, True, False], 'choice_names': ['Choice 0', 'Choice 1', 'Choice 2', 'Choice 3'], 'explanation_text': 'This is explanation text' } def setUp(self, *args, **kwargs): """ Additional setup for CheckboxProblemTypeTest """ super(CheckboxProblemTypeTest, self).setUp(*args, **kwargs) def answer_problem(self, correctness): """ Answer checkbox problem. """ if correctness == 'correct': self.problem_page.click_choice("choice_0") self.problem_page.click_choice("choice_2") elif correctness == 'partially-correct': self.problem_page.click_choice("choice_2") else: self.problem_page.click_choice("choice_1") self.problem_page.click_choice("choice_3") @attr(shard=7) def test_can_show_answer(self): """ Scenario: Verifies that show answer button is working as expected. Given that I am on courseware page And I can see a CAPA problem with show answer button When I click "Show Answer" button And I should see question's solution And I should see correct choices highlighted """ self.problem_page.click_show() self.assertTrue(self.problem_page.is_solution_tag_present()) self.assertTrue( self.problem_page.is_correct_choice_highlighted( correct_choices=[1, 3])) self.problem_page.wait_for_focus_on_problem_meta()
class CheckboxProblemTypeTest(ProblemTypeTestBase, ProblemTypeTestMixin): """ TestCase Class for Checkbox Problem Type """ problem_name = 'CHECKBOX TEST PROBLEM' problem_type = 'checkbox' factory = ChoiceResponseXMLFactory() factory_kwargs = { 'question_text': 'The correct answer is Choice 0 and Choice 2', 'choice_type': 'checkbox', 'choices': [True, False, True, False], 'choice_names': ['Choice 0', 'Choice 1', 'Choice 2', 'Choice 3'], 'explanation_text': 'This is explanation text' } def setUp(self, *args, **kwargs): """ Additional setup for CheckboxProblemTypeTest """ super(CheckboxProblemTypeTest, self).setUp(*args, **kwargs) def answer_problem(self, correct): """ Answer checkbox problem. """ if correct: self.problem_page.click_choice("choice_0") self.problem_page.click_choice("choice_2") else: self.problem_page.click_choice("choice_1") @attr('shard_7') def test_can_show_hide_answer(self): """ Scenario: Verifies that show/hide answer button is working as expected. Given that I am on courseware page And I can see a CAPA problem with show answer button When I click "Show Answer" button Then I should see "Hide Answer" text on button And I should see question's solution And I should see correct choices highlighted When I click "Hide Answer" button Then I should see "Show Answer" text on button And I should not see question's solution And I should not see correct choices highlighted """ self.problem_page.click_show_hide_button() self.assertTrue(self.problem_page.is_solution_tag_present()) self.assertTrue(self.problem_page.is_correct_choice_highlighted(correct_choices=[1, 3])) self.problem_page.click_show_hide_button() self.assertFalse(self.problem_page.is_solution_tag_present()) self.assertFalse(self.problem_page.is_correct_choice_highlighted(correct_choices=[1, 3]))
class RadioProblemTypeBase(ProblemTypeTestBase): """ ProblemTypeTestBase specialization for Radio Problem Type """ problem_name = 'RADIO TEST PROBLEM' problem_type = 'radio' partially_correct = False factory = ChoiceResponseXMLFactory() factory_kwargs = { 'question_text': 'The correct answer is Choice 2', 'choice_type': 'radio', 'choices': [False, False, True, False], 'choice_names': ['Choice 0', 'Choice 1', 'Choice 2', 'Choice 3'], } status_indicators = { 'correct': ['label.choicegroup_correct'], 'incorrect': ['label.choicegroup_incorrect', 'span.incorrect'], 'unanswered': ['span.unanswered'], 'submitted': ['label.choicegroup_submitted', 'span.submitted'], } def problem_status(self, status): """ Returns the status of problem Args: status(string): status of the problem which is to be checked Returns: True: If provided status is present on the page False: If provided status is not present on the page """ selector = ', '.join(self.status_indicators[status]) try: self.problem_page.wait_for_element_visibility(selector, 'Status not present', timeout=10) return True except BrokenPromise: return False def answer_problem(self, correctness): """ Answer radio problem. """ if correctness == 'correct': self.problem_page.click_choice("choice_2") else: self.problem_page.click_choice("choice_1")
class CheckboxProblemTypeTest(ProblemTypeTestBase, ProblemTypeTestMixin): """ TestCase Class for Checkbox Problem Type """ problem_name = 'CHECKBOX TEST PROBLEM' problem_type = 'checkbox' factory = ChoiceResponseXMLFactory() factory_kwargs = { 'question_text': 'The correct answer is Choice 0 and Choice 2', 'choice_type': 'checkbox', 'choices': [True, False, True, False], 'choice_names': ['Choice 0', 'Choice 1', 'Choice 2', 'Choice 3'] } def setUp(self, *args, **kwargs): """ Additional setup for CheckboxProblemTypeTest """ super(CheckboxProblemTypeTest, self).setUp(*args, **kwargs) self.problem_page.a11y_audit.config.set_rules({ 'ignore': [ 'section', # TODO: wcag2aa 'aria-allowed-attr', # TODO: AC-251 'aria-valid-attr', # TODO: AC-251 'aria-roles', # TODO: AC-251 'checkboxgroup', # TODO: AC-251 ] }) def answer_problem(self, correct): """ Answer checkbox problem. """ if correct: self.problem_page.click_choice("choice_0") self.problem_page.click_choice("choice_2") else: self.problem_page.click_choice("choice_1")
'incorrect': ['span.incorrect'], 'unanswered': ['span.unanswered'] }, 'multiple choice': { 'factory': MultipleChoiceResponseXMLFactory(), 'kwargs': { 'question_text': 'The correct answer is Choice 3', 'choices': [False, False, True, False], 'choice_names': ['choice_0', 'choice_1', 'choice_2', 'choice_3'] }, 'correct': ['label.choicegroup_correct', 'span.correct'], 'incorrect': ['label.choicegroup_incorrect', 'span.incorrect'], 'unanswered': ['span.unanswered'] }, 'checkbox': { 'factory': ChoiceResponseXMLFactory(), 'kwargs': { 'question_text': 'The correct answer is Choices 1 and 3', 'choice_type': 'checkbox', 'choices': [True, False, True, False, False], 'choice_names': ['Choice 1', 'Choice 2', 'Choice 3', 'Choice 4'] }, 'correct': ['span.correct'], 'incorrect': ['span.incorrect'], 'unanswered': ['span.unanswered'] }, 'radio': { 'factory': ChoiceResponseXMLFactory(), 'kwargs': { 'question_text': 'The correct answer is Choice 3', 'choice_type': 'radio',