Skip to content

Commit a61fc7b

Browse files
fix: test_error_codes mocks per Timon review
1 parent e67fd5f commit a61fc7b

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

tests/test_error_codes.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from __future__ import annotations
44

55
import json
6-
from types import SimpleNamespace
76

87
import pytest
98

109
from api.error_codes import ErrorCode
10+
from api.search import _IndexSearchOutcome
1111
from tests.conftest import assert_error_response
1212

1313

@@ -79,18 +79,16 @@ def test_bulk_export_empty_includes_export_nothing_code(client_empty):
7979

8080

8181
def test_search_index_unavailable_code(client_single, monkeypatch):
82+
def _raise_live_scan_failure(*_args, **_kwargs):
83+
raise RuntimeError("live scan failed")
84+
8285
monkeypatch.setattr(
8386
"api.search._search_via_index",
84-
lambda *_args, **_kwargs: SimpleNamespace(
85-
hits=None,
86-
fts_exhausted=False,
87-
index_locked_without_hits=True,
87+
lambda *_args, **_kwargs: _IndexSearchOutcome(
88+
None, False, index_locked_without_hits=True
8889
),
8990
)
90-
monkeypatch.setattr(
91-
"api.search._search_live_scan",
92-
lambda *_args, **_kwargs: (_ for _ in ()).throw(RuntimeError("live scan failed")),
93-
)
91+
monkeypatch.setattr("api.search._search_live_scan", _raise_live_scan_failure)
9492
resp = client_single.get("/api/search?q=test")
9593
assert resp.status_code == 503
9694
body_text = json.dumps(resp.get_json())

0 commit comments

Comments
 (0)