Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/conftest.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019-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 os | import os | ||||
import base64 | import base64 | ||||
import pytest | import pytest | ||||
import psycopg2 | import psycopg2 | ||||
from django.urls import reverse | from django.urls import reverse | ||||
from django.test.utils import setup_databases # type: ignore | from django.test.utils import setup_databases # type: ignore | ||||
# mypy is asked to ignore the import statement above because setup_databases | # mypy is asked to ignore the import statement above because setup_databases | ||||
# is not part of the d.t.utils.__all__ variable. | # is not part of the d.t.utils.__all__ variable. | ||||
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT | from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT | ||||
from rest_framework import status | from rest_framework import status | ||||
from rest_framework.test import APIClient | from rest_framework.test import APIClient | ||||
from typing import Mapping | from typing import Mapping | ||||
from swh.scheduler import get_scheduler | from swh.scheduler import get_scheduler | ||||
from swh.scheduler.tests.conftest import * # noqa | from swh.scheduler.tests.conftest import * # noqa | ||||
from swh.model.identifiers import DIRECTORY, persistent_identifier, REVISION, SNAPSHOT | |||||
from swh.deposit.config import setup_django_for | from swh.deposit.config import setup_django_for | ||||
from swh.deposit.parsers import parse_xml | from swh.deposit.parsers import parse_xml | ||||
from swh.deposit.config import SWHDefaultConfig | from swh.deposit.config import SWHDefaultConfig | ||||
from swh.deposit.config import ( | from swh.deposit.config import ( | ||||
COL_IRI, | COL_IRI, | ||||
EDIT_SE_IRI, | EDIT_SE_IRI, | ||||
DEPOSIT_STATUS_DEPOSITED, | DEPOSIT_STATUS_DEPOSITED, | ||||
DEPOSIT_STATUS_REJECTED, | DEPOSIT_STATUS_REJECTED, | ||||
▲ Show 20 Lines • Show All 366 Lines • ▼ Show 20 Lines | def complete_deposit(sample_archive, deposit_collection, authenticated_client): | ||||
""" | """ | ||||
deposit = create_deposit( | deposit = create_deposit( | ||||
authenticated_client, | authenticated_client, | ||||
deposit_collection.name, | deposit_collection.name, | ||||
sample_archive, | sample_archive, | ||||
external_id="external-id-complete", | external_id="external-id-complete", | ||||
deposit_status=DEPOSIT_STATUS_LOAD_SUCCESS, | deposit_status=DEPOSIT_STATUS_LOAD_SUCCESS, | ||||
) | ) | ||||
_swh_id_context = "https://hal.archives-ouvertes.fr/hal-01727745" | origin = "https://hal.archives-ouvertes.fr/hal-01727745" | ||||
deposit.swh_id = "swh:1:dir:42a13fc721c8716ff695d0d62fc851d641f3a12b" | directory_id = "42a13fc721c8716ff695d0d62fc851d641f3a12b" | ||||
deposit.swh_id_context = "%s;%s" % (deposit.swh_id, _swh_id_context) | revision_id = "548b3c0a2bb43e1fca191e24b5803ff6b3bc7c10" | ||||
deposit.swh_anchor_id = "swh:rev:1:548b3c0a2bb43e1fca191e24b5803ff6b3bc7c10" | snapshot_id = "e5e82d064a9c3df7464223042e0c55d72ccff7f0" | ||||
deposit.swh_anchor_id_context = "%s;%s" % (deposit.swh_anchor_id, _swh_id_context) | deposit.swh_id = persistent_identifier(DIRECTORY, directory_id) | ||||
deposit.swh_id_context = persistent_identifier( | |||||
DIRECTORY, | |||||
directory_id, | |||||
metadata={ | |||||
"origin": origin, | |||||
"visit": persistent_identifier(SNAPSHOT, snapshot_id), | |||||
"anchor": persistent_identifier(REVISION, revision_id), | |||||
"path": "/", | |||||
}, | |||||
) | |||||
deposit.save() | deposit.save() | ||||
return deposit | return deposit | ||||
@pytest.fixture() | @pytest.fixture() | ||||
def tmp_path(tmp_path): | def tmp_path(tmp_path): | ||||
return str(tmp_path) # issue with oldstable's pytest version | return str(tmp_path) # issue with oldstable's pytest version |