Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/conftest.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 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 hashlib | import hashlib | ||||
import pytest | import pytest | ||||
from django.urls import reverse | from django.urls import reverse | ||||
from os import path, listdir | |||||
from typing import Mapping | |||||
from swh.deposit.config import ( | from swh.deposit.config import ( | ||||
DEPOSIT_STATUS_DEPOSITED, COL_IRI, DEPOSIT_STATUS_VERIFIED | DEPOSIT_STATUS_DEPOSITED, COL_IRI, DEPOSIT_STATUS_VERIFIED | ||||
) | ) | ||||
from swh.deposit.models import Deposit | from swh.deposit.models import Deposit | ||||
from swh.deposit.parsers import parse_xml | from swh.deposit.parsers import parse_xml | ||||
from swh.deposit.api.private.deposit_check import SWHChecksDeposit | from swh.deposit.api.private.deposit_check import SWHChecksDeposit | ||||
@pytest.fixture | @pytest.fixture | ||||
def atom_dataset(datadir) -> Mapping[str, bytes]: | |||||
"""Compute the paths to atom files. | |||||
Returns: | |||||
Dict of atom name per content (bytes) | |||||
""" | |||||
atom_path = path.join(datadir, 'atom') | |||||
data = {} | |||||
for filename in listdir(atom_path): | |||||
filepath = path.join(atom_path, filename) | |||||
with open(filepath, 'rb') as f: | |||||
raw_content = f.read() | |||||
# Keep the filename without extension | |||||
atom_name = filename.split('.')[0] | |||||
data[atom_name] = raw_content | |||||
return data | |||||
@pytest.fixture | |||||
def ready_deposit_ok(partial_deposit_with_metadata): | def ready_deposit_ok(partial_deposit_with_metadata): | ||||
"""Returns a deposit ready for checks (it will pass the checks). | """Returns a deposit ready for checks (it will pass the checks). | ||||
""" | """ | ||||
deposit = partial_deposit_with_metadata | deposit = partial_deposit_with_metadata | ||||
deposit.status = DEPOSIT_STATUS_DEPOSITED | deposit.status = DEPOSIT_STATUS_DEPOSITED | ||||
deposit.save() | deposit.save() | ||||
return deposit | return deposit | ||||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |