diff --git a/swh/icinga_plugins/tests/test_deposit.py b/swh/icinga_plugins/tests/test_deposit.py
--- a/swh/icinga_plugins/tests/test_deposit.py
+++ b/swh/icinga_plugins/tests/test_deposit.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2019 The Software Heritage developers
+# Copyright (C) 2019-2020 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -7,6 +7,7 @@
import os
import tarfile
import time
+from typing import Optional
from click.testing import CliRunner
import pytest
@@ -63,11 +64,69 @@
xmlns:dcterms="http://purl.org/dc/terms/">
42
{status}
- {status_detail}
+ {status_detail}%s
"""
+def status_template(
+ status: str, status_detail: str = "", swhid: Optional[str] = None
+) -> str:
+ """Generate a proper status template out of status, status_detail and optional swhid
+
+ """
+ if swhid is not None:
+ template = STATUS_TEMPLATE % f"\n {swhid}"
+ return template.format(status=status, status_detail=status_detail, swhid=swhid)
+ template = STATUS_TEMPLATE % ""
+ return template.format(status=status, status_detail=status_detail)
+
+
+def test_status_template():
+ actual_status = status_template(status="deposited")
+ assert (
+ actual_status
+ == """
+
+ 42
+ deposited
+
+
+"""
+ )
+
+ actual_status = status_template(status="verified", status_detail="detail")
+ assert (
+ actual_status
+ == """
+
+ 42
+ verified
+ detail
+
+"""
+ )
+
+ actual_status = status_template(status="done", swhid="10")
+ assert (
+ actual_status
+ == """
+
+ 42
+ done
+
+ 10
+
+"""
+ )
+
+
@pytest.fixture(scope="session")
def tmp_path(tmp_path_factory):
return tmp_path_factory.mktemp(__name__)
@@ -150,19 +209,13 @@
"post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited")
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="verified", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"),
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="loading", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="loading"),
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="done", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="done"),
)
scenario.install_mock(requests_mock)
@@ -198,14 +251,10 @@
"post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited")
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="verified", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"),
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="done", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="done"),
)
scenario.install_mock(requests_mock)
@@ -244,14 +293,12 @@
"post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited")
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="verified", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"),
)
scenario.add_step(
"get",
f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="done", status_detail=""),
+ status_template(status="done"),
callback=lambda: time.sleep(60),
)
@@ -296,13 +343,13 @@
scenario.add_step(
"get",
f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="verified", status_detail=""),
+ status_template(status="verified"),
callback=lambda: time.sleep(1500),
)
scenario.add_step(
"get",
f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="loading", status_detail=""),
+ status_template(status="loading"),
callback=lambda: time.sleep(1500),
)
@@ -342,7 +389,7 @@
scenario.add_step(
"get",
f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="rejected", status_detail="booo"),
+ status_template(status="rejected", status_detail="booo"),
)
scenario.install_mock(requests_mock)
@@ -378,19 +425,15 @@
"post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited")
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="verified", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"),
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="loading", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="loading"),
)
scenario.add_step(
"get",
f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="failed", status_detail="booo"),
+ status_template(status="failed", status_detail="booo"),
)
scenario.install_mock(requests_mock)
@@ -427,19 +470,15 @@
"post", f"{BASE_URL}/testcol/", ENTRY_TEMPLATE.format(status="deposited")
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="verified", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="verified"),
)
scenario.add_step(
- "get",
- f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="loading", status_detail=""),
+ "get", f"{BASE_URL}/testcol/42/status/", status_template(status="loading"),
)
scenario.add_step(
"get",
f"{BASE_URL}/testcol/42/status/",
- STATUS_TEMPLATE.format(status="what", status_detail="booo"),
+ status_template(status="what", status_detail="booo"),
)
scenario.install_mock(requests_mock)