Ejemplo n.º 1
0
    def test_parse_from_xml(self, data):

        # Update the block based on the fixture XML definition
        config = parse_from_xml_str("".join(data["xml"]))

        # Check that the contents of the modified XBlock are correct
        expected_fields = [
            "title",
            "prompt",
            "start",
            "due",
            "submission_start",
            "submission_due",
            "criteria",
            "assessments",
            "allow_file_upload",
            "leaderboard_show",
        ]
        for field_name in expected_fields:
            if field_name in data:
                actual = config[field_name]
                expected = data[field_name]

                if field_name in ["start", "due"]:
                    expected = _parse_date(expected)

                self.assertEqual(
                    actual,
                    expected,
                    msg=u"Wrong value for '{key}': was {actual} but expected {expected}".format(
                        key=field_name, actual=repr(actual), expected=repr(expected)
                    ),
                )
Ejemplo n.º 2
0
    def test_serialize_missing_names_and_labels(self):
        # Configure rubric criteria and options with no names or labels
        # This *should* never happen, but if it does, recover gracefully
        # by assigning unique names and empty labels
        self._configure_xblock({})

        for criterion in self.oa_block.rubric_criteria:
            del criterion["name"]
            del criterion["label"]
            for option in criterion["options"]:
                del option["name"]
                del option["label"]

        xml = serialize_content(self.oa_block)
        content_dict = parse_from_xml_str(xml)

        # Verify that all names are unique
        # and that all labels are empty
        criterion_names = set()
        option_names = set()
        criteria_count = 0
        options_count = 0
        for criterion in content_dict["rubric_criteria"]:
            criterion_names.add(criterion["name"])
            self.assertEqual(criterion["label"], u"")
            criteria_count += 1

            for option in criterion["options"]:
                option_names.add(option["name"])
                self.assertEqual(option["label"], u"")
                options_count += 1

        self.assertEqual(len(criterion_names), criteria_count)
        self.assertEqual(len(option_names), options_count)
Ejemplo n.º 3
0
    def test_parse_from_xml(self, data):

        # Update the block based on the fixture XML definition
        config = parse_from_xml_str("".join(data['xml']))

        # Check that the contents of the modified XBlock are correct
        expected_fields = [
            'title', 'prompts', 'start', 'due', 'submission_start',
            'submission_due', 'criteria', 'assessments', 'file_upload_type',
            'white_listed_file_types', 'allow_multiple_files', 'allow_latex',
            'leaderboard_show'
        ]
        for field_name in expected_fields:
            if field_name in data:
                actual = config[field_name]
                expected = data[field_name]

                if field_name in ['start', 'due']:
                    expected = _parse_date(expected)

                self.assertEqual(
                    actual,
                    expected,
                    msg=
                    "Wrong value for '{key}': was {actual} but expected {expected}"
                    .format(key=field_name,
                            actual=repr(actual),
                            expected=repr(expected)))
Ejemplo n.º 4
0
    def test_serialize_missing_names_and_labels(self):
        # Configure rubric criteria and options with no names or labels
        # This *should* never happen, but if it does, recover gracefully
        # by assigning unique names and empty labels
        self._configure_xblock({})

        for criterion in self.oa_block.rubric_criteria:
            del criterion['name']
            del criterion['label']
            for option in criterion['options']:
                del option['name']
                del option['label']

        xml = serialize_content(self.oa_block)
        content_dict = parse_from_xml_str(xml)

        # Verify that all names are unique
        # and that all labels are empty
        criterion_names = set()
        option_names = set()
        criteria_count = 0
        options_count = 0
        for criterion in content_dict['rubric_criteria']:
            criterion_names.add(criterion['name'])
            self.assertEqual(criterion['label'], '')
            criteria_count += 1

            for option in criterion['options']:
                option_names.add(option['name'])
                self.assertEqual(option['label'], '')
                options_count += 1

        self.assertEqual(len(criterion_names), criteria_count)
        self.assertEqual(len(option_names), options_count)
Ejemplo n.º 5
0
    def test_parse_from_xml(self, data):

        # Update the block based on the fixture XML definition
        config = parse_from_xml_str("".join(data['xml']))

        # Check that the contents of the modified XBlock are correct
        expected_fields = [
            'title',
            'prompts',
            'start',
            'due',
            'submission_start',
            'submission_due',
            'criteria',
            'assessments',
            'allow_file_upload',
            'allow_latex',
            'leaderboard_show'
        ]
        for field_name in expected_fields:
            if field_name in data:
                actual = config[field_name]
                expected = data[field_name]

                if field_name in ['start', 'due']:
                    expected = _parse_date(expected)

                self.assertEqual(
                    actual, expected,
                    msg=u"Wrong value for '{key}': was {actual} but expected {expected}".format(
                        key=field_name,
                        actual=repr(actual),
                        expected=repr(expected)
                    )
                )
Ejemplo n.º 6
0
 def test_parse_from_xml_error(self, data):
     with self.assertRaises(UpdateFromXmlError):
         parse_from_xml_str("".join(data["xml"]))
Ejemplo n.º 7
0
 def test_parse_from_xml_error(self, data):
     with self.assertRaises(UpdateFromXmlError):
         parse_from_xml_str("".join(data['xml']))