Skip to content

Commit 38aabfa

Browse files
author
Andrei Neagu
committed
Merge remote-tracking branch 'upstream/master' into pr-osparc-fixed-dynamic-scheduler-ui
2 parents 6762e0b + 493488c commit 38aabfa

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

packages/models-library/src/models_library/rpc_pagination.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@
3030
class PageRefsParams(PageRefs[PageQueryParameters]):
3131
@classmethod
3232
def create(cls, total: int, limit: int, offset: int) -> "PageRefsParams":
33-
last_page = ceil(total / limit) - 1
33+
last_page = ceil(total / limit) - 1 if total > 0 else 0
3434
return cls.model_validate(
3535
{
3636
"self": {"offset": offset, "limit": limit},
3737
"first": {"offset": 0, "limit": limit},
3838
"prev": (
3939
{"offset": max(offset - limit, 0), "limit": limit}
40-
if offset > 0
40+
if offset > 0 and total > 0
4141
else None
4242
),
4343
"next": (
4444
{
4545
"offset": min(offset + limit, last_page * limit),
4646
"limit": limit,
4747
}
48-
if offset < (last_page * limit)
48+
if offset < (last_page * limit) and total > 0
4949
else None
5050
),
5151
"last": {"offset": last_page * limit, "limit": limit},

packages/models-library/tests/test_rest_pagination.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
from models_library.rest_pagination import Page, PageMetaInfoLimitOffset
5-
from pydantic.main import BaseModel
5+
from pydantic import BaseModel, ValidationError
66
from pytest_simcore.examples.models_library import PAGE_EXAMPLES
77

88

@@ -26,7 +26,7 @@ def test_page_response_limit_offset_models(cls_model: BaseModel, examples: list[
2626

2727

2828
def test_invalid_offset():
29-
with pytest.raises(ValueError):
29+
with pytest.raises(ValidationError):
3030
PageMetaInfoLimitOffset(limit=6, total=5, offset=5, count=2)
3131

3232

@@ -39,14 +39,14 @@ def test_invalid_offset():
3939
],
4040
)
4141
def test_invalid_count(count: int, offset: int):
42-
with pytest.raises(ValueError):
42+
with pytest.raises(ValidationError):
4343
PageMetaInfoLimitOffset(limit=6, total=5, offset=offset, count=count)
4444

4545

4646
def test_data_size_does_not_fit_count():
4747
example = deepcopy(PAGE_EXAMPLES[0])
4848
example["_meta"]["count"] = len(example["data"]) - 1
49-
with pytest.raises(ValueError):
49+
with pytest.raises(ValidationError):
5050
Page[str](**example)
5151

5252

packages/pytest-simcore/src/pytest_simcore/examples/models_library.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
},
2626
"data": ["data 5", "data 6", "data 7"],
2727
},
28+
# empty page
29+
{
30+
"_meta": {"total": 0, "count": 0, "limit": 4, "offset": 0},
31+
"_links": {
32+
"self": "https://osparc.io/v2/listing?offset=0&limit=4",
33+
"first": "https://osparc.io/v2/listing?offset=0&limit=4",
34+
"prev": None,
35+
"next": None,
36+
"last": "https://osparc.io/v2/listing?offset=0&limit=4",
37+
},
38+
"data": [],
39+
},
2840
]
2941

3042
RPC_PAGE_EXAMPLES: Final[list[dict]] = [
@@ -52,4 +64,16 @@
5264
},
5365
"data": ["data 5", "data 6", "data 7"],
5466
},
67+
# empty page
68+
{
69+
"_meta": {"total": 0, "count": 0, "limit": 4, "offset": 0},
70+
"_links": {
71+
"self": {"offset": 0, "limit": 4},
72+
"first": {"offset": 0, "limit": 4},
73+
"prev": None,
74+
"next": None,
75+
"last": {"offset": 0, "limit": 4},
76+
},
77+
"data": [],
78+
},
5579
]

services/catalog/tests/unit/with_dbs/test_api_rpc.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,25 @@ async def background_sync_task_mocked(
108108
await services_db_tables_injector(fake_data_for_services)
109109

110110

111+
async def test_rpc_catalog_with_no_services_returns_empty_page(
112+
background_sync_task_mocked: None,
113+
mocked_director_service_api: MockRouter,
114+
rpc_client: RabbitMQRPCClient,
115+
user_id: UserID,
116+
app: FastAPI,
117+
):
118+
assert app
119+
120+
page = await list_services_paginated(
121+
rpc_client, product_name="not_existing_returns_no_services", user_id=user_id
122+
)
123+
assert page.data == []
124+
assert page.links.next is None
125+
assert page.links.prev is None
126+
assert page.meta.count == 0
127+
assert page.meta.total == 0
128+
129+
111130
async def test_rpc_catalog_client(
112131
background_sync_task_mocked: None,
113132
mocked_director_service_api: MockRouter,

0 commit comments

Comments
 (0)