Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/core/tests/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 | ||||
from swh.scheduler.tests.conftest import * # noqa | from swh.scheduler.tests.conftest import * # noqa | ||||
import logging | import logging | ||||
import pytest | import pytest | ||||
from sqlalchemy import create_engine | from sqlalchemy import create_engine | ||||
from swh.lister import get_lister, SUPPORTED_LISTERS | from swh.lister import get_lister, SUPPORTED_LISTERS | ||||
from swh.lister.core.models import initialize | from swh.lister.core.models import initialize | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_listers(request, postgresql_proc, postgresql, swh_scheduler): | def lister_db_url(postgresql_proc, postgresql): | ||||
db_url = 'postgresql://{user}@{host}:{port}/{dbname}'.format( | db_url = 'postgresql://{user}@{host}:{port}/{dbname}'.format( | ||||
host=postgresql_proc.host, | host=postgresql_proc.host, | ||||
port=postgresql_proc.port, | port=postgresql_proc.port, | ||||
user='postgres', | user='postgres', | ||||
dbname='tests') | dbname='tests') | ||||
logger.debug('lister db_url: %s', db_url) | logger.debug('lister db_url: %s', db_url) | ||||
return db_url | |||||
@pytest.fixture | |||||
def swh_listers(request, lister_db_url, swh_scheduler): | |||||
listers = {} | listers = {} | ||||
# Prepare schema for all listers | # Prepare schema for all listers | ||||
for lister_name in SUPPORTED_LISTERS: | for lister_name in SUPPORTED_LISTERS: | ||||
lister = get_lister(lister_name, db_url=db_url) | lister = get_lister(lister_name, db_url=lister_db_url) | ||||
lister.scheduler = swh_scheduler # inject scheduler fixture | lister.scheduler = swh_scheduler # inject scheduler fixture | ||||
listers[lister_name] = lister | listers[lister_name] = lister | ||||
initialize(create_engine(db_url), drop_tables=True) | initialize(create_engine(lister_db_url), drop_tables=True) | ||||
# Add the load-archive-files expected by some listers (gnu, cran, ...) | # Add the load-archive-files expected by some listers (gnu, cran, ...) | ||||
swh_scheduler.create_task_type({ | swh_scheduler.create_task_type({ | ||||
'type': 'load-archive-files', | 'type': 'load-archive-files', | ||||
'description': 'Load archive files.', | 'description': 'Load archive files.', | ||||
'backend_name': 'swh.loader.package.tasks.LoadArchive', | 'backend_name': 'swh.loader.package.tasks.LoadArchive', | ||||
'default_interval': '1 day', | 'default_interval': '1 day', | ||||
}) | }) | ||||
return listers | return listers |