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 @@ -10,6 +10,7 @@ from swh.core.db.pytest_plugin import postgresql_fact from swh.core.utils import numfile_sortkey as sortkey +from swh.model.tests.swh_model_data import TEST_OBJECTS import swh.provenance SQL_DIR = path.join(path.dirname(swh.provenance.__file__), "sql") @@ -32,3 +33,25 @@ ) return ProvenanceDB(provenance_db) + + +@pytest.fixture +def swh_storage_with_objects(swh_storage): + """return a Storage object (postgresql-based by default) with a few of each + object type in it + + The inserted content comes from swh.model.tests.swh_model_data. + """ + for obj_type in ( + "content", + "skipped_content", + "directory", + "revision", + "release", + "snapshot", + "origin", + "origin_visit", + "origin_visit_status", + ): + getattr(swh_storage, f"{obj_type}_add")(TEST_OBJECTS[obj_type]) + return swh_storage diff --git a/swh/provenance/tests/test_conftest.py b/swh/provenance/tests/test_conftest.py --- a/swh/provenance/tests/test_conftest.py +++ b/swh/provenance/tests/test_conftest.py @@ -5,5 +5,15 @@ def test_provenance_fixture(provenance): + """Check the 'provenance' fixture produce a working ProvenanceDB object""" assert provenance provenance.insert_all() # should be a noop + + +def test_storage(swh_storage_with_objects): + """Check the 'swh_storage_with_objects' fixture produce a working Storage + object with at least some Content, Revision and Directory in it""" + assert swh_storage_with_objects + assert swh_storage_with_objects.content_get_random() + assert swh_storage_with_objects.directory_get_random() + assert swh_storage_with_objects.revision_get_random()