Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/test_utils.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2019 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 pytest | import pytest | ||||
from unittest.mock import patch | from unittest.mock import patch | ||||
from swh.deposit import utils | from swh.deposit import utils | ||||
from swh.deposit.models import Deposit, DepositClient | |||||
def test_origin_url_from(): | |||||
"""With correctly setup-ed deposit, all is fine | |||||
""" | |||||
for provider_url, external_id in ( | |||||
('http://somewhere.org', 'uuid'), | |||||
('http://overthejungle.org', 'diuu'), | |||||
): | |||||
deposit = Deposit( | |||||
client=DepositClient(provider_url=provider_url), | |||||
external_id=external_id | |||||
) | |||||
actual_origin_url = utils.origin_url_from(deposit) | |||||
assert actual_origin_url == '%s/%s' % ( | |||||
provider_url.rstrip('/'), external_id) | |||||
def test_origin_url_from_ko(): | |||||
"""Badly configured deposit should raise | |||||
""" | |||||
for provider_url, external_id in ( | |||||
(None, 'uuid'), | |||||
('http://overthejungle.org', None), | |||||
): | |||||
deposit = Deposit( | |||||
client=DepositClient(provider_url=provider_url), | |||||
external_id=None | |||||
) | |||||
with pytest.raises(AssertionError): | |||||
utils.origin_url_from(deposit) | |||||
def test_merge(): | def test_merge(): | ||||
"""Calling utils.merge on dicts should merge without losing information | """Calling utils.merge on dicts should merge without losing information | ||||
""" | """ | ||||
d0 = { | d0 = { | ||||
'author': 'someone', | 'author': 'someone', | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |