Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/conftest.py
# Copyright (C) 2019-2020 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 base64 | import base64 | ||||
from functools import partial | |||||
import os | import os | ||||
import re | |||||
from typing import Mapping | from typing import Mapping | ||||
from django.test.utils import setup_databases # type: ignore | from django.test.utils import setup_databases # type: ignore | ||||
from django.urls import reverse | from django.urls import reverse | ||||
import psycopg2 | import psycopg2 | ||||
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT | from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT | ||||
import pytest | import pytest | ||||
from rest_framework import status | from rest_framework import status | ||||
from rest_framework.test import APIClient | from rest_framework.test import APIClient | ||||
import yaml | import yaml | ||||
from swh.core.config import read | from swh.core.config import read | ||||
from swh.core.pytest_plugin import get_response_cb | |||||
from swh.deposit.config import ( | from swh.deposit.config import ( | ||||
COL_IRI, | COL_IRI, | ||||
DEPOSIT_STATUS_DEPOSITED, | DEPOSIT_STATUS_DEPOSITED, | ||||
DEPOSIT_STATUS_LOAD_FAILURE, | DEPOSIT_STATUS_LOAD_FAILURE, | ||||
DEPOSIT_STATUS_LOAD_SUCCESS, | DEPOSIT_STATUS_LOAD_SUCCESS, | ||||
DEPOSIT_STATUS_PARTIAL, | DEPOSIT_STATUS_PARTIAL, | ||||
DEPOSIT_STATUS_REJECTED, | DEPOSIT_STATUS_REJECTED, | ||||
DEPOSIT_STATUS_VERIFIED, | DEPOSIT_STATUS_VERIFIED, | ||||
Show All 18 Lines | TEST_USER = { | ||||
"collection": {"name": "test"}, | "collection": {"name": "test"}, | ||||
} | } | ||||
def pytest_configure(): | def pytest_configure(): | ||||
setup_django_for("testing") | setup_django_for("testing") | ||||
@pytest.fixture | |||||
def requests_mock_datadir(datadir, requests_mock_datadir): | |||||
"""Override default behavior to deal with put/post methods | |||||
""" | |||||
cb = partial(get_response_cb, datadir=datadir) | |||||
requests_mock_datadir.put(re.compile("https://"), body=cb) | |||||
requests_mock_datadir.post(re.compile("https://"), body=cb) | |||||
return requests_mock_datadir | |||||
@pytest.fixture() | @pytest.fixture() | ||||
def deposit_config(swh_scheduler_config, swh_storage_backend_config): | def deposit_config(swh_scheduler_config, swh_storage_backend_config): | ||||
return { | return { | ||||
"max_upload_size": 500, | "max_upload_size": 500, | ||||
"extraction_dir": "/tmp/swh-deposit/test/extraction-dir", | "extraction_dir": "/tmp/swh-deposit/test/extraction-dir", | ||||
"checks": False, | "checks": False, | ||||
"scheduler": {"cls": "local", "args": swh_scheduler_config,}, | "scheduler": {"cls": "local", "args": swh_scheduler_config,}, | ||||
"storage_metadata": swh_storage_backend_config, | "storage_metadata": swh_storage_backend_config, | ||||
▲ Show 20 Lines • Show All 357 Lines • Show Last 20 Lines |