Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/cli/test_client.py
Show All 18 Lines | |||||
from ..conftest import TEST_USER | from ..conftest import TEST_USER | ||||
EXAMPLE_SERVICE_DOCUMENT = { | EXAMPLE_SERVICE_DOCUMENT = { | ||||
"service": {"workspace": {"collection": {"sword:name": "softcol",}}} | "service": {"workspace": {"collection": {"sword:name": "softcol",}}} | ||||
} | } | ||||
@pytest.fixture | @pytest.fixture | ||||
def deposit_config(): | |||||
return { | |||||
"url": "https://deposit.swh.test/1", | |||||
"auth": {"username": "test", "password": "test",}, | |||||
} | |||||
@pytest.fixture | |||||
def datadir(request): | def datadir(request): | ||||
"""Override default datadir to target main test datadir""" | """Override default datadir to target main test datadir""" | ||||
return os.path.join(os.path.dirname(str(request.fspath)), "../data") | return os.path.join(os.path.dirname(str(request.fspath)), "../data") | ||||
ardumont: > It took me too much time to boostrap this...
got bitten by the `../data` ¯\_(ツ)_/¯
| |||||
@pytest.fixture | @pytest.fixture | ||||
def slug(): | def slug(): | ||||
return generate_slug() | return generate_slug() | ||||
@pytest.fixture | @pytest.fixture | ||||
Show All 38 Lines | def test_collection_error(): | ||||
mock_client.service_document.return_value = {"error": "something went wrong"} | mock_client.service_document.return_value = {"error": "something went wrong"} | ||||
with pytest.raises(InputError) as e: | with pytest.raises(InputError) as e: | ||||
_collection(mock_client) | _collection(mock_client) | ||||
assert "Service document retrieval: something went wrong" == str(e.value) | assert "Service document retrieval: something went wrong" == str(e.value) | ||||
def test_collection_ok(): | def test_collection_ok(deposit_config, requests_mock_datadir): | ||||
mock_client = MagicMock() | client = PublicApiDepositClient(deposit_config) | ||||
mock_client.service_document.return_value = EXAMPLE_SERVICE_DOCUMENT | collection_name = _collection(client) | ||||
collection_name = _collection(mock_client) | assert collection_name == "test" | ||||
assert collection_name == "softcol" | |||||
def test_collection_ko_because_downtime(): | def test_collection_ko_because_downtime(): | ||||
mock_client = MagicMock() | mock_client = MagicMock() | ||||
mock_client.service_document.side_effect = MaintenanceError("downtime") | mock_client.service_document.side_effect = MaintenanceError("downtime") | ||||
with pytest.raises(MaintenanceError, match="downtime"): | with pytest.raises(MaintenanceError, match="downtime"): | ||||
_collection(mock_client) | _collection(mock_client) | ||||
▲ Show 20 Lines • Show All 366 Lines • Show Last 20 Lines |
got bitten by the ../data ¯\_(ツ)_/¯