示例#1
0
    def test_when_other_exception_raised_create_validation_object(
            self, validate_against_schema):
        exception_obj = Exception("error msg")
        validate_against_schema.side_effect = mock.Mock(
            side_effect=exception_obj)

        ip = InformationPackage.objects.create()
        task = ProcessTask.objects.create(information_package=ip)

        validator = XMLISOSchematronValidator(
            context="dummy_schema.xsl",
            options={'rootdir': "dummy_rootdir"},
            ip=ip.id,
            task=task)

        with self.assertRaises(Exception):
            validator.validate("some_xml_file_path")

        validations = Validation.objects.filter(
            information_package_id=ip.id,
            message='error msg',
            passed=False,
            task_id=task.id,
            validator='XMLISOSchematronValidator')
        self.assertEqual(validations.count(), 1)
    def test_validate_schematron_successful_validation_should_return(self):
        schematron_file_name = "schematron.xsl"
        schematron_file_path = self.create_schematron_file(schematron_file_name)
        xml_file_path = self.create_xml("xml_file.xml")

        validator = XMLISOSchematronValidator(
            context=schematron_file_path,
            options={'rootdir': self.datadir},
            ip="dummy_ip_id",
            task="dummy_ip_id",
        )

        validator._validate_isoschematron(xml_file_path)
    def test_validate_schematron_bad_file_should_raise_exception(self):
        schematron_file_name = "schematron.xsl"
        schematron_file_path = self.create_schematron_file(schematron_file_name)
        xml_file_path = self.create_bad_xml("bad_xml_file.xml")

        validator = XMLISOSchematronValidator(
            context=schematron_file_path,
            options={'rootdir': self.datadir},
            ip="dummy_ip_id",
            task="dummy_ip_id",
        )

        expected_error_message = ".*The element Person should have the child elements Name and Gender.*"

        with self.assertRaisesRegexp(DocumentInvalid, expected_error_message):
            validator._validate_isoschematron(xml_file_path)
    def test_validate_schematron_non_existing_file_path_should_raise_exception(self):
        schematron_file_name = "schematron.xsl"
        schematron_file_path = self.create_schematron_file(schematron_file_name)
        xml_file_path = "dummy_file_path"

        validator = XMLISOSchematronValidator(
            context=schematron_file_path,
            options={'rootdir': "dummy_rootdir"},
            ip="dummy_ip_id",
            task="dummy_ip_id",
        )

        expected_err_msg = f"Error reading file '{xml_file_path}': failed to load external entity \"{xml_file_path}\""

        with self.assertRaisesRegexp(OSError, expected_err_msg):
            validator._validate_isoschematron(xml_file_path)
    def test_validate_schematron_bad_schematron_file_should_raise_exception(self):
        schematron_file_name = "non_existing_schematron_file"
        schematron_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), f'{schematron_file_name}')
        xml_file_path = "dummy_file_path"

        validator = XMLISOSchematronValidator(
            context=schematron_file_path,
            options={'rootdir': "dummy_rootdir"},
            ip="dummy_ip_id",
            task="dummy_ip_id",
        )

        expected_error_message = f"Error reading file .*{schematron_file_name}'.* failed to load external entity"

        with self.assertRaisesRegexp(OSError, expected_error_message):
            validator._validate_isoschematron(xml_file_path)
示例#6
0
    def test_when_successful_create_validation_object(self,
                                                      validate_against_schema):
        ip = InformationPackage.objects.create()
        task = ProcessTask.objects.create(information_package=ip)

        validator = XMLISOSchematronValidator(
            context="dummy_schema.xsl",
            options={'rootdir': "dummy_rootdir"},
            ip=ip.id,
            task=task)

        validator.validate("some_xml_file_path")

        validations = Validation.objects.filter(
            information_package_id=ip.id,
            passed=True,
            task_id=task.id,
            validator='XMLISOSchematronValidator')
        self.assertEqual(validations.count(), 1)
    def test_when_documentInvalid_raised_create_validation_objects(self, validate_schematron):
        exception_obj = DocumentInvalid("error msg")
        exception_obj.error_log = [
            create_mocked_error_log(123, "error msg 1"),
            create_mocked_error_log(456, "error msg 2"),
        ]
        validate_schematron.side_effect = mock.Mock(side_effect=exception_obj)

        ip = InformationPackage.objects.create()
        task = ProcessTask.objects.create(information_package=ip)

        validator = XMLISOSchematronValidator(
            context="dummy_schema.xsl",
            options={'rootdir': "dummy_rootdir"},
            ip=ip.id,
            task=task
        )
        with self.assertRaises(DocumentInvalid):
            validator.validate("some_xml_file_path")

        validations = Validation.objects.filter(passed=False, validator="XMLISOSchematronValidator")
        self.assertEqual(validations.count(), 2)