Skip to content

Commit

Permalink
Merge pull request #79 from maykinmedia/fix/handle_unexpected_operati…
Browse files Browse the repository at this point in the history
…on_ids

Handle unexpected operation ids in schema
  • Loading branch information
sergei-maertens authored Jan 11, 2024
2 parents 7de0c1e + 250e7dc commit cd2e952
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
48 changes: 47 additions & 1 deletion tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from pathlib import Path

from django.core.files.base import File
from django.core.files.base import ContentFile, File
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -105,3 +106,48 @@ def test_listzaaktypen_mixin_server_error(settings, admin_client, requests_mock)
# assert that Zaaktype field is present in admin page despite HTTPError
zaaktypen_label = doc.find("label")
assert zaaktypen_label.text() == "Zaaktype:"


@pytest.mark.django_db
def test_listzaaktypen_unexpected_operation_id(settings, admin_client, requests_mock):
requests_mock.get(
f"{API_ROOT}zaaktypen",
status_code=200,
json={"results": [], "count": 0, "next": None},
)

service = Service.objects.create(
label="Test",
api_type=APITypes.ztc,
api_root=API_ROOT,
oas_file=ContentFile(
json.dumps(
{
"openapi": "3.0.1",
"info": {"title": "Catalogi API 1.0", "version": "1.0"},
"paths": {
"/api/v1/zaaktypen": {
"get": {
"tags": ["ZaakType"],
"summary": "Alle ZAAKTYPEn opvragen.\r\nDeze lijst kan gefilterd wordt met query-string parameters.",
"description": "",
"operationId": "ZaakTypeGetAll", # Operation ID different from zaaktype_list
"responses": {
"200": {"description": "OK"},
"401": {"description": "Unauthorized"},
},
}
}
},
}
),
name="schema.yaml",
),
)
service.full_clean()

# assert that admin page works despite an operation ID different from zaaktype_list
url = reverse("admin:testapp_zgwconfig_change")
response = admin_client.get(url)

assert response.status_code == 200
7 changes: 6 additions & 1 deletion zgw_consumers/admin_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def get_zaaktypen() -> Dict[Service, List[Dict[str, Any]]]:
client = service.build_client()
logger.debug("Fetching zaaktype list for service %r", service)
zaaktypen_per_service[service] = []
response = client.list("zaaktype")
response = client.operation(
url="zaaktypen",
operation_id="zaaktype_list",
method="GET",
data={},
)
zaaktypen_per_service[service] += response["results"]
while response["next"]:
next_url = urlparse(response["next"])
Expand Down

0 comments on commit cd2e952

Please sign in to comment.