Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: raise validation error on mismatched name #97

Merged
merged 4 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions dandischema/consts.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
DANDI_SCHEMA_VERSION = "0.6.0"
ALLOWED_INPUT_SCHEMAS = [
"0.4.4",
"0.5.1",
"0.5.2",
]
DANDI_SCHEMA_VERSION = "0.6.1"
ALLOWED_INPUT_SCHEMAS = ["0.4.4", "0.5.1", "0.5.2", "0.6.0"]

# ATM we allow only for a single target version which is current
# migrate has a guard now for this since it cannot migrate to anything but current
# version
ALLOWED_TARGET_SCHEMAS = [DANDI_SCHEMA_VERSION]
# This allows multiple schemas for validation, whereas target schemas focus on
# migration.
ALLOWED_VALIDATION_SCHEMAS = ALLOWED_TARGET_SCHEMAS + ["0.4.4", "0.5.1", "0.5.2"]
ALLOWED_VALIDATION_SCHEMAS = ALLOWED_TARGET_SCHEMAS + [
"0.4.4",
"0.5.1",
"0.5.2",
"0.6.0",
]

if DANDI_SCHEMA_VERSION not in ALLOWED_INPUT_SCHEMAS:
ALLOWED_INPUT_SCHEMAS.append(DANDI_SCHEMA_VERSION)
4 changes: 2 additions & 2 deletions dandischema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
HttpUrl = AnyHttpUrl # noqa: F811


NAME_PATTERN = r"^([\w\s\-]+)?,\s+([\w\s\-\.]+)?$"
NAME_PATTERN = r"^([\w\s\-]+),\s+([\w\s\-\.]+)$"
UUID_PATTERN = (
"[a-f0-9]{8}[-]*[a-f0-9]{4}[-]*" "[a-f0-9]{4}[-]*[a-f0-9]{4}[-]*[a-f0-9]{12}$"
)
Expand Down Expand Up @@ -293,7 +293,7 @@ class BaseType(DandiBaseModel):
None,
description="The identifier can be any url or a compact URI, preferably"
" supported by identifiers.org.",
regex=r"^[a-zA-Z0-9]+:[a-zA-Z0-9-/\._]+$",
regex=r"^[a-zA-Z0-9-]+:[a-zA-Z0-9-/\._]+$",
nskey="schema",
)
name: Optional[str] = Field(
Expand Down
1 change: 1 addition & 0 deletions dandischema/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def test_pydantic_validation(schema_dir):
validate({})


@skipif_no_network
def test_json_schemakey_validation():
with pytest.raises(JsonschemaValidationError) as exc:
validate(
Expand Down
3 changes: 3 additions & 0 deletions dandischema/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ class TempKlass(DandiBaseModel):
"includeInCitation": True,
},
]
with pytest.raises(pydantic.ValidationError):
TempKlass(contributor=contributor)
contributor[0]["name"] = ", "
with pytest.raises(pydantic.ValidationError):
TempKlass(contributor=contributor)
contributor[0]["name"] = "last, first"
Expand Down