Skip to content

Commit

Permalink
Merge pull request #1703 from fractal-analytics-platform/1687-coverag…
Browse files Browse the repository at this point in the history
…e-api-schemas-100-with-unit-tests

Coverage schemas 100%
  • Loading branch information
tcompa committed Aug 21, 2024
2 parents b52dd65 + 38d9158 commit cbed743
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tests/v2/01_schemas/test_schemas_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ async def test_schemas_workflow_v2():
with pytest.raises(ValidationError):
WorkflowUpdateV2(name=None)

workflow_update = WorkflowUpdateV2(name="new name")

for key, value in workflow_update.dict(exclude_unset=True).items():
setattr(workflow, key, value)
with pytest.raises(ValidationError):
WorkflowUpdateV2(name="foo", reordered_workflowtask_ids=[1, 2, -3])

assert workflow.name == "new name"
WorkflowUpdateV2(name="new name", reordered_workflowtask_ids=[1, 2, 3])


async def test_schemas_workflow_task_v2():
Expand Down
5 changes: 5 additions & 0 deletions tests/v2/01_schemas/test_task_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def test_TaskCollectPipV2():
assert collection.package == "package"
assert collection.package_version == "1.2.3"

with pytest.raises(
ValidationError, match="Local-package path must be absolute"
):
TaskCollectPipV2(package="not/absolute.whl")


async def test_TaskCollectCustomV2(testdata_path):

Expand Down
52 changes: 52 additions & 0 deletions tests/v2/01_schemas/test_unit_schemas_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from fractal_server.app.schemas.v2 import ProjectCreateV2
from fractal_server.app.schemas.v2 import TaskCollectPipV2
from fractal_server.app.schemas.v2 import TaskCreateV2
from fractal_server.app.schemas.v2 import TaskUpdateV2
from fractal_server.app.schemas.v2 import WorkflowCreateV2
from fractal_server.app.schemas.v2 import WorkflowTaskCreateV2
from fractal_server.app.schemas.v2 import WorkflowTaskDumpV2
from fractal_server.images import Filters


def test_extra_on_create_models():
Expand Down Expand Up @@ -77,6 +80,11 @@ def test_dictionary_keys_validation():
with pytest.raises(ValidationError):
TaskCreateV2(**args, input_types={"a": True, " a ": False})

with pytest.raises(
ValidationError, match="Task must have at least one valid command"
):
TaskCreateV2(name="name", source="source")


def test_task_collect_pip():

Expand All @@ -93,3 +101,47 @@ def test_task_collect_pip():
TaskCollectPipV2(package="/tmp/x.whl", package_version="1")
msg = "Cannot provide package version when package is a wheel file"
assert msg in str(e.value)


def test_task_update():
t = TaskUpdateV2()
assert t.input_types is None
assert t.output_types is None
with pytest.raises(ValidationError):
TaskUpdateV2(input_types=None)
with pytest.raises(ValidationError):
TaskUpdateV2(output_types=None)


def test_job_create():
JobCreateV2()
JobCreateV2(last_task_index=None)
JobCreateV2(last_task_index=1)
with pytest.raises(ValidationError, match="cannot be negative"):
JobCreateV2(last_task_index=-1)


def test_workflow_task_dump():
WorkflowTaskDumpV2(
id=1,
workflow_id=1,
is_legacy_task=False,
input_filters=Filters(),
task_id=1,
)
with pytest.raises(ValidationError, match="both"):
WorkflowTaskDumpV2(
id=1,
workflow_id=1,
is_legacy_task=False,
input_filters=Filters(),
task_id=1,
task_legacy_id=1,
)
with pytest.raises(ValidationError, match="none"):
WorkflowTaskDumpV2(
id=1,
workflow_id=1,
is_legacy_task=False,
input_filters=Filters(),
)

0 comments on commit cbed743

Please sign in to comment.