Changeset View
Changeset View
Standalone View
Standalone View
swh/core/db/tests/conftest.py
# Copyright (C) 2019-2022 The Software Heritage developers | # Copyright (C) 2019-2022 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 | ||||
from click.testing import CliRunner | from click.testing import CliRunner | ||||
from hypothesis import HealthCheck | from hypothesis import HealthCheck | ||||
import psycopg2 | |||||
import pytest | import pytest | ||||
from pytest_postgresql import factories | |||||
from swh.core.db.db_utils import import_swhmodule | from swh.core.db.db_utils import import_swhmodule | ||||
os.environ["LC_ALL"] = "C.UTF-8" | os.environ["LC_ALL"] = "C.UTF-8" | ||||
# we use getattr here to keep mypy happy regardless hypothesis version | # we use getattr here to keep mypy happy regardless hypothesis version | ||||
function_scoped_fixture_check = ( | function_scoped_fixture_check = ( | ||||
[getattr(HealthCheck, "function_scoped_fixture")] | [getattr(HealthCheck, "function_scoped_fixture")] | ||||
if hasattr(HealthCheck, "function_scoped_fixture") | if hasattr(HealthCheck, "function_scoped_fixture") | ||||
else [] | else [] | ||||
) | ) | ||||
def create_role_guest(**kwargs): | |||||
with psycopg2.connect(**kwargs) as conn: | |||||
with conn.cursor() as cur: | |||||
cur.execute("CREATE ROLE guest LOGIN PASSWORD 'guest'") | |||||
postgresql_proc = factories.postgresql_proc( | |||||
load=[create_role_guest], | |||||
) | |||||
@pytest.fixture | @pytest.fixture | ||||
def cli_runner(): | def cli_runner(): | ||||
return CliRunner() | return CliRunner() | ||||
@pytest.fixture() | @pytest.fixture() | ||||
def mock_import_swhmodule(mocker, datadir): | def mock_import_swhmodule(mocker, datadir): | ||||
"""This bypasses the module manipulation to make import_swhmodule return a mock | """This bypasses the module manipulation to make import_swhmodule return a mock | ||||
Show All 36 Lines |