Skip to content

Commit

Permalink
Merge pull request #97 from dandi/fix/pattern
Browse files Browse the repository at this point in the history
fix: raise validation error on mismatched name
  • Loading branch information
satra authored Jan 10, 2022
2 parents 435fc13 + 8d1a5e4 commit 7e53e9f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
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

0 comments on commit 7e53e9f

Please sign in to comment.