test(plans): «нет файла» — настоящий multipart без части file (#617)

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
This commit is contained in:
Claude
2026-09-24 19:57:42 +03:00
parent 857369b18b
commit 3fafd9f2b6
+12 -1
View File
@@ -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"