diff --git a/backend/gn_module_monitoring/tests/test_routes/test_site.py b/backend/gn_module_monitoring/tests/test_routes/test_site.py index 6bddc90ca..d63591ca5 100644 --- a/backend/gn_module_monitoring/tests/test_routes/test_site.py +++ b/backend/gn_module_monitoring/tests/test_routes/test_site.py @@ -40,6 +40,13 @@ def test_get_sites(self, sites): assert r.json["count"] >= len(sites) assert any([schema.dump(site) in r.json["items"] for site in sites.values()]) + def test_get_sites_limit(self, sites): + limit = 34 + + r = self.client.get(url_for("monitorings.get_sites", limit=limit)) + + assert len(r.json["items"]) == limit + def test_get_module_sites(self): module_code = "TEST" r = self.client.get(url_for("monitorings.get_module_sites", module_code=module_code)) diff --git a/backend/gn_module_monitoring/tests/test_utils/__init__.py b/backend/gn_module_monitoring/tests/test_utils/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/backend/gn_module_monitoring/tests/test_utils/test_routes.py b/backend/gn_module_monitoring/tests/test_utils/test_routes.py new file mode 100644 index 000000000..cc6357f37 --- /dev/null +++ b/backend/gn_module_monitoring/tests/test_utils/test_routes.py @@ -0,0 +1,14 @@ +import pytest +from werkzeug.datastructures import MultiDict + +from gn_module_monitoring.utils.routes import get_limit_offset + + +@pytest.mark.parametrize("limit, offset", [("1", "2"), (1, 2), ("1", 2), (1, "2")]) +def test_get_limit_offset(limit, offset): + multi_dict = MultiDict([("limit", limit), ("offset", offset)]) + + comp_limit, comp_offset = get_limit_offset(params=multi_dict) + + assert isinstance(comp_limit, int) + assert isinstance(comp_offset, int) diff --git a/backend/gn_module_monitoring/utils/routes.py b/backend/gn_module_monitoring/utils/routes.py index 5a75c1c4b..a7889dc68 100644 --- a/backend/gn_module_monitoring/utils/routes.py +++ b/backend/gn_module_monitoring/utils/routes.py @@ -10,11 +10,11 @@ def get_limit_offset(params: MultiDict) -> Tuple[int]: - return params.pop("limit", 50), params.pop("offset", 1) + return int(params.pop("limit", 50)), int(params.pop("offset", 1)) def paginate(query: Query, schema: Schema, limit: int, page: int) -> Response: - result = query.paginate(page=page, error_out=False, max_per_page=limit) + result = query.paginate(page=page, error_out=False, per_page=limit) pagination_schema = paginate_schema(schema) data = pagination_schema().dump( dict(items=result.items, count=result.total, limit=limit, offset=page - 1)