11import json
2+ import pytest
23import re
34from unittest .mock import patch
45
@@ -274,13 +275,25 @@ def test_bulk_update_with_source_raise_bulk_indexing_error(
274275 )
275276
276277
278+ @pytest .mark .parametrize (
279+ "bulk_update_return" ,
280+ [
281+ {"updated" : 1 , "errors" : 0 , "total" : 1 },
282+ {"updated" : 0 , "errors" : 1 , "total" : 1 },
283+ ],
284+ )
277285@patch ("tim.helpers.validate_bulk_cli_options" )
278286@patch ("tim.opensearch.bulk_update" )
279- def test_bulk_update_embeddings_success (
280- mock_bulk_update , mock_validate_bulk_cli_options , caplog , monkeypatch , runner
287+ def test_bulk_update_embeddings_logs_complete (
288+ mock_bulk_update ,
289+ mock_validate_bulk_cli_options ,
290+ bulk_update_return ,
291+ caplog ,
292+ monkeypatch ,
293+ runner ,
281294):
282295 monkeypatch .delenv ("TIMDEX_OPENSEARCH_ENDPOINT" , raising = False )
283- mock_bulk_update .return_value = { "updated" : 1 , "errors" : 0 , "total" : 1 }
296+ mock_bulk_update .return_value = bulk_update_return
284297 mock_validate_bulk_cli_options .return_value = "libguides"
285298
286299 result = runner .invoke (
@@ -304,34 +317,7 @@ def test_bulk_update_embeddings_success(
304317
305318@patch ("tim.helpers.validate_bulk_cli_options" )
306319@patch ("tim.opensearch.bulk_update" )
307- def test_bulk_update_embeddings_raise_error (
308- mock_bulk_update , mock_validate_bulk_cli_options , caplog , monkeypatch , runner
309- ):
310- monkeypatch .delenv ("TIMDEX_OPENSEARCH_ENDPOINT" , raising = False )
311- mock_bulk_update .return_value = {"updated" : 0 , "errors" : 1 , "total" : 1 }
312- mock_validate_bulk_cli_options .return_value = "libguides"
313-
314- result = runner .invoke (
315- main ,
316- [
317- "bulk-update-embeddings" ,
318- "--source" ,
319- "libguides" ,
320- "--run-id" ,
321- "85cfe316-089c-4639-a5af-c861a7321493" ,
322- "tests/fixtures/dataset" ,
323- ],
324- )
325- assert result .exit_code == EXIT_CODES ["success" ]
326- assert (
327- f"Bulk update with embeddings complete: { json .dumps (mock_bulk_update ())} "
328- in caplog .text
329- )
330-
331-
332- @patch ("tim.helpers.validate_bulk_cli_options" )
333- @patch ("tim.opensearch.bulk_update" )
334- def test_bulk_update_embeddings_raise_bulk_operation_error (
320+ def test_bulk_update_embeddings_exit_bulk_operation_error (
335321 mock_bulk_update , mock_validate_bulk_cli_options , caplog , monkeypatch , runner
336322):
337323 monkeypatch .delenv ("TIMDEX_OPENSEARCH_ENDPOINT" , raising = False )
@@ -351,7 +337,7 @@ def test_bulk_update_embeddings_raise_bulk_operation_error(
351337 "tests/fixtures/dataset" ,
352338 ],
353339 )
354- assert result .exit_code == EXIT_CODES ["success " ]
340+ assert result .exit_code == EXIT_CODES ["error " ]
355341 assert "Bulk update with embeddings failed" in caplog .text
356342
357343
0 commit comments