Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/loader/test_client.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-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 json | import json | ||||
import os | import os | ||||
from typing import Any, Callable, Optional | from typing import Any, Callable, Optional | ||||
from urllib.parse import urlparse | from urllib.parse import urlparse | ||||
import pytest | import pytest | ||||
from requests import Session | |||||
from swh.deposit.client import PrivateApiDepositClient | from swh.deposit.client import PrivateApiDepositClient | ||||
from swh.deposit.config import DEPOSIT_STATUS_LOAD_FAILURE, DEPOSIT_STATUS_LOAD_SUCCESS | from swh.deposit.config import DEPOSIT_STATUS_LOAD_FAILURE, DEPOSIT_STATUS_LOAD_SUCCESS | ||||
CLIENT_TEST_CONFIG = { | CLIENT_TEST_CONFIG = { | ||||
"url": "https://nowhere.org/", | "url": "https://nowhere.org/", | ||||
"auth": {}, # no authentication in test scenario | "auth": {}, # no authentication in test scenario | ||||
} | } | ||||
▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | |||||
# private api update status | # private api update status | ||||
def test_status_update(mocker): | def test_status_update(mocker): | ||||
"""Update status | """Update status | ||||
""" | """ | ||||
mocked_put = mocker.patch("swh.deposit.client.requests.put") | mocked_put = mocker.patch.object(Session, "request") | ||||
deposit_client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) | deposit_client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) | ||||
deposit_client.status_update( | deposit_client.status_update( | ||||
"/update/status", DEPOSIT_STATUS_LOAD_SUCCESS, revision_id="some-revision-id", | "/update/status", DEPOSIT_STATUS_LOAD_SUCCESS, revision_id="some-revision-id", | ||||
) | ) | ||||
mocked_put.assert_called_once_with( | mocked_put.assert_called_once_with( | ||||
"put", | |||||
"https://nowhere.org/update/status", | "https://nowhere.org/update/status", | ||||
json={ | json={ | ||||
"status": DEPOSIT_STATUS_LOAD_SUCCESS, | "status": DEPOSIT_STATUS_LOAD_SUCCESS, | ||||
"revision_id": "some-revision-id", | "revision_id": "some-revision-id", | ||||
}, | }, | ||||
) | ) | ||||
def test_status_update_with_no_revision_id(mocker): | def test_status_update_with_no_revision_id(mocker): | ||||
"""Reading metadata can fail for some reasons | """Reading metadata can fail for some reasons | ||||
""" | """ | ||||
mocked_put = mocker.patch("swh.deposit.client.requests.put") | mocked_put = mocker.patch.object(Session, "request") | ||||
deposit_client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) | deposit_client = PrivateApiDepositClient(config=CLIENT_TEST_CONFIG) | ||||
deposit_client.status_update("/update/status/fail", DEPOSIT_STATUS_LOAD_FAILURE) | deposit_client.status_update("/update/status/fail", DEPOSIT_STATUS_LOAD_FAILURE) | ||||
mocked_put.assert_called_once_with( | mocked_put.assert_called_once_with( | ||||
"put", | |||||
"https://nowhere.org/update/status/fail", | "https://nowhere.org/update/status/fail", | ||||
json={"status": DEPOSIT_STATUS_LOAD_FAILURE,}, | json={"status": DEPOSIT_STATUS_LOAD_FAILURE,}, | ||||
) | ) |