diff --git a/swh/web/tests/api/test_utils.py b/swh/web/tests/api/test_utils.py --- a/swh/web/tests/api/test_utils.py +++ b/swh/web/tests/api/test_utils.py @@ -5,13 +5,10 @@ import random -from hypothesis import given - from swh.model.hashutil import DEFAULT_ALGORITHMS from swh.web.api import utils from swh.web.common.origin_visits import get_origin_visits from swh.web.common.utils import resolve_branch_alias, reverse -from swh.web.tests.strategies import snapshot url_map = [ { @@ -496,7 +493,6 @@ assert actual_revision == revision_data -@given(snapshot()) def test_enrich_snapshot(api_request_factory, archive_data, snapshot): snapshot_data = archive_data.snapshot_get(snapshot) diff --git a/swh/web/tests/api/views/test_identifiers.py b/swh/web/tests/api/views/test_identifiers.py --- a/swh/web/tests/api/views/test_identifiers.py +++ b/swh/web/tests/api/views/test_identifiers.py @@ -10,7 +10,6 @@ from swh.web.common.utils import reverse from swh.web.tests.data import random_sha1 from swh.web.tests.strategies import ( - snapshot, unknown_content, unknown_directory, unknown_release, @@ -20,7 +19,6 @@ from swh.web.tests.utils import check_api_get_responses, check_api_post_responses -@given(snapshot()) def test_swhid_resolve_success( api_client, content, directory, origin, release, revision, snapshot ): @@ -111,7 +109,6 @@ check_api_get_responses(api_client, url, status_code=400) -@given(snapshot()) def test_api_known_swhid_all_present( api_client, content, directory, release, revision, snapshot ): diff --git a/swh/web/tests/api/views/test_snapshot.py b/swh/web/tests/api/views/test_snapshot.py --- a/swh/web/tests/api/views/test_snapshot.py +++ b/swh/web/tests/api/views/test_snapshot.py @@ -12,11 +12,10 @@ from swh.web.api.utils import enrich_snapshot from swh.web.common.utils import reverse from swh.web.tests.data import random_sha1 -from swh.web.tests.strategies import new_snapshot, snapshot +from swh.web.tests.strategies import new_snapshot from swh.web.tests.utils import check_api_get_responses, check_http_get_response -@given(snapshot()) def test_api_snapshot(api_client, archive_data, snapshot): url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot}) @@ -26,7 +25,6 @@ assert rv.data == expected_data -@given(snapshot()) def test_api_snapshot_paginated(api_client, archive_data, snapshot): branches_offset = 0 @@ -88,7 +86,6 @@ assert rv.data == whole_snapshot -@given(snapshot()) def test_api_snapshot_filtered(api_client, archive_data, snapshot): snapshot_branches = [] @@ -125,7 +122,6 @@ check_api_get_responses(api_client, url, status_code=404) -@given(snapshot()) def test_api_snapshot_uppercase(api_client, snapshot): url = reverse( "api-1-snapshot-uppercase-checksum", url_args={"snapshot_id": snapshot.upper()} diff --git a/swh/web/tests/browse/test_snapshot_context.py b/swh/web/tests/browse/test_snapshot_context.py --- a/swh/web/tests/browse/test_snapshot_context.py +++ b/swh/web/tests/browse/test_snapshot_context.py @@ -5,8 +5,6 @@ import random -from hypothesis import given - from swh.model.swhids import ObjectType from swh.web.browse.snapshot_context import ( _get_release, @@ -23,7 +21,6 @@ SnapshotReleaseInfo, ) from swh.web.common.utils import format_utc_iso_date, reverse -from swh.web.tests.strategies import snapshot def test_get_origin_visit_snapshot_simple(archive_data, origin_with_multiple_visits): @@ -87,7 +84,6 @@ assert origin_visit_branches == (branches, releases, aliases) -@given(snapshot()) def test_get_snapshot_context_no_origin(archive_data, snapshot): for browse_context, kwargs in ( diff --git a/swh/web/tests/browse/views/test_identifiers.py b/swh/web/tests/browse/views/test_identifiers.py --- a/swh/web/tests/browse/views/test_identifiers.py +++ b/swh/web/tests/browse/views/test_identifiers.py @@ -6,14 +6,11 @@ import random from urllib.parse import quote -from hypothesis import given - from swh.model.model import Origin from swh.model.swhids import ObjectType from swh.web.common.identifiers import gen_swhid from swh.web.common.utils import reverse from swh.web.tests.django_asserts import assert_contains -from swh.web.tests.strategies import snapshot from swh.web.tests.utils import check_html_get_response @@ -100,7 +97,6 @@ assert resp["location"] == release_browse_url -@given(snapshot()) def test_snapshot_id_browse(client, snapshot): swhid = gen_swhid(ObjectType.SNAPSHOT, snapshot) diff --git a/swh/web/tests/common/test_archive.py b/swh/web/tests/common/test_archive.py --- a/swh/web/tests/common/test_archive.py +++ b/swh/web/tests/common/test_archive.py @@ -34,7 +34,6 @@ new_origin, new_revision, sha256, - snapshot, unknown_content, unknown_contents, unknown_directory, @@ -796,7 +795,6 @@ ) -@given(snapshot()) def test_lookup_known_objects( archive_data, content, directory, release, revision, snapshot ): @@ -984,7 +982,6 @@ ) -@given(snapshot()) def test_lookup_snapshot_sizes(archive_data, snapshot): branches = archive_data.snapshot_get(snapshot)["branches"] @@ -1031,7 +1028,6 @@ ) -@given(snapshot()) def test_lookup_snapshot_alias(snapshot): resolved_alias = archive.lookup_snapshot_alias(snapshot, "HEAD") assert resolved_alias is not None diff --git a/swh/web/tests/common/test_identifiers.py b/swh/web/tests/common/test_identifiers.py --- a/swh/web/tests/common/test_identifiers.py +++ b/swh/web/tests/common/test_identifiers.py @@ -6,7 +6,6 @@ import random from urllib.parse import quote -from hypothesis import given import pytest from swh.model.hashutil import hash_to_bytes @@ -25,7 +24,6 @@ from swh.web.common.typing import SWHObjectInfo from swh.web.common.utils import reverse from swh.web.tests.data import random_sha1 -from swh.web.tests.strategies import snapshot def test_gen_swhid(content): @@ -63,7 +61,6 @@ assert e.match("Invalid swh object type") -@given(snapshot()) def test_resolve_swhid_legacy(content, directory, release, revision, snapshot): for obj_type, obj_id in ( (ObjectType.CONTENT, content["sha1_git"]), @@ -100,7 +97,6 @@ resolve_swhid(f"swh:1:ori:{random_sha1()}") -@given(snapshot()) def test_get_swhid(content, directory, release, revision, snapshot): for obj_type, obj_id in ( (ObjectType.CONTENT, content["sha1_git"]), @@ -119,7 +115,6 @@ get_swhid("foo") -@given(snapshot()) def test_group_swhids(content, directory, release, revision, snapshot): swhids = [] expected = {} diff --git a/swh/web/tests/common/test_middlewares.py b/swh/web/tests/common/test_middlewares.py --- a/swh/web/tests/common/test_middlewares.py +++ b/swh/web/tests/common/test_middlewares.py @@ -3,19 +3,16 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from hypothesis import given import pytest from django.test import modify_settings from swh.web.common.utils import reverse -from swh.web.tests.strategies import snapshot @modify_settings( MIDDLEWARE={"remove": ["swh.web.common.middlewares.ExceptionMiddleware"]} ) -@given(snapshot()) def test_exception_middleware_disabled(client, mocker, snapshot): mock_browse_snapshot_directory = mocker.patch( "swh.web.browse.views.snapshot.browse_snapshot_directory" @@ -28,7 +25,6 @@ client.get(url) -@given(snapshot()) def test_exception_middleware_enabled(client, mocker, snapshot): mock_browse_snapshot_directory = mocker.patch( "swh.web.browse.views.snapshot.browse_snapshot_directory" diff --git a/swh/web/tests/conftest.py b/swh/web/tests/conftest.py --- a/swh/web/tests/conftest.py +++ b/swh/web/tests/conftest.py @@ -520,9 +520,16 @@ ) +@pytest.fixture(scope="function") +def snapshot(tests_data): + """Fixture returning a random snapshot ingested into the test archive. + """ + return random.choice(_known_swh_objects(tests_data, "snapshots")) + + @pytest.fixture(scope="function") def origin(tests_data): - """Fixturee returning a random origin ingested into the test archive. + """Fixture returning a random origin ingested into the test archive. """ return random.choice(_known_swh_objects(tests_data, "origins")) @@ -610,6 +617,14 @@ return _object_type_swhid(tests_data, ObjectType.REVISION) +@pytest.fixture(scope="function") +def snapshot_swhid(tests_data): + """Fixture returning a qualified SWHID for a snapshot object + ingested into the test archive. + """ + return _object_type_swhid(tests_data, ObjectType.SNAPSHOT) + + # Fixture to manipulate data from a sample archive used in the tests @pytest.fixture(scope="function") def archive_data(tests_data): diff --git a/swh/web/tests/misc/test_badges.py b/swh/web/tests/misc/test_badges.py --- a/swh/web/tests/misc/test_badges.py +++ b/swh/web/tests/misc/test_badges.py @@ -16,7 +16,6 @@ from swh.web.tests.strategies import ( invalid_sha1, new_origin, - snapshot, unknown_content, unknown_directory, unknown_release, @@ -46,7 +45,6 @@ _test_badge_endpoints(client, "revision", revision) -@given(snapshot()) def test_snapshot_badge(client, snapshot): _test_badge_endpoints(client, "snapshot", snapshot) diff --git a/swh/web/tests/strategies.py b/swh/web/tests/strategies.py --- a/swh/web/tests/strategies.py +++ b/swh/web/tests/strategies.py @@ -8,21 +8,12 @@ from hypothesis import assume, settings from hypothesis.extra.dateutil import timezones -from hypothesis.strategies import ( - binary, - characters, - composite, - datetimes, - lists, - sampled_from, - text, -) +from hypothesis.strategies import binary, characters, composite, datetimes, lists, text from swh.model.hashutil import hash_to_bytes, hash_to_hex from swh.model.hypothesis_strategies import origins as new_origin_strategy from swh.model.hypothesis_strategies import snapshots as new_snapshot from swh.model.model import Person, Revision, RevisionType, TimestampWithTimezone -from swh.model.swhids import ObjectType from swh.web.tests.data import get_tests_data # Module dedicated to the generation of input data for tests through @@ -36,13 +27,6 @@ settings.load_profile("swh-web") -# The following strategies exploit the hypothesis capabilities - - -def _known_swh_object(object_type): - return sampled_from(get_tests_data()[object_type]) - - def sha1(): """ Hypothesis strategy returning a valid hexadecimal sha1 value. @@ -240,14 +224,6 @@ return lists(unknown_revision(), min_size=min_size, max_size=max_size) -def snapshot(): - """ - Hypothesis strategy returning a random snapshot ingested - into the test archive. - """ - return _known_swh_object("snapshots") - - def new_snapshots(nb_snapshots=None): min_size = nb_snapshots if nb_snapshots else 2 max_size = nb_snapshots if nb_snapshots else 8 @@ -267,19 +243,3 @@ lambda s: get_tests_data()["storage"].snapshot_get_branches(hash_to_bytes(s)) is None ) - - -def swhid(): - """ - Hypothesis strategy returning a qualified SWHID for any object - ingested into the test archive. - """ - return _known_swh_object("swhids") - - -def snapshot_swhid(): - """ - Hypothesis strategy returning a qualified SWHID for a snapshot object - ingested into the test archive. - """ - return swhid().filter(lambda swhid: swhid.object_type == ObjectType.SNAPSHOT)