Changeset View
Changeset View
Standalone View
Standalone View
swh/icinga_plugins/tests/test_save_code_now.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021-2022 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 | ||||
from datetime import datetime, timezone | from datetime import datetime, timezone | ||||
import random | import random | ||||
from typing import Dict, Optional, Tuple | from typing import Dict, Optional, Tuple | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | def test_save_code_now_success(requests_mock, mocker, mocked_time, origin_info): | ||||
scenario.add_step( | scenario.add_step( | ||||
"get", api_url, [fake_response(origin, visit_type, "accepted", "succeeded")] | "get", api_url, [fake_response(origin, visit_type, "accepted", "succeeded")] | ||||
) | ) | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
# fmt: off | # fmt: off | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"--prometheus-exporter", | |||||
"--prometheus-exporter-directory", "/tmp", | |||||
"check-savecodenow", "--swh-web-url", root_api_url, | "check-savecodenow", "--swh-web-url", root_api_url, | ||||
"origin", origin, | "origin", origin, | ||||
"--visit-type", visit_type, | "--visit-type", visit_type, | ||||
] | ] | ||||
) | ) | ||||
# fmt: on | # fmt: on | ||||
assert result.output == ( | assert result.output == ( | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | for i in range(13): | ||||
origin, visit_type, "accepted", waiting_status | origin, visit_type, "accepted", waiting_status | ||||
) | ) | ||||
scenario.add_step("get", api_url, [response_scheduled]) | scenario.add_step("get", api_url, [response_scheduled]) | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
# fmt: off | # fmt: off | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"check-savecodenow", "--swh-web-url", root_api_url, | "check-savecodenow", | ||||
"--swh-web-url", root_api_url, | |||||
"origin", origin, | "origin", origin, | ||||
"--visit-type", visit_type, | "--visit-type", visit_type, | ||||
], | ], | ||||
catch_exceptions=True, | catch_exceptions=True, | ||||
) | ) | ||||
# fmt: on | # fmt: on | ||||
assert result.output == ( | assert result.output == ( | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |