diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,13 @@ *.csv +*.dump *.egg* *.log +*.mypy* *.prof *.zip *.orig *.bak -.coverage +.coverage* .tox .vscode __pycache__ diff --git a/pytest.ini b/pytest.ini --- a/pytest.ini +++ b/pytest.ini @@ -4,3 +4,5 @@ mongodb_fixture_dir = swh/provenance/tests/data/mongo mongodb_engine = mongomock mongodb_dbname = test + +postgresql_postgres_options = -N 500 diff --git a/requirements-test.txt b/requirements-test.txt --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,4 +1,5 @@ pytest pytest-mongodb +pytest-rabbitmq swh.loader.git >= 0.8 swh.journal >= 0.8 diff --git a/swh/provenance/tests/conftest.py b/swh/provenance/tests/conftest.py --- a/swh/provenance/tests/conftest.py +++ b/swh/provenance/tests/conftest.py @@ -44,7 +44,7 @@ return postgresql.get_dsn_parameters() -@pytest.fixture(params=["mongodb", "postgresql"]) +@pytest.fixture(params=["mongodb", "postgresql", "rabbitmq"]) def provenance_storage( request: SubRequest, provenance_postgresqldb: Dict[str, str], @@ -63,6 +63,28 @@ ) as storage: yield storage + elif request.param == "rabbitmq": + from swh.provenance.api.server import ProvenanceStorageRabbitMQServer + + rabbitmq = request.getfixturevalue("rabbitmq") + host = rabbitmq.args["host"] + port = rabbitmq.args["port"] + rabbitmq_params: Dict[str, Any] = { + "url": f"amqp://guest:guest@{host}:{port}/%2f", + "storage_config": { + "cls": "postgresql", # TODO: also test with underlying mongodb storage + "db": provenance_postgresqldb, + "raise_on_commit": True, + }, + } + server = ProvenanceStorageRabbitMQServer( + url=rabbitmq_params["url"], storage_config=rabbitmq_params["storage_config"] + ) + server.start() + with get_provenance_storage(cls=request.param, **rabbitmq_params) as storage: + yield storage + server.stop() + else: # in test sessions, we DO want to raise any exception occurring at commit time with get_provenance_storage( diff --git a/tox.ini b/tox.ini --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=black,flake8,mypy,py3 +envlist = black,flake8,mypy,py3 [testenv] extras = @@ -11,6 +11,7 @@ {envsitepackagesdir}/swh/provenance \ --cov={envsitepackagesdir}/swh/provenance \ --cov-branch {posargs} +passenv = HOME # required by pytest-rabbitmq [testenv:black] skip_install = true