diff --git a/swh/storage/tests/schemata/__init__.py b/swh/storage/tests/schemata/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/swh/storage/tests/schemata/conftest.py b/swh/storage/tests/schemata/conftest.py new file mode 100644 index 0000000..5cfa8ae --- /dev/null +++ b/swh/storage/tests/schemata/conftest.py @@ -0,0 +1,25 @@ +# 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 pytest_postgresql.janitor import DatabaseJanitor +from sqlalchemy import create_engine + + +@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() diff --git a/swh/storage/tests/schemata/test_distribution.py b/swh/storage/tests/schemata/test_distribution.py new file mode 100644 index 0000000..8c90c3e --- /dev/null +++ b/swh/storage/tests/schemata/test_distribution.py @@ -0,0 +1,51 @@ +# 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.storage.schemata.distribution import SQLBase, Distribution, Area + +from sqlalchemy.orm import sessionmaker + + +@pytest.fixture +def session(sqlalchemy_engine): + SQLBase.metadata.create_all(sqlalchemy_engine) + Session = sessionmaker(bind=sqlalchemy_engine) + session = Session() + yield session + session.close() + + +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()) diff --git a/tox.ini b/tox.ini index 4cca042..d719433 100644 --- a/tox.ini +++ b/tox.ini @@ -1,39 +1,41 @@ [tox] envlist=flake8,mypy,py3 [testenv:py3] deps = .[testing] .[listener] + .[schemata] pytest-cov commands = pytest --hypothesis-profile=fast \ --cov={envsitepackagesdir}/swh/storage \ {envsitepackagesdir}/swh/storage \ --cov-branch {posargs} [testenv:py3-slow] deps = .[testing] .[listener] + .[schemata] pytest-cov commands = pytest --hypothesis-profile=slow \ --cov={envsitepackagesdir}/swh/storage \ {envsitepackagesdir}/swh/storage \ --cov-branch {posargs} [testenv:flake8] skip_install = true deps = flake8 commands = {envpython} -m flake8 [testenv:mypy] skip_install = true deps = .[testing] mypy commands = mypy swh