Changeset View
Changeset View
Standalone View
Standalone View
swh/icinga_plugins/tests/test_deposit.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import io | import io | ||||
import os | import os | ||||
import tarfile | import tarfile | ||||
import time | import time | ||||
from typing import Optional | from typing import Optional | ||||
from click.testing import CliRunner | |||||
import pytest | import pytest | ||||
from swh.icinga_plugins.cli import icinga_cli_group | from swh.icinga_plugins.tests.utils import invoke | ||||
from .web_scenario import WebScenario | from .web_scenario import WebScenario | ||||
BASE_URL = "http://swh-deposit.example.org/1" | BASE_URL = "http://swh-deposit.example.org/1" | ||||
COMMON_OPTIONS = [ | COMMON_OPTIONS = [ | ||||
"--server", | "--server", | ||||
BASE_URL, | BASE_URL, | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | def sample_archive(tmp_path): | ||||
path = os.path.join(tmp_path, "archive.tar.gz") | path = os.path.join(tmp_path, "archive.tar.gz") | ||||
with tarfile.open(path, "w:gz") as tf: | with tarfile.open(path, "w:gz") as tf: | ||||
tf.addfile(tarfile.TarInfo("hello.py"), io.BytesIO(b'print("Hello world")')) | tf.addfile(tarfile.TarInfo("hello.py"), io.BytesIO(b'print("Hello world")')) | ||||
return path | return path | ||||
def invoke(args, catch_exceptions=False): | |||||
runner = CliRunner() | |||||
result = runner.invoke(icinga_cli_group, args) | |||||
if not catch_exceptions and result.exception: | |||||
print(result.output) | |||||
raise result.exception | |||||
return result | |||||
def test_deposit_immediate_success( | def test_deposit_immediate_success( | ||||
requests_mock, mocker, sample_archive, sample_metadata, mocked_time | requests_mock, mocker, sample_archive, sample_metadata, mocked_time | ||||
): | ): | ||||
"""Both deposit creation and deposit metadata update passed without delays | """Both deposit creation and deposit metadata update passed without delays | ||||
""" | """ | ||||
scenario = WebScenario() | scenario = WebScenario() | ||||
▲ Show 20 Lines • Show All 444 Lines • Show Last 20 Lines |