Skip to content

Commit

Permalink
Test for repeated logical paths (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeon committed Apr 22, 2021
1 parent 0c7d93f commit 6b1c9e2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 7 additions & 1 deletion ocfl/data/validation-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,13 @@
"en": "OCFL Object %s inventory %s version block has message key with value that isn't a string"
}
},
"E095": {
"E095a": {
"params": ["where", "version", "path"],
"description": {
"en": "OCFL Object %s inventory version %s state has logical path %s used more than once."
}
},
"E095b": {
"params": ["where", "version", "path"],
"description": {
"en": "OCFL Object %s inventory version %s state has logical path %s used as both a directory and a file path."
Expand Down
9 changes: 6 additions & 3 deletions ocfl/inventory_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ def validate_state_block(self, state, version, unnormalized_digests):
self.error('E050e', version=version, digest=digest)
else:
for path in state[digest]:
self.check_logical_path(path, version, logical_paths, logical_directories)
if path in logical_paths:
self.error("E095a", version=version, path=path)
else:
self.check_logical_path(path, version, logical_paths, logical_directories)
if digest not in unnormalized_digests:
# Exact string value must match, not just normalized
self.error("E050f", version=version, digest=digest)
Expand All @@ -343,7 +346,7 @@ def validate_state_block(self, state, version, unnormalized_digests):
# Check for conflicting logical paths
for path in logical_directories:
if path in logical_paths:
self.error("E095", version=version, path=path)
self.error("E095b", version=version, path=path)
return digests

def check_content_paths_map_to_versions(self, manifest_files, all_versions):
Expand Down Expand Up @@ -380,7 +383,7 @@ def digest_regex(self):
return r'''^.*$'''

def check_logical_path(self, path, version, logical_paths, logical_directories):
"""Check logical path and accumulate paths/directories for E095 check.
"""Check logical path and accumulate paths/directories for E095b check.
logical_paths and logical_directories are expected to be sets.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def test01_bad(self):
# 'E092_algorithm_change_incorrect_digest': ['E092'], FIXME https://github.com/OCFL/fixtures/pull/67
'E093_fixity_digest_mismatch': ['E093a'],
'E094_message_not_a_string': ['E094'],
'E095_conflicting_logical_paths': ['E095'],
# 'E095_non_unique_logical_paths': ['E095'], FIXME https://github.com/zimeon/ocfl-py/issues/39
'E095_conflicting_logical_paths': ['E095b'],
'E095_non_unique_logical_paths': ['E095a'],
'E096_manifest_repeated_digest': ['E096'],
'E096_manifest_duplicate_digests': ['E096'],
'E097_fixity_repeated_digest': ['E097'],
Expand Down

0 comments on commit 6b1c9e2

Please sign in to comment.