From c9a960f07f51f209c25ea3b4af72151d7890cd00 Mon Sep 17 00:00:00 2001
From: Antoine Lambert <anlambert@softwareheritage.org>
Date: Thu, 23 Nov 2023 17:42:21 +0100
Subject: [PATCH] tests/test_cli: Fix test_locate_origins with dev version of
 swh-graph

It now requires a swh-graph server running or connection errors appear.

Use swh-graph NaiveClient to avoid spawning a real graph server during
the tests.
---
 conftest.py                    | 6 +++++-
 swh/scrubber/cli.py            | 1 -
 swh/scrubber/tests/test_cli.py | 8 ++++++--
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/conftest.py b/conftest.py
index 785711b..706148c 100644
--- a/conftest.py
+++ b/conftest.py
@@ -1 +1,5 @@
-pytest_plugins = ["swh.storage.pytest_plugin", "swh.core.db.pytest_plugin"]
+pytest_plugins = [
+    "swh.storage.pytest_plugin",
+    "swh.core.db.pytest_plugin",
+    "swh.graph.pytest_plugin",
+]
diff --git a/swh/scrubber/cli.py b/swh/scrubber/cli.py
index e279228..ca2fafe 100644
--- a/swh/scrubber/cli.py
+++ b/swh/scrubber/cli.py
@@ -387,7 +387,6 @@ def scrubber_check_stats(ctx, name: str, config_id: int, json_format: bool):
     stats = db.config_get_stats(config_id)
 
     if json_format:
-
         stats["config"] = asdict(stats["config"])
         stats["config"]["object_type"] = stats["config"]["object_type"].name.lower()
         click.echo(dumps(stats, indent=2))
diff --git a/swh/scrubber/tests/test_cli.py b/swh/scrubber/tests/test_cli.py
index 53f9796..381f7d1 100644
--- a/swh/scrubber/tests/test_cli.py
+++ b/swh/scrubber/tests/test_cli.py
@@ -487,7 +487,6 @@ def test_check_stats(mocker, scrubber_db, swh_storage):
     assert result.exit_code == 0, result.output
 
     for otype in ("snapshot", "revision", "release"):
-
         result = invoke(
             scrubber_db,
             ["check", "stats", "--json", f"cfg_{otype}"],
@@ -701,7 +700,7 @@ def test_check_journal(
     assert journal_checker.method_calls == [call.run()]
 
 
-def test_locate_origins(mocker, scrubber_db, swh_storage):
+def test_locate_origins(mocker, scrubber_db, swh_storage, naive_graph_client):
     origin_locator = MagicMock()
     OriginLocator = mocker.patch(
         "swh.scrubber.origin_locator.OriginLocator", return_value=origin_locator
@@ -709,6 +708,11 @@ def test_locate_origins(mocker, scrubber_db, swh_storage):
     get_scrubber_db = mocker.patch(
         "swh.scrubber.get_scrubber_db", return_value=scrubber_db
     )
+    mocker.patch(
+        "swh.graph.http_client.RemoteGraphClient",
+        return_value=naive_graph_client,
+    )
+
     result = invoke(scrubber_db, ["locate"], storage=swh_storage)
     assert result.exit_code == 0, result.output
     assert result.output == ""
-- 
GitLab