Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/pytest_plugin.py
Show All 17 Lines | |||||
SQL_DIR = path.join(path.dirname(swh.storage.__file__), "sql") | SQL_DIR = path.join(path.dirname(swh.storage.__file__), "sql") | ||||
environ["LC_ALL"] = "C.UTF-8" | environ["LC_ALL"] = "C.UTF-8" | ||||
DUMP_FILES = path.join(SQL_DIR, "*.sql") | DUMP_FILES = path.join(SQL_DIR, "*.sql") | ||||
@pytest.fixture | |||||
def swh_storage_backend_config(swh_storage_postgresql): | |||||
"""Basic pg storage configuration with no journal collaborator | |||||
(to avoid pulling optional dependency on clients of this fixture) | |||||
""" | |||||
yield { | |||||
"cls": "local", | |||||
"db": swh_storage_postgresql.dsn, | |||||
"objstorage": {"cls": "memory", "args": {}}, | |||||
"check_config": {"check_write": True}, | |||||
} | |||||
@pytest.fixture | |||||
def swh_storage(swh_storage_backend_config): | |||||
return get_storage(**swh_storage_backend_config) | |||||
# the postgres_fact factory fixture below is mostly a copy of the code | # the postgres_fact factory fixture below is mostly a copy of the code | ||||
# from pytest-postgresql. We need a custom version here to be able to | # from pytest-postgresql. We need a custom version here to be able to | ||||
# specify our version of the DBJanitor we use. | # specify our version of the DBJanitor we use. | ||||
def postgresql_fact(process_fixture_name, db_name=None, dump_files=DUMP_FILES): | def postgresql_fact(process_fixture_name, db_name=None, dump_files=DUMP_FILES): | ||||
@pytest.fixture | @pytest.fixture | ||||
def postgresql_factory(request): | def postgresql_factory(request): | ||||
""" | """ | ||||
Fixture factory for PostgreSQL. | Fixture factory for PostgreSQL. | ||||
Show All 32 Lines | def postgresql_factory(request): | ||||
connection.close() | connection.close() | ||||
return postgresql_factory | return postgresql_factory | ||||
swh_storage_postgresql = postgresql_fact("postgresql_proc", db_name="storage") | swh_storage_postgresql = postgresql_fact("postgresql_proc", db_name="storage") | ||||
@pytest.fixture | |||||
def swh_storage_backend_config(swh_storage_postgresql): | |||||
"""Basic pg storage configuration with no journal collaborator | |||||
(to avoid pulling optional dependency on clients of this fixture) | |||||
""" | |||||
yield { | |||||
"cls": "local", | |||||
"db": swh_storage_postgresql.dsn, | |||||
"objstorage": {"cls": "memory", "args": {}}, | |||||
"check_config": {"check_write": True}, | |||||
} | |||||
@pytest.fixture | |||||
def swh_storage(swh_storage_backend_config): | |||||
return get_storage(**swh_storage_backend_config) | |||||
# This version of the DatabaseJanitor implement a different setup/teardown | # This version of the DatabaseJanitor implement a different setup/teardown | ||||
# behavior than than the stock one: instead of dropping, creating and | # behavior than than the stock one: instead of dropping, creating and | ||||
# initializing the database for each test, it create and initialize the db only | # initializing the database for each test, it create and initialize the db only | ||||
# once, then it truncate the tables. This is needed to have acceptable test | # once, then it truncate the tables. This is needed to have acceptable test | ||||
# performances. | # performances. | ||||
class SwhDatabaseJanitor(DatabaseJanitor): | class SwhDatabaseJanitor(DatabaseJanitor): | ||||
def __init__( | def __init__( | ||||
self, | self, | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |