diff --git a/swh/provenance/tests/conftest.py b/swh/provenance/tests/conftest.py index 7210fe0..db87dac 100644 --- a/swh/provenance/tests/conftest.py +++ b/swh/provenance/tests/conftest.py @@ -1,34 +1,57 @@ # Copyright (C) 2021 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 glob from os import path import pytest 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") SQL_FILES = [ sqlfile for sqlfile in sorted(glob.glob(path.join(SQL_DIR, "*.sql")), key=sortkey) if "-without-path-" not in sqlfile ] provenance_db = postgresql_fact( "postgresql_proc", db_name="provenance", dump_files=SQL_FILES ) @pytest.fixture def provenance(provenance_db): """return a working and initialized provenance db""" from swh.provenance.postgresql.provenancedb_with_path import ( ProvenanceWithPathDB as ProvenanceDB, ) 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 index ce1190f..f45fe0b 100644 --- a/swh/provenance/tests/test_conftest.py +++ b/swh/provenance/tests/test_conftest.py @@ -1,9 +1,19 @@ # Copyright (C) 2021 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 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()