def test_manifest_noreps(self): man_no_reps = IP.PackageManifest("no_reps", has_reps=False) val_errors = IP.validate_manifest(man_no_reps) self.assertTrue(len(val_errors) == 1) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR9", severity=Severity.Warn)) val_errors = IP.validate_manifest(man_no_reps, is_root=False) self.assertTrue(len(val_errors) == 1) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR11", severity=Severity.Warn))
def test_manifest_noschema(self): # test as root man_no_schema = IP.PackageManifest("no_schema", has_schema=False) val_errors = IP.validate_manifest(man_no_schema) self.assertTrue(len(val_errors) == 1) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR15", severity=Severity.Warn)) val_errors = IP.validate_manifest(man_no_schema, is_root=False) self.assertTrue(len(val_errors) == 2) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR15", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR11", severity=Severity.Warn))
def test_manifest_nomets(self): """Ensure proper behaviour when no METS file is present.""" # test as root man_no_mets = IP.PackageManifest("no_mets", has_mets=False) val_errors = IP.validate_manifest(man_no_mets) self.assertTrue(len(val_errors) == 1) self.assertTrue(contains_rule_id(val_errors, "CSIPSTR4")) val_errors = IP.validate_manifest(man_no_mets, is_root=False) self.assertTrue(len(val_errors) == 2) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR12", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR11", severity=Severity.Warn))
def test_manifest_nomd(self): # test as root man_no_md = IP.PackageManifest("no_md", has_md=False) val_errors = IP.validate_manifest(man_no_md) self.assertTrue(len(val_errors) == 1) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR5", severity=Severity.Warn)) val_errors = IP.validate_manifest(man_no_md, is_root=False) self.assertTrue(len(val_errors) == 2) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR13", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR11", severity=Severity.Warn))
def test_minimal(self): """Test minimal IP with schemas, the basic no errors but with warnings package.""" ip_path = os.path.join(os.path.dirname(__file__), 'resources', 'ips', 'minimal', 'minimal_IP_with_schemas.zip') details = IP.validate_package_structure(ip_path) self.assertTrue( details.package_status == IP.PackageStatus.WellFormed, 'Expecting status WellFormed, not {}'.format( details.package_status)) val_errors = details.errors self.assertTrue( len(val_errors) == 3, 'Expecting 3 errors but found {}'.format(len(val_errors))) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR12", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR13", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR15", severity=Severity.Warn))
def test_nomets(self): """Test package with no METS.xml file""" ip_path = os.path.join(os.path.dirname(__file__), 'resources', 'ips', 'struct', 'no_mets.tar.gz') details = IP.validate_package_structure(ip_path) self.assertTrue( details.package_status == IP.PackageStatus.NotWellFormed, 'Expecting status NotWellFormed, not {}'.format( details.package_status)) val_errors = details.errors self.assertTrue( len(val_errors) == 4, 'Expecting 4 errors but found {}'.format(len(val_errors))) self.assertTrue(contains_rule_id(val_errors, "CSIPSTR4")) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR12", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR13", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR15", severity=Severity.Warn))
def test_nodata(self): # test as root ip_path = os.path.join(os.path.dirname(__file__), 'resources', 'ips', 'struct', 'no_data.tar.gz') details = IP.validate_package_structure(ip_path) self.assertTrue( details.package_status == IP.PackageStatus.WellFormed, 'Expecting status WellFormed, not {}'.format( details.package_status)) val_errors = details.errors self.assertTrue( len(val_errors) == 4, 'Expecting 4 errors but found {}'.format(len(val_errors))) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR11", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR12", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR13", severity=Severity.Warn)) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR15", severity=Severity.Warn))
def test_check_package_root_multi_var(self): """Dedicated test for package root detection errors.""" ip_path = os.path.join(os.path.dirname(__file__), 'resources', 'ips', 'unpacked', 'multi_var') details = IP.check_package_root(ip_path) self.assertTrue( details.package_status == IP.PackageStatus.NotWellFormed, 'Expecting status NotWellFormed, not {}'.format( details.package_status)) val_errors = details.errors self.assertTrue( len(val_errors) == 1, 'Expecting 1 errors but found {}'.format(len(val_errors))) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR1", severity=Severity.Error))
def test_noreps(self): ip_path = os.path.join(os.path.dirname(__file__), 'resources', 'ips', 'struct', 'no_reps.tar.gz') details = IP.validate_package_structure(ip_path) self.assertTrue( details.package_status == IP.PackageStatus.WellFormed, 'Expecting status WellFormed, not {}'.format( details.package_status)) val_errors = details.errors for err in val_errors: print(err.rule_id) self.assertTrue( len(val_errors) == 1, 'Expecting 1 errors but found {}'.format(len(val_errors))) self.assertTrue( contains_rule_id(val_errors, "CSIPSTR9", severity=Severity.Warn))