From 3fafd9f2b60bbb855bc3105ed5ea2136c9eca7c0 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 24 Sep 2026 07:40:31 +0300 Subject: [PATCH] =?UTF-8?q?test(plans):=20=C2=AB=D0=BD=D0=B5=D1=82=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=C2=BB=20=E2=80=94=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D1=8F=D1=89=D0=B8=D0=B9=20multipart=20=D0=B1?= =?UTF-8?q?=D0=B5=D0=B7=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=20file=20(#617)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HA-тест test_issue_617_plan_upload_validates_fields_like_ws_plan_set слал FormData только с текстовыми полями. aiohttp в этом случае кодирует тело как application/x-www-form-urlencoded, а не multipart: view отвечал bad_request (контракт ТЗ — «битый multipart»), и ожидание no_file в тесте было неверным — дефект фикстуры, а не view (Validate 35952858822). Теперь случай «multipart без части file» задаётся явно (FormData(default_to_multipart=True)) и ждёт no_file, а тело без multipart проверяется отдельно и ждёт bad_request. Ни одно ожидание не ослаблено: добавлена ещё одна проверка ветки отказа. Issue: #617 User-Visible: no --- tests_backend/test_ha_upload.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests_backend/test_ha_upload.py b/tests_backend/test_ha_upload.py index c8891284..98930647 100644 --- a/tests_backend/test_ha_upload.py +++ b/tests_backend/test_ha_upload.py @@ -314,13 +314,24 @@ async def test_issue_617_plan_upload_validates_fields_like_ws_plan_set( assert bad_ext.status == 400 assert (await bad_ext.json())["error"] == "bad_ext" - no_file = FormData() + # Without a file field aiohttp's FormData falls back to + # application/x-www-form-urlencoded, which is not multipart at all: the + # view answers bad_request for it (the card never sends such a body). The + # "multipart without a file part" case has to be forced explicitly. + no_file = FormData(default_to_multipart=True) no_file.add_field("space_id", "f1") no_file.add_field("ext", "png") missing = await client.post("/api/houseplan/plans/upload", data=no_file) assert missing.status == 400 assert (await missing.json())["error"] == "no_file" + urlencoded = FormData() + urlencoded.add_field("space_id", "f1") + urlencoded.add_field("ext", "png") + not_multipart = await client.post("/api/houseplan/plans/upload", data=urlencoded) + assert not_multipart.status == 400 + assert (await not_multipart.json())["error"] == "bad_request" + two = await client.post("/api/houseplan/plans/upload", data=_plan_form(b"x", files=2)) assert two.status == 400 assert (await two.json())["error"] == "one_file_only"