Skip to content

Commit

Permalink
🐛 Objecttypes v1 does not use pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
damm89 committed Oct 23, 2024
1 parent 0aab31f commit f9114f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
6 changes: 1 addition & 5 deletions src/bptl/work_units/zgw/objects/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ def fetch_objecttype(task: BaseTask, url: str) -> Dict:

def fetch_objecttypes(task: BaseTask, query_params: dict = dict()) -> List[Dict]:
client = get_objecttypes_client(task)
objecttypes = get_paginated_results(
client,
"objecttypes",
request_kwargs={"params": query_params},
)
objecttypes = client.get("objecttypes", request_kwargs={"params": query_params})
return objecttypes


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from bptl.camunda.models import ExternalTask
from bptl.tasks.base import MissingVariable
from bptl.tasks.tests.factories import DefaultServiceFactory, TaskMappingFactory
from bptl.tests.utils import mock_parallel, paginated_response
from bptl.tests.utils import mock_parallel

from ..models import MetaObjectTypesConfig
from ..tasks import filter_zaakobjects_on_objecttype_label
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_missing_label_variable(self, m):

def test_no_objecttypes(self, m):
mock_service_oas_get(m, OBJECTTYPES_ROOT, "objecttypes")
m.get(f"{OBJECTTYPES_ROOT}objecttypes", json=paginated_response([]))
m.get(f"{OBJECTTYPES_ROOT}objecttypes", json=[])
task_dict = {
"topic_name": "some-topic-name",
"worker_id": "test-worker-id",
Expand All @@ -137,7 +137,7 @@ def test_objecttypes_empty_label(self, m):
mock_service_oas_get(m, OBJECTTYPES_ROOT, "objecttypes")
m.get(
f"{OBJECTTYPES_ROOT}objecttypes",
json=paginated_response([REVIEW_OBJECTTYPE]),
json=[REVIEW_OBJECTTYPE],
)
m.get(f"{REVIEW_OBJECT['url']}", json=REVIEW_OBJECT)
zaakobject = generate_oas_component(
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_objecttypes_mismatch_label(self, m):
mock_service_oas_get(m, OBJECTTYPES_ROOT, "objecttypes")
m.get(
f"{OBJECTTYPES_ROOT}objecttypes",
json=paginated_response([REVIEW_OBJECTTYPE]),
json=[REVIEW_OBJECTTYPE],
)
m.get(f"{REVIEW_OBJECT['url']}", json=REVIEW_OBJECT)
zaakobject = generate_oas_component(
Expand Down
21 changes: 4 additions & 17 deletions src/bptl/work_units/zgw/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@
def get_paginated_results(
client: Client, resource: str, minimum=None, *args, **kwargs
) -> list:
query_params = kwargs.get("query_params", {})

results = []
if hasattr(client, "list"):
query_params = kwargs.get("query_params", {})
response = client.list(resource, *args, **kwargs)
else:
if not "request_kwargs" in kwargs:
kwargs["request_kwargs"] = {}
if not "params" in kwargs["request_kwargs"]:
kwargs["request_kwargs"]["params"] = {}

query_params = kwargs["request_kwargs"]["params"]
response = client.get(resource, *args, **kwargs)
response = client.list(resource, *args, **kwargs)

results += response["results"]

Expand All @@ -30,12 +21,8 @@ def get_paginated_results(
query = parse_qs(next_url.query)
new_page = int(query["page"][0])
query_params["page"] = [new_page]
if hasattr(client, "list"):
kwargs["query_params"] = query_params
response = client.list(resource, *args, **kwargs)
else:
kwargs["request_kwargs"]["params"] = query_params
response = client.get(resource, *args, **kwargs)
kwargs["query_params"] = query_params
response = client.list(resource, *args, **kwargs)
results += response["results"]

if minimum and len(results) >= minimum:
Expand Down

0 comments on commit f9114f1

Please sign in to comment.