From 5727ee317ed1847917d3e375d4e8570096f2d843 Mon Sep 17 00:00:00 2001 From: Shwetansh Singh Date: Mon, 2 Nov 2026 13:17:16 +0000 Subject: [PATCH 1/6] test: add unit tests for DeleteQueue --- tests/test_delete_queue.py | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/test_delete_queue.py diff --git a/tests/test_delete_queue.py b/tests/test_delete_queue.py new file mode 100644 index 0000000..04619f6 --- /dev/null +++ b/tests/test_delete_queue.py @@ -0,0 +1,53 @@ +from databusclient.api.delete import DeleteQueue + +def test_new_queue_is_empty(): + q = DeleteQueue("fake-key") + assert q.is_empty() is True + assert q.is_not_empty() is False + + +def test_add_uri_makes_queue_not_empty(): + q = DeleteQueue("fake-key") + q.add_uri("https://databus.dbpedia.org/acc/group") + assert q.is_empty() is False + + +def test_add_uris_adds_all(): + q = DeleteQueue("fake-key") + q.add_uris(["https://databus.dbpedia.org/acc/group", + "https://databus.dbpedia.org/acc/group/artifact", + "https://databus.dbpedia.org/acc/group/artifact/2024.01.01" + ]) + assert len(q.queue) == 3 + +def test_duplicate_uri_stored_once(): + q = DeleteQueue("fake-key") + q.add_uri("https://databus.dbpedia.org/acc/group") + q.add_uri("https://databus.dbpedia.org/acc/group") + assert len(q.queue) == 1 + + +def test_sorted_queue_deepest_first(): + q = DeleteQueue("fake-key") + q.add_uri("https://databus.dbpedia.org/acc/group/artifact/2024.01.01") + q.add_uri("https://databus.dbpedia.org/acc/group/artifact") + q.add_uri("https://databus.dbpedia.org/acc/group") + assert q.sorted_queue() == [ + "https://databus.dbpedia.org/acc/group/artifact/2024.01.01", + "https://databus.dbpedia.org/acc/group/artifact", + "https://databus.dbpedia.org/acc/group", +] + +def test_path_depth_counts_segments (): + assert DeleteQueue._path_depth("https://databus.dbpedia.org/acc/group") == 2 + assert DeleteQueue._path_depth("https://databus.dbpedia.org/acc/group/artifacat/2024.01.01") == 4 + + +def test_path_depth_ignore_trailing_slash(): + assert DeleteQueue._path_depth("https://databus.dbpedia.org/acc/group/") == 2 + + + + + + From 0ddbc7c70aad9f88dac9adac184d93facc2ffb41 Mon Sep 17 00:00:00 2001 From: Shwetansh Singh Date: Mon, 2 Nov 2026 13:29:02 +0000 Subject: [PATCH 2/6] test: verify DeleteQueue.execute passes sorted URIs with force --- tests/test_delete_queue.py | 63 +++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/tests/test_delete_queue.py b/tests/test_delete_queue.py index 04619f6..d1cca41 100644 --- a/tests/test_delete_queue.py +++ b/tests/test_delete_queue.py @@ -1,4 +1,6 @@ from databusclient.api.delete import DeleteQueue +from databusclient.api import delete + def test_new_queue_is_empty(): q = DeleteQueue("fake-key") @@ -8,46 +10,79 @@ def test_new_queue_is_empty(): def test_add_uri_makes_queue_not_empty(): q = DeleteQueue("fake-key") - q.add_uri("https://databus.dbpedia.org/acc/group") + q.add_uri("https://databus.dbpedia.org/acc/group") assert q.is_empty() is False def test_add_uris_adds_all(): q = DeleteQueue("fake-key") - q.add_uris(["https://databus.dbpedia.org/acc/group", - "https://databus.dbpedia.org/acc/group/artifact", - "https://databus.dbpedia.org/acc/group/artifact/2024.01.01" - ]) + q.add_uris( + [ + "https://databus.dbpedia.org/acc/group", + "https://databus.dbpedia.org/acc/group/artifact", + "https://databus.dbpedia.org/acc/group/artifact/2024.01.01", + ] + ) assert len(q.queue) == 3 + def test_duplicate_uri_stored_once(): q = DeleteQueue("fake-key") - q.add_uri("https://databus.dbpedia.org/acc/group") + q.add_uri("https://databus.dbpedia.org/acc/group") q.add_uri("https://databus.dbpedia.org/acc/group") assert len(q.queue) == 1 def test_sorted_queue_deepest_first(): q = DeleteQueue("fake-key") - q.add_uri("https://databus.dbpedia.org/acc/group/artifact/2024.01.01") - q.add_uri("https://databus.dbpedia.org/acc/group/artifact") q.add_uri("https://databus.dbpedia.org/acc/group") + q.add_uri("https://databus.dbpedia.org/acc/group/artifact/2024.01.01") + q.add_uri("https://databus.dbpedia.org/acc/group/artifact") assert q.sorted_queue() == [ "https://databus.dbpedia.org/acc/group/artifact/2024.01.01", "https://databus.dbpedia.org/acc/group/artifact", "https://databus.dbpedia.org/acc/group", -] + ] -def test_path_depth_counts_segments (): - assert DeleteQueue._path_depth("https://databus.dbpedia.org/acc/group") == 2 - assert DeleteQueue._path_depth("https://databus.dbpedia.org/acc/group/artifacat/2024.01.01") == 4 +def test_path_depth_counts_segments(): + assert DeleteQueue._path_depth("https://databus.dbpedia.org/acc/group") == 2 + assert ( + DeleteQueue._path_depth( + "https://databus.dbpedia.org/acc/group/artifact/2024.01.01" + ) + == 4 + ) -def test_path_depth_ignore_trailing_slash(): - assert DeleteQueue._path_depth("https://databus.dbpedia.org/acc/group/") == 2 +def test_path_depth_ignores_trailing_slash(): + assert DeleteQueue._path_depth("https://databus.dbpedia.org/acc/group/") == 2 +def test_execute_deletes_deepest_first(monkeypatch): + calls = {} + def fake_delete_list(databusURIs, databus_key, force=False, manifest_context=None): + calls["uris"] = databusURIs + calls["key"] = databus_key + calls["force"] = force + monkeypatch.setattr(delete, "_delete_list", fake_delete_list) + q = DeleteQueue("fake-key") + q.add_uris( + [ + "https://databus.dbpedia.org/acc/group", + "https://databus.dbpedia.org/acc/group/artifact/2024.01.01", + "https://databus.dbpedia.org/acc/group/artifact", + ] + ) + q.execute() + + assert calls["uris"] == [ + "https://databus.dbpedia.org/acc/group/artifact/2024.01.01", + "https://databus.dbpedia.org/acc/group/artifact", + "https://databus.dbpedia.org/acc/group", + ] + assert calls["key"] == "fake-key" + assert calls["force"] is True From 90be0767b1586c00b99d9fce66ffe353b0dbef96 Mon Sep 17 00:00:00 2001 From: Shwetansh Singh Date: Tue, 3 Nov 2026 10:29:49 +0000 Subject: [PATCH 3/6] test: add unit tests for _confirm_delete --- tests/test_delete_queue.py | 50 +++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/tests/test_delete_queue.py b/tests/test_delete_queue.py index d1cca41..968d52f 100644 --- a/tests/test_delete_queue.py +++ b/tests/test_delete_queue.py @@ -1,4 +1,4 @@ -from databusclient.api.delete import DeleteQueue +from databusclient.api.delete import DeleteQueue, _confirm_delete from databusclient.api import delete @@ -86,3 +86,51 @@ def fake_delete_list(databusURIs, databus_key, force=False, manifest_context=Non ] assert calls["key"] == "fake-key" assert calls["force"] is True + + +def test_confirm_y_return_confirm(monkeypatch): + def fake_input(prompt): + return "y" + + monkeypatch.setattr("builtins.input", fake_input) + + assert _confirm_delete("https://databus.dbpedia.org/acc/gorup") == "confirm" + + +def test_confirm_messy_yes_returns_confirm(monkeypatch): + def fake_input(prompt): + return " YES " + + monkeypatch.setattr("builtins.input", fake_input) + + assert _confirm_delete("https://databus.dbpedia.org/acc/gorup") == "confirm" + + +def test_confirm_s_returns_skip(monkeypatch): + def fake_input(prompt): + return "s" + + monkeypatch.setattr("builtins.input", fake_input) + + assert _confirm_delete("https://databus.dbpedia.org/acc/gorup") == "skip" + + +def test_confirm_c_return_cancel(monkeypatch): + def fake_input(prompt): + return "c" + + monkeypatch.setattr("builtins.input", fake_input) + + assert _confirm_delete("https://databus.dbpedia.org/acc/gorup") == "cancel" + + +def test_confirm_invalid_then_valid_asks_again(monkeypatch): + answers = ["maybe", "s"] + + def fake_input(prompt): + return answers.pop(0) + + monkeypatch.setattr("builtins.input", fake_input) + + assert _confirm_delete("https://databus.dbpedia.org/acc/group") == "skip" + assert answers == [] From 199e71530f5f8046b95baaeb6695dc772a81f083 Mon Sep 17 00:00:00 2001 From: Shwetansh Singh Date: Tue, 3 Nov 2026 12:19:12 +0000 Subject: [PATCH 4/6] test: fix typos in delete queue tests --- tests/test_delete_queue.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_delete_queue.py b/tests/test_delete_queue.py index 968d52f..6e0821b 100644 --- a/tests/test_delete_queue.py +++ b/tests/test_delete_queue.py @@ -88,13 +88,13 @@ def fake_delete_list(databusURIs, databus_key, force=False, manifest_context=Non assert calls["force"] is True -def test_confirm_y_return_confirm(monkeypatch): +def test_confirm_y_returns_confirm(monkeypatch): def fake_input(prompt): return "y" monkeypatch.setattr("builtins.input", fake_input) - assert _confirm_delete("https://databus.dbpedia.org/acc/gorup") == "confirm" + assert _confirm_delete("https://databus.dbpedia.org/acc/group") == "confirm" def test_confirm_messy_yes_returns_confirm(monkeypatch): @@ -103,7 +103,7 @@ def fake_input(prompt): monkeypatch.setattr("builtins.input", fake_input) - assert _confirm_delete("https://databus.dbpedia.org/acc/gorup") == "confirm" + assert _confirm_delete("https://databus.dbpedia.org/acc/group") == "confirm" def test_confirm_s_returns_skip(monkeypatch): @@ -112,16 +112,16 @@ def fake_input(prompt): monkeypatch.setattr("builtins.input", fake_input) - assert _confirm_delete("https://databus.dbpedia.org/acc/gorup") == "skip" + assert _confirm_delete("https://databus.dbpedia.org/acc/group") == "skip" -def test_confirm_c_return_cancel(monkeypatch): +def test_confirm_c_returns_cancel(monkeypatch): def fake_input(prompt): return "c" monkeypatch.setattr("builtins.input", fake_input) - assert _confirm_delete("https://databus.dbpedia.org/acc/gorup") == "cancel" + assert _confirm_delete("https://databus.dbpedia.org/acc/group") == "cancel" def test_confirm_invalid_then_valid_asks_again(monkeypatch): From cd3f8c14e150066d355b0ce4d7a7bcfedcd8d65d Mon Sep 17 00:00:00 2001 From: Shwetansh Singh Date: Tue, 3 Nov 2026 13:35:54 +0000 Subject: [PATCH 5/6] test: address review nitpicks for delete queue tests --- tests/test_delete_queue.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_delete_queue.py b/tests/test_delete_queue.py index 6e0821b..501fd43 100644 --- a/tests/test_delete_queue.py +++ b/tests/test_delete_queue.py @@ -12,6 +12,7 @@ def test_add_uri_makes_queue_not_empty(): q = DeleteQueue("fake-key") q.add_uri("https://databus.dbpedia.org/acc/group") assert q.is_empty() is False + assert q.is_not_empty() is True def test_add_uris_adds_all(): @@ -61,15 +62,17 @@ def test_path_depth_ignores_trailing_slash(): def test_execute_deletes_deepest_first(monkeypatch): calls = {} + marker = object() def fake_delete_list(databusURIs, databus_key, force=False, manifest_context=None): calls["uris"] = databusURIs calls["key"] = databus_key calls["force"] = force + calls["manifest_context"] = manifest_context monkeypatch.setattr(delete, "_delete_list", fake_delete_list) - q = DeleteQueue("fake-key") + q = DeleteQueue("fake-key", manifest_context=marker) q.add_uris( [ "https://databus.dbpedia.org/acc/group", @@ -86,6 +89,7 @@ def fake_delete_list(databusURIs, databus_key, force=False, manifest_context=Non ] assert calls["key"] == "fake-key" assert calls["force"] is True + assert calls["manifest_context"] is marker def test_confirm_y_returns_confirm(monkeypatch): @@ -134,3 +138,21 @@ def fake_input(prompt): assert _confirm_delete("https://databus.dbpedia.org/acc/group") == "skip" assert answers == [] + + +def test_confirm_skip_word_returns_skip(monkeypatch): + def fake_input(prompt): + return "skip" + + monkeypatch.setattr("builtins.input", fake_input) + + assert _confirm_delete("https://databus.dbpedia.org/acc/group") == "skip" + + +def test_confirm_cancel_word_returns_cancel(monkeypatch): + def fake_input(prompt): + return "cancel" + + monkeypatch.setattr("builtins.input", fake_input) + + assert _confirm_delete("https://databus.dbpedia.org/acc/group") == "cancel" From 5efeeb685da116b695ed1442c241bab9f77a1882 Mon Sep 17 00:00:00 2001 From: Shwetansh Singh Date: Tue, 3 Nov 2026 13:48:50 +0000 Subject: [PATCH 6/6] test: assert _delete_list is called once in execute test --- tests/test_delete_queue.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_delete_queue.py b/tests/test_delete_queue.py index 501fd43..01c6b0f 100644 --- a/tests/test_delete_queue.py +++ b/tests/test_delete_queue.py @@ -69,6 +69,7 @@ def fake_delete_list(databusURIs, databus_key, force=False, manifest_context=Non calls["key"] = databus_key calls["force"] = force calls["manifest_context"] = manifest_context + calls["count"] = calls.get("count", 0) + 1 monkeypatch.setattr(delete, "_delete_list", fake_delete_list) @@ -90,6 +91,7 @@ def fake_delete_list(databusURIs, databus_key, force=False, manifest_context=Non assert calls["key"] == "fake-key" assert calls["force"] is True assert calls["manifest_context"] is marker + assert calls.get("count", 0) == 1 def test_confirm_y_returns_confirm(monkeypatch):