Skip to content

Commit 67c064b

Browse files
Address comments in PR #373
* Fix cassette to handle method call to refresh index * Use parameterized tests * Remove comments
1 parent 6eb5385 commit 67c064b

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

tests/fixtures/cassettes/opensearch/bulk_update_updates_records.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,26 @@ interactions:
2626
status:
2727
code: 200
2828
message: OK
29+
- request:
30+
body: null
31+
headers:
32+
Content-Length:
33+
- '0'
34+
content-type:
35+
- application/json
36+
user-agent:
37+
- opensearch-py/2.8.0 (Python 3.12.2)
38+
method: POST
39+
uri: http://localhost:9200/test-index/_refresh
40+
response:
41+
body:
42+
string: '{"_shards":{"total":2,"successful":1,"failed":0}}'
43+
headers:
44+
content-length:
45+
- '49'
46+
content-type:
47+
- application/json; charset=UTF-8
48+
status:
49+
code: 200
50+
message: OK
2951
version: 1

tests/test_cli.py

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import pytest
23
import re
34
from 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

tests/test_opensearch.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,6 @@ def test_bulk_delete_logs_error_if_record_not_found(
535535
)
536536

537537

538-
# what happens when you try to 'bulk_update_embeddings' a document that doesn't exist*
539-
# - do you need all these mocks or VCRs to test that (probably no :o)
540-
# fixture that reindexes a source into the mock
541-
# if we run tda in fixtures/datasets -- what's in it??
542538
@my_vcr.use_cassette("opensearch/bulk_update_updates_records.yaml")
543539
def test_bulk_update_updates_records(test_opensearch_client):
544540
updates = [

0 commit comments

Comments
 (0)