Skip to content

Commit

Permalink
Add some validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Jan 15, 2025
1 parent f206847 commit 2e74813
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/v2/01_schemas/test_schemas_dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from devtools import debug
from pydantic import ValidationError

from fractal_server.app.models.v2 import DatasetV2
Expand All @@ -10,6 +11,51 @@
from fractal_server.urls import normalize_url


VALID_ATTRIBUTE_FILTERS = (
{},
{"key1": []},
{"key1": ["A"]},
{"key1": ["A", "B"]},
{"key1": [1, 2]},
{"key1": [True, False]},
{"key1": [1.5, -1.2]},
{"key1": None},
{"key1": [1, 2], "key2": ["A", "B"]},
)

INVALID_ATTRIBUTE_FILTERS = (
{True: ["value"]}, # non-string key
{1: ["value"]}, # non-string key
{"key1": [1], " key1": [1]}, # non-unique normalized keys
{"key1": [None]}, # None value
# {"key1": [1, True]}, # non-homogeneous types - FIXME unsupported
{"key1": [1, 1.0]}, # non-homogeneous types - FIXME unsupported
{"key1": [1, "a"]}, # non-homogeneous types
{"key1": [[1, 2], [1, 2]]}, # non-scalar type
)


@pytest.mark.parametrize("attribute_filters", VALID_ATTRIBUTE_FILTERS)
def test_valid_attribute_filters(attribute_filters: dict):
DatasetCreateV2(
name="x",
zarr_dir="/x",
attribute_filters=attribute_filters,
)


@pytest.mark.parametrize("attribute_filters", INVALID_ATTRIBUTE_FILTERS)
def test_invalid_attribute_filters(attribute_filters: dict):
debug(attribute_filters)
with pytest.raises(ValueError) as e:
DatasetCreateV2(
name="x",
zarr_dir="/x",
attribute_filters=attribute_filters,
)
debug(e.value)


async def test_schemas_dataset_v2():

project = ProjectV2(id=1, name="project")
Expand Down

0 comments on commit 2e74813

Please sign in to comment.