Exemplo n.º 1
0
 def redefine_option_problem(self, problem_url_name):
     """Change the problem definition so the answer is Option 2"""
     factory = OptionResponseXMLFactory()
     factory_args = {'question_text': 'The correct answer is {0}'.format(OPTION_2),
                     'options': [OPTION_1, OPTION_2],
                     'correct_option': OPTION_2,
                     'num_responses': 2}
     problem_xml = factory.build_xml(**factory_args)
     location = InstructorTaskTestCase.problem_location(problem_url_name)
     self.module_store.update_item(location, problem_xml)
Exemplo n.º 2
0
 def redefine_option_problem(self, problem_url_name, correct_answer=OPTION_1, num_inputs=1, num_responses=2):
     """Change the problem definition so the answer is Option 2"""
     factory = OptionResponseXMLFactory()
     factory_args = self._option_problem_factory_args(correct_answer, num_inputs, num_responses)
     problem_xml = factory.build_xml(**factory_args)
     location = InstructorTaskTestCase.problem_location(problem_url_name)
     item = self.module_store.get_item(location)
     with self.module_store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, location.course_key):
         item.data = problem_xml
         self.module_store.update_item(item, self.user.id)
         self.module_store.publish(location, self.user.id)
Exemplo n.º 3
0
 def redefine_option_problem(self, problem_url_name, correct_answer=OPTION_1, num_inputs=1, num_responses=2):
     """Change the problem definition so the answer is Option 2"""
     factory = OptionResponseXMLFactory()
     factory_args = self._option_problem_factory_args(correct_answer, num_inputs, num_responses)
     problem_xml = factory.build_xml(**factory_args)
     location = InstructorTaskTestCase.problem_location(problem_url_name)
     item = self.module_store.get_item(location)
     with self.module_store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, location.course_key):
         item.data = problem_xml
         self.module_store.update_item(item, self.user.id)
         self.module_store.publish(location, self.user.id)
Exemplo n.º 4
0
 def define_option_problem(self, problem_url_name):
     """Create the problem definition so the answer is Option 1"""
     factory = OptionResponseXMLFactory()
     factory_args = {'question_text': 'The correct answer is {0}'.format(OPTION_1),
                     'options': [OPTION_1, OPTION_2],
                     'correct_option': OPTION_1,
                     'num_responses': 2}
     problem_xml = factory.build_xml(**factory_args)
     ItemFactory.create(parent_location=self.problem_section.location,
                        category="problem",
                        display_name=str(problem_url_name),
                        data=problem_xml)
Exemplo n.º 5
0
 def define_option_problem(self, problem_url_name, parent=None, **kwargs):
     """Create the problem definition so the answer is Option 1"""
     if parent is None:
         parent = self.problem_section
     factory = OptionResponseXMLFactory()
     factory_args = self._option_problem_factory_args()
     problem_xml = factory.build_xml(**factory_args)
     ItemFactory.create(parent_location=parent.location,
                        parent=parent,
                        category="problem",
                        display_name=problem_url_name,
                        data=problem_xml,
                        **kwargs)
Exemplo n.º 6
0
 def define_option_problem(self, problem_url_name, parent=None, **kwargs):
     """Create the problem definition so the answer is Option 1"""
     if parent is None:
         parent = self.problem_section
     factory = OptionResponseXMLFactory()
     factory_args = self._option_problem_factory_args()
     problem_xml = factory.build_xml(**factory_args)
     return ItemFactory.create(parent_location=parent.location,
                               parent=parent,
                               category="problem",
                               display_name=problem_url_name,
                               data=problem_xml,
                               **kwargs)
Exemplo n.º 7
0
 def redefine_option_problem(self, problem_url_name):
     """Change the problem definition so the answer is Option 2"""
     factory = OptionResponseXMLFactory()
     factory_args = {'question_text': 'The correct answer is {0}'.format(OPTION_2),
                     'options': [OPTION_1, OPTION_2],
                     'correct_option': OPTION_2,
                     'num_responses': 2}
     problem_xml = factory.build_xml(**factory_args)
     location = InstructorTaskTestCase.problem_location(problem_url_name)
     item = self.module_store.get_item(location)
     with self.module_store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, location.course_key):
         item.data = problem_xml
         self.module_store.update_item(item, self.user.id)
         self.module_store.publish(location, self.user.id)
Exemplo n.º 8
0
 def redefine_option_problem(self, problem_url_name):
     """Change the problem definition so the answer is Option 2"""
     factory = OptionResponseXMLFactory()
     factory_args = {'question_text': 'The correct answer is {0}'.format(OPTION_2),
                     'options': [OPTION_1, OPTION_2],
                     'correct_option': OPTION_2,
                     'num_responses': 2}
     problem_xml = factory.build_xml(**factory_args)
     location = InstructorTaskTestCase.problem_location(problem_url_name)
     item = self.module_store.get_item(location)
     with self.module_store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, location.course_key):
         item.data = problem_xml
         self.module_store.update_item(item, self.user.id)
         self.module_store.publish(location, self.user.id)
Exemplo n.º 9
0
class DropDownProblemTypeTest(ProblemTypeTestBase, ProblemTypeTestMixin):
    """
    TestCase Class for Drop Down Problem Type
    """
    problem_name = 'DROP DOWN TEST PROBLEM'
    problem_type = 'drop down'

    factory = OptionResponseXMLFactory()

    factory_kwargs = {
        'question_text': 'The correct answer is Option 2',
        'options': ['Option 1', 'Option 2', 'Option 3', 'Option 4'],
        'correct_option': 'Option 2'
    }

    def setUp(self, *args, **kwargs):
        """
        Additional setup for DropDownProblemTypeTest
        """
        super(DropDownProblemTypeTest, self).setUp(*args, **kwargs)
        self.problem_page.a11y_audit.config.set_rules({
            'ignore': [
                'section',  # TODO: wcag2aa
                'label',  # TODO: AC-291
            ]
        })

    def answer_problem(self, correct):
        """
        Answer drop down problem.
        """
        answer = 'Option 2' if correct else 'Option 3'
        selector_element = self.problem_page.q(
            css='.problem .option-input select')
        select_option_by_text(selector_element, answer)
Exemplo n.º 10
0
    def add_dropdown_to_section(self, section_location, name, num_inputs=2):
        """
        Create and return a dropdown problem.

        section_location: location object of section in which to create the problem
            (problems must live in a section to be graded properly)

        name: string name of the problem

        num_input: the number of input fields to create in the problem
        """

        prob_xml = OptionResponseXMLFactory().build_xml(
            question_text='The correct answer is Correct',
            num_inputs=num_inputs,
            weight=num_inputs,
            options=['Correct', 'Incorrect', u'ⓤⓝⓘⓒⓞⓓⓔ'],
            correct_option='Correct'
        )

        problem = ItemFactory.create(
            parent_location=section_location,
            category='problem',
            data=prob_xml,
            metadata={'rerandomize': 'always'},
            display_name=name
        )

        # re-fetch the course from the database so the object is up to date
        self.refresh_course()
        return problem
Exemplo n.º 11
0
class DropDownProblemTypeBase(ProblemTypeTestBase):
    """
    ProblemTypeTestBase specialization for Drop Down Problem Type
    """
    problem_name = 'DROP DOWN TEST PROBLEM'
    problem_type = 'drop down'

    partially_correct = False

    factory = OptionResponseXMLFactory()

    factory_kwargs = {
        'question_text': 'The correct answer is Option 2',
        'options': ['Option 1', 'Option 2', 'Option 3', 'Option 4'],
        'correct_option': 'Option 2'
    }

    def answer_problem(self, correctness):
        """
        Answer drop down problem.
        """
        answer = 'Option 2' if correctness == 'correct' else 'Option 3'
        selector_element = self.problem_page.q(
            css='.problem .option-input select')
        select_option_by_text(selector_element, answer)
Exemplo n.º 12
0
    def setUp(self):
        self.user = UserFactory.create()
        self.request = RequestFactory().get('/')
        self.request.user = self.user
        self.request.session = {}
        self.course = CourseFactory.create()

        problem_xml = OptionResponseXMLFactory().build_xml(
            question_text='The correct answer is Correct',
            num_inputs=2,
            weight=2,
            options=['Correct', 'Incorrect'],
            correct_option='Correct'
        )
        self.descriptor = ItemFactory.create(
            category='problem',
            data=problem_xml,
            display_name='Option Response Problem'
        )

        self.location = self.descriptor.location
        self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
            self.course.id,
            self.user,
            self.descriptor
        )
Exemplo n.º 13
0
 def setUpClass(cls):
     super(MasqueradeTestCase, cls).setUpClass()
     cls.course = CourseFactory.create(
         number='masquerade-test', metadata={'start': datetime.now(UTC)})
     cls.info_page = ItemFactory.create(category="course_info",
                                        parent_location=cls.course.location,
                                        data="OOGIE BLOOGIE",
                                        display_name="updates")
     cls.chapter = ItemFactory.create(
         parent_location=cls.course.location,
         category="chapter",
         display_name="Test Section",
     )
     cls.sequential_display_name = "Test Masquerade Subsection"
     cls.sequential = ItemFactory.create(
         parent_location=cls.chapter.location,
         category="sequential",
         display_name=cls.sequential_display_name,
     )
     cls.vertical = ItemFactory.create(
         parent_location=cls.sequential.location,
         category="vertical",
         display_name="Test Unit",
     )
     problem_xml = OptionResponseXMLFactory().build_xml(
         question_text='The correct answer is Correct',
         num_inputs=2,
         weight=2,
         options=['Correct', 'Incorrect'],
         correct_option='Correct')
     cls.problem_display_name = "TestMasqueradeProblem"
     cls.problem = ItemFactory.create(parent_location=cls.vertical.location,
                                      category='problem',
                                      data=problem_xml,
                                      display_name=cls.problem_display_name)
Exemplo n.º 14
0
class DropDownProblemTypeTest(ProblemTypeTestBase, ProblemTypeTestMixin):
    """
    TestCase Class for Drop Down Problem Type
    """
    problem_name = 'DROP DOWN TEST PROBLEM'
    problem_type = 'drop down'

    partially_correct = False

    factory = OptionResponseXMLFactory()

    factory_kwargs = {
        'question_text': 'The correct answer is Option 2',
        'options': ['Option 1', 'Option 2', 'Option 3', 'Option 4'],
        'correct_option': 'Option 2'
    }

    def setUp(self, *args, **kwargs):
        """
        Additional setup for DropDownProblemTypeTest
        """
        super(DropDownProblemTypeTest, self).setUp(*args, **kwargs)

    def answer_problem(self, correctness):
        """
        Answer drop down problem.
        """
        answer = 'Option 2' if correctness == 'correct' else 'Option 3'
        selector_element = self.problem_page.q(
            css='.problem .option-input select')
        select_option_by_text(selector_element, answer)
Exemplo n.º 15
0
 def define_option_problem(self, problem_url_name, parent=None, **kwargs):
     """Create the problem definition so the answer is Option 1"""
     if parent is None:
         parent = self.problem_section
     factory = OptionResponseXMLFactory()
     factory_args = {
         "question_text": "The correct answer is {0}".format(OPTION_1),
         "options": [OPTION_1, OPTION_2],
         "correct_option": OPTION_1,
         "num_responses": 2,
     }
     problem_xml = factory.build_xml(**factory_args)
     ItemFactory.create(
         parent_location=parent.location,
         parent=parent,
         category="problem",
         display_name=problem_url_name,
         data=problem_xml,
         **kwargs
     )
    def setUp(self):
        self.user = UserFactory.create()
        self.request = RequestFactory().get('/')
        self.request.user = self.user
        self.request.session = {}
        self.course = CourseFactory.create()

        self.problem_xml = OptionResponseXMLFactory().build_xml(
            question_text='The correct answer is Correct',
            num_inputs=2,
            weight=2,
            options=['Correct', 'Incorrect'],
            correct_option='Correct')
Exemplo n.º 17
0
    def setUp(self):
        super(MasqueradeTestCase, self).setUp()

        # By default, tests run with DISABLE_START_DATES=True. To test that masquerading as a student is
        # working properly, we must use start dates and set a start date in the past (otherwise the access
        # checks exist prematurely).
        self.course = CourseFactory.create(
            number='masquerade-test', metadata={'start': datetime.now(UTC())})
        # Creates info page and puts random data in it for specific student info page test
        self.info_page = ItemFactory.create(
            category="course_info",
            parent_location=self.course.location,
            data="OOGIE BLOOGIE",
            display_name="updates")
        self.chapter = ItemFactory.create(
            parent_location=self.course.location,
            category="chapter",
            display_name="Test Section",
        )
        self.sequential_display_name = "Test Masquerade Subsection"
        self.sequential = ItemFactory.create(
            parent_location=self.chapter.location,
            category="sequential",
            display_name=self.sequential_display_name,
        )
        self.vertical = ItemFactory.create(
            parent_location=self.sequential.location,
            category="vertical",
            display_name="Test Unit",
        )
        problem_xml = OptionResponseXMLFactory().build_xml(
            question_text='The correct answer is Correct',
            num_inputs=2,
            weight=2,
            options=['Correct', 'Incorrect'],
            correct_option='Correct')
        self.problem_display_name = "TestMasqueradeProblem"
        self.problem = ItemFactory.create(
            parent_location=self.vertical.location,
            category='problem',
            data=problem_xml,
            display_name=self.problem_display_name)
        self.test_user = self.create_user()
        self.login(self.test_user.email, 'test')
        self.enroll(self.course, True)
Exemplo n.º 18
0
 def setUp(self):
     super(TestInlineAnalytics, self).setUp()
     self.user = UserFactory.create()
     self.request = RequestFactory().get('/')
     self.request.user = self.user
     self.request.session = {}
     self.course = CourseFactory.create(
         org='A',
         number='B',
         display_name='C',
     )
     self.staff = StaffFactory(course_key=self.course.id)
     self.instructor = InstructorFactory(course_key=self.course.id)
     self.problem_xml = OptionResponseXMLFactory().build_xml(
         question_text='The correct answer is Correct',
         num_inputs=2,
         weight=2,
         options=['Correct', 'Incorrect'],
         correct_option='Correct',
     )
     self.descriptor = ItemFactory.create(
         category='problem',
         data=self.problem_xml,
         display_name='Option Response Problem',
         rerandomize='never',
     )
     self.location = self.descriptor.location
     self.field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
         self.course.id,
         self.user,
         self.descriptor,
     )
     self.field_data_cache_staff = FieldDataCache.cache_for_descriptor_descendents(
         self.course.id,
         self.staff,
         self.descriptor,
     )
     self.field_data_cache_instructor = FieldDataCache.cache_for_descriptor_descendents(
         self.course.id,
         self.instructor,
         self.descriptor,
     )
Exemplo n.º 19
0
import textwrap
from common import section_location
from capa.tests.response_xml_factory import OptionResponseXMLFactory, \
    ChoiceResponseXMLFactory, MultipleChoiceResponseXMLFactory, \
    StringResponseXMLFactory, NumericalResponseXMLFactory, \
    FormulaResponseXMLFactory, CustomResponseXMLFactory, \
    CodeResponseXMLFactory, ChoiceTextResponseXMLFactory

# Factories from capa.tests.response_xml_factory that we will use
# to generate the problem XML, with the keyword args used to configure
# the output.
# 'correct', 'incorrect', and 'unanswered' keys are lists of CSS selectors
# the presence of any in the list is sufficient
PROBLEM_DICT = {
    'drop down': {
        'factory': OptionResponseXMLFactory(),
        'kwargs': {
            'question_text': 'The correct answer is Option 2',
            'options': ['Option 1', 'Option 2', 'Option 3', 'Option 4'],
            'correct_option': 'Option 2'
        },
        'correct': ['span.correct'],
        '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']
Exemplo n.º 20
0
    def setUp(self):
        self.output = StringIO.StringIO()
        self.gzipfile = StringIO.StringIO()
        self.course = CourseFactory.create(
            display_name=self.COURSE_NAME,
        )
        self.course.raw_grader = [{
            'drop_count': 0,
            'min_count': 1,
            'short_label': 'Final',
            'type': 'Final Exam',
            'weight': 1.0
        }]
        self.course.grade_cutoffs = {'Pass': 0.1}
        self.students = [
            UserFactory.create(username='******'),
            UserFactory.create(username='******'),
            UserFactory.create(username='******'),
            UserFactory.create(username='******'),
            UserFactory.create(username='******'),
            StaffFactory.create(username='******', course_key=self.course.id),
            InstructorFactory.create(username='******', course_key=self.course.id),
        ]
        UserStandingFactory.create(
            user=self.students[4],
            account_status=UserStanding.ACCOUNT_DISABLED,
            changed_by=self.students[6]
        )

        for user in self.students:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)

        self.pgreport = ProgressReport(self.course.id)
        self.pgreport2 = ProgressReport(self.course.id, lambda state: state)

        self.chapter = ItemFactory.create(
            parent_location=self.course.location,
            category="chapter",
            display_name="Week 1"
        )
        self.chapter.save()
        self.section = ItemFactory.create(
            parent_location=self.chapter.location,
            category="sequential",
            display_name="Lesson 1"
        )
        self.section.save()
        self.vertical = ItemFactory.create(
            parent_location=self.section.location,
            category="vertical",
            display_name="Unit1"
        )
        self.vertical.save()
        self.html = ItemFactory.create(
            parent_location=self.vertical.location,
            category="html",
            data={'data': "<html>foobar</html>"}
        )
        self.html.save()
        """
        course.children = [week1.location.url(), week2.location.url(),
                           week3.location.url()]
        """
        from capa.tests.response_xml_factory import OptionResponseXMLFactory
        self.problem_xml = OptionResponseXMLFactory().build_xml(
            question_text='The correct answer is Correct',
            num_inputs=2,
            weight=2,
            options=['Correct', 'Incorrect'],
            correct_option='Correct'
        )

        self.problems = []
        for num in xrange(1, 3):
            self.problems.append(ItemFactory.create(
                parent_location=self.vertical.location,
                category='problem',
                display_name='problem_' + str(num),
                metadata={'graded': True, 'format': 'Final Exam'},
                data=self.problem_xml
            ))
            self.problems[num - 1].save()

        for problem in self.problems:
            problem.correct_map = {
                unicode(problem.location) + "_2_1": {
                    "hint": "",
                    "hintmode": "",
                    "correctness": "correct",
                    "npoints": "",
                    "msg": "",
                    "queuestate": ""
                },
                unicode(problem.location) + "_2_2": {
                    "hint": "",
                    "hintmode": "",
                    "correctness": "incorrect",
                    "npoints": "",
                    "msg": "",
                    "queuestate": ""
                }
            }

            problem.student_answers = {
                unicode(problem.location) + "_2_1": "Correct",
                unicode(problem.location) + "_2_2": "Incorrect"
            }

            problem.input_state = {
                unicode(problem.location) + "_2_1": {},
                unicode(problem.location) + "_2_2": {}
            }

        self.course.save()

        patcher = patch('pgreport.views.logging')
        self.log_mock = patcher.start()
        self.addCleanup(patcher.stop)

        """