Пример #1
0
    def update_xml(self, data, suffix=''):
        """
        Update the XBlock's XML.

        Args:
            data (dict): Data from the request; should have a value for the key 'xml'
                containing the XML for this XBlock.

        Kwargs:
            suffix (str): Not used

        Returns:
            dict with keys 'success' (bool) and 'msg' (str)
        """
        if 'xml' in data:
            try:
                update_from_xml_str(self, data['xml'], validator=validator(self))

            except ValidationError as ex:
                return {'success': False, 'msg': _('Validation error: {error}').format(error=ex)}

            except UpdateFromXmlError as ex:
                return {'success': False, 'msg': _('An error occurred while saving: {error}').format(error=ex)}

            else:
                return {'success': True, 'msg': _('Successfully updated OpenAssessment XBlock')}

        else:
            return {'success': False, 'msg': _('Must specify "xml" in request JSON dict.')}
Пример #2
0
 def test_invalid(self, data):
     # Plug in a rubric validator that always reports that the rubric dict is invalid.
     # We need to back this up with an integration test that checks whether the XBlock
     # provides an appropriate rubric validator.
     with self.assertRaises(ValidationError):
         update_from_xml_str(self.oa_block,
                             "".join(data['xml']),
                             validator=lambda *args: (False, ''))
Пример #3
0
 def test_invalid(self, data):
     # Plug in a rubric validator that always reports that the rubric dict is invalid.
     # We need to back this up with an integration test that checks whether the XBlock
     # provides an appropriate rubric validator.
     with self.assertRaises(ValidationError):
         update_from_xml_str(
             self.oa_block, "".join(data['xml']),
             validator=lambda *args: (False, '')
         )
Пример #4
0
    def update_xml(self, data, suffix=''):
        """
        Update the XBlock's XML.

        Args:
            data (dict): Data from the request; should have a value for the key 'xml'
                containing the XML for this XBlock.

        Kwargs:
            suffix (str): Not used

        Returns:
            dict with keys 'success' (bool) and 'msg' (str)
        """
        if 'xml' in data:
            try:
                update_from_xml_str(self,
                                    data['xml'],
                                    validator=validator(self))

            except ValidationError as ex:
                return {
                    'success': False,
                    'msg':
                    _('Validation error: {error}').format(error=ex.message)
                }

            except UpdateFromXmlError as ex:
                return {
                    'success':
                    False,
                    'msg':
                    _('An error occurred while saving: {error}').format(
                        error=ex.message)
                }

            else:
                return {
                    'success': True,
                    'msg': _('Successfully updated OpenAssessment XBlock')
                }

        else:
            return {
                'success': False,
                'msg': _('Must specify "xml" in request JSON dict.')
            }
Пример #5
0
    def test_update_from_xml(self, data):

        # Update the block based on the fixture XML definition
        returned_block = update_from_xml_str(self.oa_block, "".join(data['xml']))

        # The block we passed in should be updated and returned
        self.assertEqual(self.oa_block, returned_block)

        # Check that the contents of the modified XBlock are correct
        self.assertEqual(self.oa_block.title, data['title'])
        self.assertEqual(self.oa_block.prompt, data['prompt'])
        self.assertEqual(self.oa_block.start, _parse_date(data['start']))
        self.assertEqual(self.oa_block.due, _parse_date(data['due']))
        self.assertEqual(self.oa_block.submission_due, data['submission_due'])
        self.assertEqual(self.oa_block.rubric_criteria, data['criteria'])
        self.assertEqual(self.oa_block.rubric_assessments, data['assessments'])
Пример #6
0
    def test_update_from_xml(self, data):

        # Update the block based on the fixture XML definition
        returned_block = update_from_xml_str(self.oa_block, "".join(data['xml']))

        # The block we passed in should be updated and returned
        self.assertEqual(self.oa_block, returned_block)

        # Check that the contents of the modified XBlock are correct
        self.assertEqual(self.oa_block.title, data['title'])
        self.assertEqual(self.oa_block.prompt, data['prompt'])
        self.assertEqual(self.oa_block.start, _parse_date(data['start']))
        self.assertEqual(self.oa_block.due, _parse_date(data['due']))
        self.assertEqual(self.oa_block.submission_start, data['submission_start'])
        self.assertEqual(self.oa_block.submission_due, data['submission_due'])
        self.assertEqual(self.oa_block.rubric_criteria, data['criteria'])
        self.assertEqual(self.oa_block.rubric_assessments, data['assessments'])
Пример #7
0
 def test_update_from_xml_error(self, data):
     with self.assertRaises(UpdateFromXmlError):
         update_from_xml_str(self.oa_block, "".join(data['xml']))