Skip to content
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
44 changes: 44 additions & 0 deletions tests/test_canvas_tables_ask_removed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""The CANVAS_TABLES ask is no longer part of the models.

The API never returned a result for it, so the client no longer offers it.
An ask list that still names it is refused when it is built, in either
generation's union and by the v1 deserializer, instead of being sent and
left without an answer.
"""

import pytest
from pydantic import TypeAdapter, ValidationError

import werk24.models.v1.ask as v1_ask
from werk24 import AskUnion
from werk24.models.v1.ask import W24AskType, W24AskUnion, deserialize_ask_v1


def test_the_ask_type_and_its_model_are_gone():
assert "CANVAS_TABLES" not in W24AskType.__members__
assert not hasattr(v1_ask, "W24AskCanvasTables")


@pytest.mark.parametrize(
"adapter",
[TypeAdapter(list[AskUnion]), TypeAdapter(list[W24AskUnion])],
ids=["AskUnion", "W24AskUnion"],
)
def test_an_ask_list_naming_it_is_refused(adapter):
with pytest.raises(ValidationError):
adapter.validate_python([{"ask_type": "NOTES"}, {"ask_type": "CANVAS_TABLES"}])


def test_the_v1_deserializer_refuses_it():
with pytest.raises(ValueError, match="Unknown Ask Type"):
deserialize_ask_v1({"ask_type": "CANVAS_TABLES"})


def test_the_asks_next_to_it_still_resolve():
asks = TypeAdapter(list[AskUnion]).validate_python(
[{"ask_type": "NOTES"}, {"ask_type": "EXCEL_SUMMARY"}]
)
assert [type(ask).__name__ for ask in asks] == [
"W24AskNotes",
"W24AskExcelSummary",
]
23 changes: 0 additions & 23 deletions werk24/models/v1/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from .angle import W24Angle
from .balloon import W24Balloon
from .file_format import (
W24FileFormatTable,
W24FileFormatThumbnail,
W24FileFormatVariantCAD,
)
Expand Down Expand Up @@ -162,10 +161,6 @@ class W24AskType(str, Enum):
""" Ask to obtain an excel summary of the document.
"""

CANVAS_TABLES = "CANVAS_TABLES"
""" Ask to obtain the tables from the canvas.
"""


class W24Ask(BaseModel):
"""Base model from which all Asks inherit
Expand Down Expand Up @@ -1153,22 +1148,6 @@ class W24AskExcelSummary(W24Ask):
ask_type: Literal[W24AskType.EXCEL_SUMMARY] = W24AskType.EXCEL_SUMMARY


class W24AskCanvasTables(W24Ask):
"""Ask to obtain all the canvas tables from the drawing."""

ask_type: Literal[W24AskType.CANVAS_TABLES] = W24AskType.CANVAS_TABLES

split_min_max_columns: bool = Field(
description=("Split range columns into min and max columns."),
default=False,
)

output_format: W24FileFormatTable = Field(
description=("Output format in which to generate the tables."),
default=W24FileFormatTable.CSV,
)


W24AskUnion = Union[
W24AskCanvasThumbnail,
W24AskNotes,
Expand All @@ -1195,7 +1174,6 @@ class W24AskCanvasTables(W24Ask):
W24AskVariantProcesses,
W24AskDebug,
W24AskExcelSummary,
W24AskCanvasTables,
# W24AskVariantToleranceElements
]
"""Union of all W24Asks to ensure proper de-serialization """
Expand Down Expand Up @@ -1265,7 +1243,6 @@ def _deserialize_ask_type(ask_type: str) -> Type[W24Ask]:
"VARIANT_PROCESSES": W24AskVariantProcesses,
"EXCEL_SUMMARY": W24AskExcelSummary,
"DEBUG": W24AskDebug,
"CANVAS_TABLES": W24AskCanvasTables,
}.get(ask_type, None)

if class_ is None:
Expand Down
Loading