From ed2c2dbed959d8bd12f689827629383ce9494a47 Mon Sep 17 00:00:00 2001
From: Antoine Lambert <anlambert@softwareheritage.org>
Date: Thu, 14 Oct 2021 16:55:37 +0200
Subject: [PATCH] api/origin_save: Do not fetch savable visit types when
 running tests

As this is done through a decorator to replace a variable in a docstring,
it has the side effect to call swh-scheduler API when importing the module.

This is not required when running tests so do not fetch that list of
visit types in that case.
---
 swh/web/api/views/origin_save.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/swh/web/api/views/origin_save.py b/swh/web/api/views/origin_save.py
index 19a18bac8..7be7c01f6 100644
--- a/swh/web/api/views/origin_save.py
+++ b/swh/web/api/views/origin_save.py
@@ -3,6 +3,8 @@
 # License: GNU Affero General Public License version 3, or any later version
 # See top-level LICENSE file for more information
 
+import os
+
 from swh.web.api.apidoc import api_doc, format_docstring
 from swh.web.api.apiurls import api_route
 from swh.web.auth.utils import (
@@ -18,11 +20,13 @@ from swh.web.common.origin_save import (
 
 
 def _savable_visit_types():
-    visit_types = sorted(get_savable_visit_types())
     docstring = ""
-    for visit_type in visit_types[:-1]:
-        docstring += f"**{visit_type}**, "
-    docstring += f"and **{visit_types[-1]}**"
+    if os.environ.get("DJANGO_SETTINGS_MODULE") != "swh.web.settings.tests":
+        visit_types = sorted(get_savable_visit_types())
+        docstring = ""
+        for visit_type in visit_types[:-1]:
+            docstring += f"**{visit_type}**, "
+        docstring += f"and **{visit_types[-1]}**"
     return docstring
 
 
-- 
GitLab