Skip to content

Commit

Permalink
Ability to validate list of records
Browse files Browse the repository at this point in the history
  • Loading branch information
mesemus committed Jul 28, 2023
1 parent 3ce986f commit 9220bd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions oarepo_runtime/cli/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ def validate(service_name, record_file, verbose):
else:
data = yaml.safe_load(StringIO(file_content))

loaded = schema().load(data)
click.secho("Marshmallow validation has been successful", fg="green")
if not isinstance(data, list):
data = [data]
for idx, d in enumerate(data):
loaded = schema().load(d)
click.secho(f"Marshmallow validation of record idx {idx+1} has been successful", fg="green")

rec: Record = config.record_cls(loaded)
rec: Record = config.record_cls(loaded)

# Run pre create extensions to check vocabularies
try:
with db.session.begin_nested():
for e in rec._extensions:
e.pre_commit(rec)
raise CheckOk()
except CheckOk:
click.secho("Pre-commit hook has been successful", fg="green")
# Run pre create extensions to check vocabularies
try:
with db.session.begin_nested():
for e in rec._extensions:
e.pre_commit(rec)
raise CheckOk()
except CheckOk:
click.secho(f"Pre-commit hook of record idx {idx+1} has been successful", fg="green")

if verbose:
yaml.safe_dump(loaded, sys.stdout, allow_unicode=True)
if verbose:
yaml.safe_dump(loaded, sys.stdout, allow_unicode=True)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-runtime
version = 1.3.23
version = 1.3.24
description = A set of runtime extensions of Invenio repository
authors = Alzbeta Pokorna
readme = README.md
Expand Down

0 comments on commit 9220bd6

Please sign in to comment.