def test_partial_credit(self):
     """
     Test that we can see the partial credit value and feedback.
     """
     self.courseware_page.visit()
     problem_page = ProblemPage(self.browser)
     problem_page.wait_for_element_visibility(problem_page.CSS_PROBLEM_HEADER, 'wait for problem header')
     self.assertEqual(problem_page.problem_name, 'PARTIAL CREDIT TEST PROBLEM')
     problem_page.fill_answer_numerical('-1')
     problem_page.click_check()
     problem_page.wait_for_status_icon()
     self.assertTrue(problem_page.simpleprob_is_partially_correct())
 def test_question_with_description(self):
     """
     Scenario: Test that question and description are rendered as expected.
     Given I am enrolled in a course.
     When I visit a unit page with a CAPA question.
     Then label and description should be rendered correctly.
     """
     self.courseware_page.visit()
     problem_page = ProblemPage(self.browser)
     problem_page.wait_for_element_visibility(problem_page.CSS_PROBLEM_HEADER, 'wait for problem header')
     self.assertEqual(problem_page.problem_name, 'Label with Description')
     self.assertEqual(problem_page.problem_question, 'Eggplant is a _____?')
     self.assertEqual(problem_page.problem_question_descriptions, self.descriptions)
示例#3
0
 def test_partial_credit(self):
     """
     Test that we can see the partial credit value and feedback.
     """
     self.courseware_page.visit()
     problem_page = ProblemPage(self.browser)
     problem_page.wait_for_element_visibility(
         problem_page.CSS_PROBLEM_HEADER, 'wait for problem header')
     self.assertEqual(problem_page.problem_name,
                      'PARTIAL CREDIT TEST PROBLEM')
     problem_page.fill_answer_numerical('-1')
     problem_page.click_check()
     problem_page.wait_for_status_icon()
     self.assertTrue(problem_page.simpleprob_is_partially_correct())
示例#4
0
 def test_question_with_description(self):
     """
     Scenario: Test that question and description are rendered as expected.
     Given I am enrolled in a course.
     When I visit a unit page with a CAPA question.
     Then label and description should be rendered correctly.
     """
     self.courseware_page.visit()
     problem_page = ProblemPage(self.browser)
     problem_page.wait_for_element_visibility(
         problem_page.CSS_PROBLEM_HEADER, 'wait for problem header')
     self.assertEqual(problem_page.problem_name, 'Label with Description')
     self.assertEqual(problem_page.problem_question, 'Eggplant is a _____?')
     self.assertEqual(problem_page.problem_question_descriptions,
                      self.descriptions)
示例#5
0
class ProblemTypeTestBase(ProblemsTest, EventsTestMixin):
    """
    Base class for testing assesment problem types in bok choy.

    This inherits from ProblemsTest, which has capabilities for testing problem
    features that are not problem type specific (checking, hinting, etc.).

    The following attributes must be explicitly defined when inheriting from
    this class:
        problem_name (str)
        problem_type (str)
        factory (ResponseXMLFactory subclass instance)

    Additionally, the default values for factory_kwargs and status_indicators
    may need to be overridden for some problem types.
    """
    __metaclass__ = ProblemTypeTestBaseMeta

    problem_name = None
    problem_type = None
    problem_points = 1
    factory = None
    factory_kwargs = {}
    status_indicators = {
        'correct': ['span.correct'],
        'incorrect': ['span.incorrect'],
        'unanswered': ['span.unanswered'],
        'submitted': ['span.submitted'],
    }

    def setUp(self):
        """
        Visits courseware_page and defines self.problem_page.
        """
        super(ProblemTypeTestBase, self).setUp()
        self.courseware_page.visit()
        self.problem_page = ProblemPage(self.browser)

    def get_sequential(self):
        """ Allow any class in the inheritance chain to customize subsection metadata."""
        return XBlockFixtureDesc('sequential', 'Test Subsection', metadata=getattr(self, 'sequential_metadata', {}))

    def get_problem(self):
        """
        Creates a {problem_type} problem
        """
        # Generate the problem XML using capa.tests.response_xml_factory
        return XBlockFixtureDesc(
            'problem',
            self.problem_name,
            data=self.factory.build_xml(**self.factory_kwargs),
            metadata={'rerandomize': 'always', 'show_reset_button': True}
        )

    def wait_for_status(self, status):
        """
        Waits for the expected status indicator.

        Args:
            status: one of ("correct", "incorrect", "unanswered", "submitted")
        """
        msg = "Wait for status to be {}".format(status)
        selector = ', '.join(self.status_indicators[status])
        self.problem_page.wait_for_element_visibility(selector, msg)

    @abstractmethod
    def answer_problem(self, correctness):
        """
        Args:
            `correct` (bool): Inputs correct answer if True, else inputs
                incorrect answer.
        """
        raise NotImplementedError()
class ProblemTypeTestBase(ProblemsTest, EventsTestMixin):
    """
    Base class for testing assesment problem types in bok choy.

    This inherits from ProblemsTest, which has capabilities for testing problem
    features that are not problem type specific (checking, hinting, etc.).

    The following attributes must be explicitly defined when inheriting from
    this class:
        problem_name (str)
        problem_type (str)
        factory (ResponseXMLFactory subclass instance)

    Additionally, the default values for factory_kwargs and status_indicators
    may need to be overridden for some problem types.
    """
    __metaclass__ = ProblemTypeTestBaseMeta

    problem_name = None
    problem_type = None
    factory = None
    factory_kwargs = {}
    status_indicators = {
        'correct': ['span.correct'],
        'incorrect': ['span.incorrect'],
        'unanswered': ['span.unanswered'],
    }

    def setUp(self):
        """
        Visits courseware_page and defines self.problem_page.
        """
        super(ProblemTypeTestBase, self).setUp()
        self.courseware_page.visit()
        self.problem_page = ProblemPage(self.browser)

    def get_problem(self):
        """
        Creates a {problem_type} problem
        """
        # Generate the problem XML using capa.tests.response_xml_factory
        return XBlockFixtureDesc(
            'problem',
            self.problem_name,
            data=self.factory.build_xml(**self.factory_kwargs),
            metadata={'rerandomize': 'always', 'show_reset_button': True}
        )

    def wait_for_status(self, status):
        """
        Waits for the expected status indicator.

        Args:
            status: one of ("correct", "incorrect", "unanswered)
        """
        msg = "Wait for status to be {}".format(status)
        selector = ', '.join(self.status_indicators[status])
        self.problem_page.wait_for_element_visibility(selector, msg)

    @abstractmethod
    def answer_problem(self, correctness):
        """
        Args:
            `correct` (bool): Inputs correct answer if True, else inputs
                incorrect answer.
        """
        raise NotImplementedError()