fix(tests): test_form2_ahr_limit — чтение plan.qN без KeyError после null-strip (AURORA-1897, #296)

После AURORA-1848 GET листа вырезает null-поля, поэтому у заголовка статьи
без плана в квартале ключа plan.qN нет вовсе, и чтение «до» падало
KeyError до проверки самой логики. Заменено на plan.get("qN") or 0.
Продуктовый код не меняется: с правкой все 7 тестов зелёные на test
(после PR #295).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andrey Epifancev 2026-11-08 16:04:33 +04:00
parent f9fbd7399f
commit 8ba26427dd

View File

@ -104,7 +104,7 @@ def test_annual_dms_limit_divided_by_four(client, admin_tokens, form2_id):
# лимитные LEAF из сидовых данных). # лимитные LEAF из сидовых данных).
before = _find_ahr_header_row( before = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 456 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 456
)["data"]["plan"]["q1"] or 0 )["data"]["plan"].get("q1") or 0
rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 24, "qty_q1", 10) rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 24, "qty_q1", 10)
row = _find_by_id(rows, 24) row = _find_by_id(rows, 24)
@ -113,7 +113,7 @@ def test_annual_dms_limit_divided_by_four(client, admin_tokens, form2_id):
after = _find_ahr_header_row( after = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 456 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 456
)["data"]["plan"]["q1"] or 0 )["data"]["plan"].get("q1") or 0
assert (after - before) == pytest.approx(69.645) assert (after - before) == pytest.approx(69.645)
@ -124,7 +124,7 @@ def test_quarterly_limit_uses_amount_without_vat(client, admin_tokens, form2_id)
# статьи — см. комментарий в test_annual_dms_limit_divided_by_four. # статьи — см. комментарий в test_annual_dms_limit_divided_by_four.
before = _find_ahr_header_row( before = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 150 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 150
)["data"]["plan"]["q2"] or 0 )["data"]["plan"].get("q2") or 0
rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 3, "qty_q2", 1) rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 3, "qty_q2", 1)
row = _find_by_id(rows, 3) row = _find_by_id(rows, 3)
@ -132,7 +132,7 @@ def test_quarterly_limit_uses_amount_without_vat(client, admin_tokens, form2_id)
after = _find_ahr_header_row( after = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 150 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 150
)["data"]["plan"]["q2"] or 0 )["data"]["plan"].get("q2") or 0
assert (after - before) == pytest.approx(2.0) assert (after - before) == pytest.approx(2.0)
@ -144,7 +144,7 @@ def test_sim_card_without_vat_limit_backfilled_is_not_zero(client, admin_tokens,
# статьи — см. комментарий в test_annual_dms_limit_divided_by_four. # статьи — см. комментарий в test_annual_dms_limit_divided_by_four.
before = _find_ahr_header_row( before = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 150 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 150
)["data"]["plan"]["q1"] or 0 )["data"]["plan"].get("q1") or 0
rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 7, "qty_q1", 20) rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 7, "qty_q1", 20)
row = _find_by_id(rows, 7) row = _find_by_id(rows, 7)
@ -152,7 +152,7 @@ def test_sim_card_without_vat_limit_backfilled_is_not_zero(client, admin_tokens,
after = _find_ahr_header_row( after = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 150 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 150
)["data"]["plan"]["q1"] or 0 )["data"]["plan"].get("q1") or 0
assert (after - before) == pytest.approx(7.5) assert (after - before) == pytest.approx(7.5)
@ -165,7 +165,7 @@ def test_printers_annual_limit_without_name_lookup(client, admin_tokens, form2_i
# комментарий в test_annual_dms_limit_divided_by_four. # комментарий в test_annual_dms_limit_divided_by_four.
before = _find_ahr_header_row( before = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 167 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 167
)["data"]["plan"]["q1"] or 0 )["data"]["plan"].get("q1") or 0
rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 13, "qty_q1", 5) rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 13, "qty_q1", 5)
row = _find_by_id(rows, 13) row = _find_by_id(rows, 13)
@ -173,7 +173,7 @@ def test_printers_annual_limit_without_name_lookup(client, admin_tokens, form2_i
after = _find_ahr_header_row( after = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 167 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 167
)["data"]["plan"]["q1"] or 0 )["data"]["plan"].get("q1") or 0
assert (after - before) == pytest.approx(6.471875) assert (after - before) == pytest.approx(6.471875)
@ -185,7 +185,7 @@ def test_quarterly_norm_unchanged_other_than_vat_source(client, admin_tokens, fo
# статьи — см. комментарий в test_annual_dms_limit_divided_by_four. # статьи — см. комментарий в test_annual_dms_limit_divided_by_four.
before = _find_ahr_header_row( before = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 179 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 179
)["data"]["plan"]["q3"] or 0 )["data"]["plan"].get("q3") or 0
rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 17, "qty_q3", 2) rows = _patch_cell(client, admin_tokens, form2_id, "AHR_LIMIT", 17, "qty_q3", 2)
row = _find_by_id(rows, 17) row = _find_by_id(rows, 17)
@ -193,7 +193,7 @@ def test_quarterly_norm_unchanged_other_than_vat_source(client, admin_tokens, fo
after = _find_ahr_header_row( after = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 179 _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), 179
)["data"]["plan"]["q3"] or 0 )["data"]["plan"].get("q3") or 0
assert (after - before) == pytest.approx(7.5) assert (after - before) == pytest.approx(7.5)
@ -232,7 +232,7 @@ def test_rent_plan_still_passed_through_without_division(client, admin_tokens, f
# быть другие записи аренды из сидовых данных). # быть другие записи аренды из сидовых данных).
before = _find_ahr_header_row( before = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), AHR_RENT_PARENT_EXPENSE_ITEM _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), AHR_RENT_PARENT_EXPENSE_ITEM
)["data"]["plan"]["q1"] or 0 )["data"]["plan"].get("q1") or 0
response = client.post( response = client.post(
f"/api/v1/form/{form2_id}/sheet/AHR_RENT/line", f"/api/v1/form/{form2_id}/sheet/AHR_RENT/line",
@ -253,5 +253,5 @@ def test_rent_plan_still_passed_through_without_division(client, admin_tokens, f
after = _find_ahr_header_row( after = _find_ahr_header_row(
_get_sheet_rows(client, admin_tokens, form2_id, "AHR"), AHR_RENT_PARENT_EXPENSE_ITEM _get_sheet_rows(client, admin_tokens, form2_id, "AHR"), AHR_RENT_PARENT_EXPENSE_ITEM
)["data"]["plan"]["q1"] or 0 )["data"]["plan"].get("q1") or 0
assert (after - before) == 100 assert (after - before) == 100