diff --git a/mypy.ini b/mypy.ini index 34ca4f4..d32ccd2 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,39 +1,42 @@ [mypy] namespace_packages = True warn_unused_ignores = True # support for sqlalchemy magic: see https://github.com/dropbox/sqlalchemy-stubs plugins = sqlmypy # 3rd party libraries without stubs (yet) [mypy-bs4.*] ignore_missing_imports = True [mypy-celery.*] ignore_missing_imports = True [mypy-debian.*] ignore_missing_imports = True [mypy-iso8601.*] ignore_missing_imports = True [mypy-pkg_resources.*] ignore_missing_imports = True [mypy-pytest.*] ignore_missing_imports = True +[mypy-pytest_postgresql.*] +ignore_missing_imports = True + [mypy-requests_mock.*] ignore_missing_imports = True [mypy-testing.postgresql.*] ignore_missing_imports = True [mypy-urllib3.util.*] ignore_missing_imports = True [mypy-xmltodict.*] ignore_missing_imports = True diff --git a/swh/lister/debian/tests/conftest.py b/swh/lister/debian/tests/conftest.py index a479ed1..42a9ab3 100644 --- a/swh/lister/debian/tests/conftest.py +++ b/swh/lister/debian/tests/conftest.py @@ -1,30 +1,60 @@ # Copyright (C) 2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import pytest -from swh.lister.core.tests.conftest import * # noqa +from pytest_postgresql.janitor import DatabaseJanitor +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker +from swh.lister.core.tests.conftest import * # noqa +from swh.lister.core.models import SQLBase from swh.lister.debian import debian_init @pytest.fixture def lister_debian(swh_listers): lister = swh_listers['debian'] # Initialize the debian data model debian_init(lister.db_engine, distributions=['stretch'], area_names=['main', 'contrib']) # Add the load-deb-package in the scheduler backend lister.scheduler.create_task_type({ 'type': 'load-deb-package', 'description': 'Load a Debian package', 'backend_name': 'swh.loader.debian.tasks.LoaderDebianPackage', 'default_interval': '1 day', }) return lister + + +@pytest.fixture +def sqlalchemy_engine(postgresql_proc): + pg_host = postgresql_proc.host + pg_port = postgresql_proc.port + pg_user = postgresql_proc.user + + pg_db = 'sqlalchemy-tests' + + url = f'postgresql://{pg_user}@{pg_host}:{pg_port}/{pg_db}' + with DatabaseJanitor( + pg_user, pg_host, pg_port, pg_db, postgresql_proc.version + ): + engine = create_engine(url) + yield engine + engine.dispose() + + +@pytest.fixture +def session(sqlalchemy_engine): + SQLBase.metadata.create_all(sqlalchemy_engine) + Session = sessionmaker(bind=sqlalchemy_engine) + session = Session() + yield session + session.close() diff --git a/swh/lister/debian/tests/test_models.py b/swh/lister/debian/tests/test_models.py new file mode 100644 index 0000000..701d573 --- /dev/null +++ b/swh/lister/debian/tests/test_models.py @@ -0,0 +1,41 @@ +# Copyright (C) 2019 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import pytest + +from swh.lister.debian.models import Distribution, Area + + +def test_area_index_uris_deb(session): + d = Distribution( + name='Debian', type='deb', mirror_uri='http://deb.debian.org/debian' + ) + a = Area( + distribution=d, + name='unstable/main', + active=True, + ) + session.add_all([d, a]) + session.commit() + + uris = list(a.index_uris()) + assert uris + + +def test_area_index_uris_rpm(session): + d = Distribution( + name='CentOS', type='rpm', + mirror_uri='http://centos.mirrors.proxad.net/' + ) + a = Area( + distribution=d, + name='8', + active=True, + ) + session.add_all([d, a]) + session.commit() + + with pytest.raises(NotImplementedError): + list(a.index_uris())