Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unexpected operation ids in schema #79

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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