Skip to content

Commit

Permalink
api: fix ID field in orderBy
Browse files Browse the repository at this point in the history
Fixes: #353

Signed-off-by: Isabella do Amaral <[email protected]>
  • Loading branch information
isinyaaa committed Sep 6, 2024
1 parent 327e865 commit 2e32888
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api/openapi/model-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ components:
enum:
- CREATE_TIME
- LAST_UPDATE_TIME
- Id
- ID
type: string
Artifact:
oneOf:
Expand Down Expand Up @@ -1661,7 +1661,7 @@ components:
explode: true
examples:
orderBy:
value: Id
value: ID
name: orderBy
description: Specifies the order by criteria for listing entities.
schema:
Expand Down
2 changes: 1 addition & 1 deletion clients/python/src/mr_openapi/models/order_by_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OrderByField(str, Enum):
"""
CREATE_TIME = "CREATE_TIME"
LAST_UPDATE_TIME = "LAST_UPDATE_TIME"
ID = "Id"
ID = "ID"

@classmethod
def from_json(cls, json_str: str) -> Self:
Expand Down
132 changes: 132 additions & 0 deletions clients/python/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,76 @@ def test_get_registered_models(client: ModelRegistry):
assert i == models


@pytest.mark.e2e
def test_get_registered_models_order_by(client: ModelRegistry):
models = 5

rms = []
for name in [f"test_model{i}" for i in range(models)]:
rms.append(
client.register_model(
name,
"s3",
model_format_name="test_format",
model_format_version="test_version",
version="1.0.0",
)
)

# id ordering should match creation order
i = 0
for rm, by_id in zip(
rms,
client.get_registered_models().order_by_id(),
strict=True,
):
assert rm.id == by_id.id
i += 1

assert i == models

# and obviously, creation ordering should match creation ordering
i = 0
for rm, by_creation in zip(
rms,
client.get_registered_models().order_by_creation_time(),
strict=True,
):
assert rm.id == by_creation.id
i += 1

assert i == models

# update order should match creation ordering by default
i = 0
for rm, by_update in zip(
rms,
client.get_registered_models().order_by_update_time(),
strict=True,
):
assert rm.id == by_update.id
i += 1

assert i == models

# now update the models in reverse order
for rm in reversed(rms):
rm.description = "updated"
client.update(rm)

# and they should match in reverse
i = 0
for rm, by_update in zip(
reversed(rms),
client.get_registered_models().order_by_update_time(),
strict=True,
):
assert rm.id == by_update.id
i += 1

assert i == models


@pytest.mark.e2e
def test_get_registered_models_and_reset(client: ModelRegistry):
model_count = 6
Expand Down Expand Up @@ -260,6 +330,68 @@ def test_get_model_versions(client: ModelRegistry):
assert i == models


@pytest.mark.e2e
def test_get_model_versions_order_by(client: ModelRegistry):
name = "test_model"
models = 5
mvs = []
for v in [f"1.0.{i}" for i in range(models)]:
client.register_model(
name,
"s3",
model_format_name="test_format",
model_format_version="test_version",
version=v,
)
mvs.append(client.get_model_version(name, v))

i = 0
for mv, by_id in zip(
mvs,
client.get_model_versions(name).order_by_id(),
strict=True,
):
assert mv.id == by_id.id
i += 1

assert i == models

i = 0
for mv, by_creation in zip(
mvs,
client.get_model_versions(name).order_by_creation_time(),
strict=True,
):
assert mv.id == by_creation.id
i += 1

assert i == models

i = 0
for mv, by_update in zip(
mvs,
client.get_model_versions(name).order_by_update_time(),
strict=True,
):
assert mv.id == by_update.id
i += 1

assert i == models

for mv in reversed(mvs):
mv.description = "updated"
client.update(mv)

i = 0
for mv, by_update in zip(
reversed(mvs),
client.get_model_versions(name).order_by_update_time(),
strict=True,
):
assert mv.id == by_update.id
i += 1


@pytest.mark.e2e
def test_get_model_versions_and_reset(client: ModelRegistry):
name = "test_model"
Expand Down
4 changes: 2 additions & 2 deletions pkg/openapi/model_order_by_field.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2e32888

Please sign in to comment.