Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/cli/test_client.py
| # Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2020 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 ast | import ast | ||||
| import contextlib | import contextlib | ||||
| import json | import json | ||||
| import logging | import logging | ||||
| import os | import os | ||||
| from unittest.mock import MagicMock | from unittest.mock import MagicMock | ||||
| from click.testing import CliRunner | |||||
| import pytest | import pytest | ||||
| import yaml | import yaml | ||||
| from swh.deposit.cli import deposit as cli | from swh.deposit.cli import deposit as cli | ||||
| from swh.deposit.cli.client import InputError, _client, _collection, _url, generate_slug | from swh.deposit.cli.client import InputError, _client, _collection, _url, generate_slug | ||||
| from swh.deposit.client import MaintenanceError, PublicApiDepositClient | from swh.deposit.client import MaintenanceError, PublicApiDepositClient | ||||
| from swh.deposit.parsers import parse_xml | from swh.deposit.parsers import parse_xml | ||||
| Show All 24 Lines | def patched_tmp_path(tmp_path, mocker): | ||||
| mocker.patch( | mocker.patch( | ||||
| "tempfile.TemporaryDirectory", | "tempfile.TemporaryDirectory", | ||||
| return_value=contextlib.nullcontext(str(tmp_path)), | return_value=contextlib.nullcontext(str(tmp_path)), | ||||
| ) | ) | ||||
| return tmp_path | return tmp_path | ||||
| @pytest.fixture | @pytest.fixture | ||||
| def cli_runner(): | |||||
| return CliRunner() | |||||
| @pytest.fixture | |||||
| def client_mock_api_down(mocker, slug): | def client_mock_api_down(mocker, slug): | ||||
| """A mock client whose connection with api fails due to maintenance issue | """A mock client whose connection with api fails due to maintenance issue | ||||
| """ | """ | ||||
| mock_client = MagicMock() | mock_client = MagicMock() | ||||
| mocker.patch("swh.deposit.cli.client._client", return_value=mock_client) | mocker.patch("swh.deposit.cli.client._client", return_value=mock_client) | ||||
| mock_client.service_document.side_effect = MaintenanceError( | mock_client.service_document.side_effect = MaintenanceError( | ||||
| "Database backend maintenance: Temporarily unavailable, try again later." | "Database backend maintenance: Temporarily unavailable, try again later." | ||||
| ▲ Show 20 Lines • Show All 657 Lines • Show Last 20 Lines | |||||