Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/tests/conftest.py
Show All 38 Lines | ) -> Dict[str, str]: | ||||
from swh.core.cli.db import populate_database_for_package | from swh.core.cli.db import populate_database_for_package | ||||
populate_database_for_package( | populate_database_for_package( | ||||
"swh.provenance", postgresql.dsn, flavor=request.param | "swh.provenance", postgresql.dsn, flavor=request.param | ||||
) | ) | ||||
return postgresql.get_dsn_parameters() | return postgresql.get_dsn_parameters() | ||||
@pytest.fixture(params=["mongodb", "postgresql"]) | @pytest.fixture(params=["mongodb", "postgresql", "rabbitmq"]) | ||||
def provenance_storage( | def provenance_storage( | ||||
request: SubRequest, | request: SubRequest, | ||||
provenance_postgresqldb: Dict[str, str], | provenance_postgresqldb: Dict[str, str], | ||||
mongodb: mongomock.database.Database, | mongodb: mongomock.database.Database, | ||||
) -> Generator[ProvenanceStorageInterface, None, None]: | ) -> Generator[ProvenanceStorageInterface, None, None]: | ||||
"""Return a working and initialized ProvenanceStorageInterface object""" | """Return a working and initialized ProvenanceStorageInterface object""" | ||||
if request.param == "mongodb": | if request.param == "mongodb": | ||||
mongodb_params = { | mongodb_params = { | ||||
"host": mongodb.client.address[0], | "host": mongodb.client.address[0], | ||||
"port": mongodb.client.address[1], | "port": mongodb.client.address[1], | ||||
"dbname": mongodb.name, | "dbname": mongodb.name, | ||||
} | } | ||||
with get_provenance_storage( | with get_provenance_storage( | ||||
cls=request.param, db=mongodb_params, engine="mongomock" | cls=request.param, db=mongodb_params, engine="mongomock" | ||||
) as storage: | ) as storage: | ||||
yield storage | yield storage | ||||
elif request.param == "rabbitmq": | |||||
from swh.provenance.api.server import ProvenanceStorageRabbitMQServer | |||||
rabbitmq = request.getfixturevalue("rabbitmq") | |||||
host = rabbitmq.args["host"] | |||||
douardda: what's the `%2f` doing here? | |||||
Done Inline Actionsis the virtual host to connect to (the URL encoding for /): https://pika.readthedocs.io/en/stable/examples/using_urlparameters.html aeviso: is the virtual host to connect to (the URL encoding for /): https://pika.readthedocs. | |||||
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: | else: | ||||
# in test sessions, we DO want to raise any exception occurring at commit time | # in test sessions, we DO want to raise any exception occurring at commit time | ||||
with get_provenance_storage( | with get_provenance_storage( | ||||
cls=request.param, db=provenance_postgresqldb, raise_on_commit=True | cls=request.param, db=provenance_postgresqldb, raise_on_commit=True | ||||
) as storage: | ) as storage: | ||||
yield storage | yield storage | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |
what's the %2f doing here?