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
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2020 The Software Heritage developers
+# Copyright (C) 2015-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -11,7 +11,7 @@
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 origin, release, revision, snapshot
+from swh.web.tests.strategies import release, revision, snapshot
url_map = [
{
@@ -538,7 +538,6 @@
assert actual_snapshot == snapshot_data
-@given(origin())
def test_enrich_origin(api_request_factory, origin):
url = reverse("api-1-origin", url_args={"origin_url": origin["url"]})
request = api_request_factory.get(url)
@@ -553,7 +552,6 @@
assert actual_origin == origin_data
-@given(origin())
def test_enrich_origin_search_result(api_request_factory, origin):
url = reverse("api-1-origin-search", url_args={"url_pattern": origin["url"]})
request = api_request_factory.get(url)
@@ -578,7 +576,6 @@
)
-@given(origin())
def test_enrich_origin_visit(api_request_factory, origin):
origin_visit = random.choice(get_origin_visits(origin))
diff --git a/swh/web/tests/api/views/test_graph.py b/swh/web/tests/api/views/test_graph.py
--- a/swh/web/tests/api/views/test_graph.py
+++ b/swh/web/tests/api/views/test_graph.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 The Software Heritage developers
+# Copyright (C) 2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -7,8 +7,6 @@
import json
import textwrap
-from hypothesis import given
-
from django.http.response import StreamingHttpResponse
from swh.model.hashutil import hash_to_bytes
@@ -16,7 +14,6 @@
from swh.web.api.views.graph import API_GRAPH_PERM
from swh.web.common.utils import reverse
from swh.web.config import SWH_WEB_INTERNAL_SERVER_NAME, get_config
-from swh.web.tests.strategies import origin
from swh.web.tests.utils import check_http_get_response
@@ -165,7 +162,6 @@
assert b"".join(resp.streaming_content) == response_ndjson.encode()
-@given(origin())
def test_graph_response_resolve_origins(
archive_data, api_client, keycloak_oidc, requests_mock, origin
):
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 (
- origin,
release,
revision,
snapshot,
@@ -23,7 +22,7 @@
from swh.web.tests.utils import check_api_get_responses, check_api_post_responses
-@given(origin(), release(), revision(), snapshot())
+@given(release(), revision(), snapshot())
def test_swhid_resolve_success(
api_client, client, content, directory, origin, release, revision, snapshot
):
diff --git a/swh/web/tests/api/views/test_origin.py b/swh/web/tests/api/views/test_origin.py
--- a/swh/web/tests/api/views/test_origin.py
+++ b/swh/web/tests/api/views/test_origin.py
@@ -26,7 +26,7 @@
ORIGIN_METADATA_KEY,
ORIGIN_METADATA_VALUE,
)
-from swh.web.tests.strategies import new_origin, new_snapshots, origin, visit_dates
+from swh.web.tests.strategies import new_origin, new_snapshots, visit_dates
from swh.web.tests.utils import check_api_get_responses
@@ -322,7 +322,6 @@
assert rv.data == expected_visit
-@given(origin())
def test_api_lookup_origin_visit_not_found(api_client, origin):
all_visits = list(reversed(get_origin_visits(origin)))
@@ -394,7 +393,6 @@
assert {origin["url"] for origin in results} == origin_urls
-@given(origin())
def test_api_origin_by_url(api_client, archive_data, origin):
origin_url = origin["url"]
url = reverse("api-1-origin", url_args={"origin_url": origin_url})
@@ -706,7 +704,6 @@
oimsft.assert_called_with(conjunction=[ORIGIN_METADATA_VALUE], limit=100)
-@given(origin())
def test_api_origin_intrinsic_metadata(api_client, origin):
url = reverse(
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
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2019 The Software Heritage developers
+# Copyright (C) 2018-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -12,11 +12,7 @@
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,
- origin_with_pull_request_branches,
- snapshot,
-)
+from swh.web.tests.strategies import new_snapshot, snapshot
from swh.web.tests.utils import check_api_get_responses, check_http_get_response
@@ -156,13 +152,12 @@
check_api_get_responses(api_client, url, status_code=200)
-@given(origin_with_pull_request_branches())
def test_api_snapshot_no_pull_request_branches_filtering(
- api_client, archive_data, origin
+ api_client, archive_data, origin_with_pull_request_branches
):
"""Pull request branches should not be filtered out when querying
a snapshot with the Web API."""
- snapshot = archive_data.snapshot_get_latest(origin.url)
+ snapshot = archive_data.snapshot_get_latest(origin_with_pull_request_branches.url)
url = reverse("api-1-snapshot", url_args={"snapshot_id": snapshot["id"]})
resp = check_api_get_responses(api_client, url, status_code=200)
assert any([b.startswith("refs/pull/") for b in resp.data["branches"]])
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
@@ -23,16 +23,11 @@
SnapshotReleaseInfo,
)
from swh.web.common.utils import format_utc_iso_date, reverse
-from swh.web.tests.strategies import (
- origin_with_multiple_visits,
- origin_with_releases,
- snapshot,
-)
+from swh.web.tests.strategies import snapshot
-@given(origin_with_multiple_visits())
-def test_get_origin_visit_snapshot_simple(archive_data, origin):
- visits = archive_data.origin_visit_get(origin["url"])
+def test_get_origin_visit_snapshot_simple(archive_data, origin_with_multiple_visits):
+ visits = archive_data.origin_visit_get(origin_with_multiple_visits["url"])
for visit in visits:
@@ -86,7 +81,7 @@
assert branches and releases, "Incomplete test data."
origin_visit_branches = get_origin_visit_snapshot(
- origin, visit_id=visit["visit"]
+ origin_with_multiple_visits, visit_id=visit["visit"]
)
assert origin_visit_branches == (branches, releases, aliases)
@@ -172,20 +167,21 @@
)
-@given(origin_with_multiple_visits())
-def test_get_snapshot_context_with_origin(archive_data, origin):
+def test_get_snapshot_context_with_origin(archive_data, origin_with_multiple_visits):
- origin_visits = get_origin_visits(origin)
+ origin_visits = get_origin_visits(origin_with_multiple_visits)
timestamp = format_utc_iso_date(origin_visits[0]["date"], "%Y-%m-%dT%H:%M:%SZ")
visit_id = origin_visits[1]["visit"]
+ origin_url = origin_with_multiple_visits["url"]
+
for browse_context, kwargs in (
- ("content", {"origin_url": origin["url"], "path": "/some/path"}),
- ("directory", {"origin_url": origin["url"]}),
- ("log", {"origin_url": origin["url"]}),
- ("directory", {"origin_url": origin["url"], "timestamp": timestamp,},),
- ("directory", {"origin_url": origin["url"], "visit_id": visit_id,},),
+ ("content", {"origin_url": origin_url, "path": "/some/path"}),
+ ("directory", {"origin_url": origin_url}),
+ ("log", {"origin_url": origin_url}),
+ ("directory", {"origin_url": origin_url, "timestamp": timestamp,},),
+ ("directory", {"origin_url": origin_url, "visit_id": visit_id,},),
):
visit_id = kwargs["visit_id"] if "visit_id" in kwargs else None
@@ -243,7 +239,7 @@
branches=branches,
branches_url=branches_url,
is_empty=is_empty,
- origin_info={"url": origin["url"]},
+ origin_info={"url": origin_url},
origin_visits_url=origin_visits_url,
release=None,
release_alias=False,
@@ -382,9 +378,8 @@
assert snapshot_context == expected_revision
-@given(origin_with_releases())
-def test_get_release_large_snapshot(archive_data, origin):
- snapshot = archive_data.snapshot_get_latest(origin["url"])
+def test_get_release_large_snapshot(archive_data, origin_with_releases):
+ snapshot = archive_data.snapshot_get_latest(origin_with_releases["url"])
release_id = random.choice(
[
v["target"]
diff --git a/swh/web/tests/browse/views/test_content.py b/swh/web/tests/browse/views/test_content.py
--- a/swh/web/tests/browse/views/test_content.py
+++ b/swh/web/tests/browse/views/test_content.py
@@ -20,11 +20,7 @@
from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import gen_path_info, reverse
from swh.web.tests.django_asserts import assert_contains, assert_not_contains
-from swh.web.tests.strategies import (
- invalid_sha1,
- origin_with_multiple_visits,
- unknown_content,
-)
+from swh.web.tests.strategies import invalid_sha1, unknown_content
from swh.web.tests.utils import check_html_get_response, check_http_get_response
@@ -422,9 +418,11 @@
assert_contains(resp, escape(content_display["content_data"]))
-@given(origin_with_multiple_visits())
-def test_content_origin_snapshot_branch_browse(client, archive_data, origin):
- visits = archive_data.origin_visit_get(origin["url"])
+def test_content_origin_snapshot_branch_browse(
+ client, archive_data, origin_with_multiple_visits
+):
+ origin_url = origin_with_multiple_visits["url"]
+ visits = archive_data.origin_visit_get(origin_url)
visit = random.choice(visits)
snapshot = archive_data.snapshot_get(visit["snapshot"])
snapshot_sizes = archive_data.snapshot_count_branches(visit["snapshot"])
@@ -441,7 +439,7 @@
"browse-content",
url_args={"query_string": directory_file["checksums"]["sha1"]},
query_params={
- "origin_url": origin["url"],
+ "origin_url": origin_with_multiple_visits["url"],
"snapshot": snapshot["id"],
"branch": branch_info["name"],
"path": directory_file["name"],
@@ -453,7 +451,7 @@
)
_check_origin_snapshot_related_html(
- resp, origin, snapshot, snapshot_sizes, branches, releases
+ resp, origin_with_multiple_visits, snapshot, snapshot_sizes, branches, releases
)
assert_contains(resp, directory_file["name"])
assert_contains(resp, f"Branch: {branch_info['name']}")
@@ -462,7 +460,7 @@
ObjectType.CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
"anchor": gen_swhid(ObjectType.REVISION, branch_info["revision"]),
"path": f"/{directory_file['name']}",
@@ -474,7 +472,7 @@
ObjectType.DIRECTORY,
directory,
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
"anchor": gen_swhid(ObjectType.REVISION, branch_info["revision"]),
},
@@ -485,21 +483,23 @@
ObjectType.REVISION,
branch_info["revision"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rev_swhid)
snp_swhid = gen_swhid(
- ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
+ ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin_url,},
)
assert_contains(resp, snp_swhid)
-@given(origin_with_multiple_visits())
-def test_content_origin_snapshot_release_browse(client, archive_data, origin):
- visits = archive_data.origin_visit_get(origin["url"])
+def test_content_origin_snapshot_release_browse(
+ client, archive_data, origin_with_multiple_visits
+):
+ origin_url = origin_with_multiple_visits["url"]
+ visits = archive_data.origin_visit_get(origin_url)
visit = random.choice(visits)
snapshot = archive_data.snapshot_get(visit["snapshot"])
snapshot_sizes = archive_data.snapshot_count_branches(visit["snapshot"])
@@ -515,7 +515,7 @@
"browse-content",
url_args={"query_string": directory_file["checksums"]["sha1"]},
query_params={
- "origin_url": origin["url"],
+ "origin_url": origin_url,
"snapshot": snapshot["id"],
"release": release_info["name"],
"path": directory_file["name"],
@@ -527,7 +527,7 @@
)
_check_origin_snapshot_related_html(
- resp, origin, snapshot, snapshot_sizes, branches, releases
+ resp, origin_with_multiple_visits, snapshot, snapshot_sizes, branches, releases
)
assert_contains(resp, directory_file["name"])
assert_contains(resp, f"Release: {release_info['name']}")
@@ -536,7 +536,7 @@
ObjectType.CONTENT,
directory_file["checksums"]["sha1_git"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
"anchor": gen_swhid(ObjectType.RELEASE, release_info["id"]),
"path": f"/{directory_file['name']}",
@@ -548,7 +548,7 @@
ObjectType.DIRECTORY,
release_info["directory"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
"anchor": gen_swhid(ObjectType.RELEASE, release_info["id"]),
},
@@ -559,7 +559,7 @@
ObjectType.REVISION,
release_info["target"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
@@ -569,14 +569,14 @@
ObjectType.RELEASE,
release_info["id"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rel_swhid)
snp_swhid = gen_swhid(
- ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
+ ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin_url,},
)
assert_contains(resp, snp_swhid)
diff --git a/swh/web/tests/browse/views/test_directory.py b/swh/web/tests/browse/views/test_directory.py
--- a/swh/web/tests/browse/views/test_directory.py
+++ b/swh/web/tests/browse/views/test_directory.py
@@ -34,7 +34,6 @@
invalid_sha1,
new_person,
new_swh_date,
- origin_with_multiple_visits,
unknown_directory,
)
from swh.web.tests.utils import check_html_get_response
@@ -193,9 +192,11 @@
assert_contains(resp, 'id="swhid-context-option-directory"')
-@given(origin_with_multiple_visits())
-def test_directory_origin_snapshot_branch_browse(client, archive_data, origin):
- visits = archive_data.origin_visit_get(origin["url"])
+def test_directory_origin_snapshot_branch_browse(
+ client, archive_data, origin_with_multiple_visits
+):
+ origin_url = origin_with_multiple_visits["url"]
+ visits = archive_data.origin_visit_get(origin_url)
visit = random.choice(visits)
snapshot = archive_data.snapshot_get(visit["snapshot"])
snapshot_sizes = archive_data.snapshot_count_branches(visit["snapshot"])
@@ -212,7 +213,7 @@
"browse-directory",
url_args={"sha1_git": directory},
query_params={
- "origin_url": origin["url"],
+ "origin_url": origin_url,
"snapshot": snapshot["id"],
"branch": branch_info["name"],
"path": directory_subdir["name"],
@@ -224,7 +225,7 @@
)
_check_origin_snapshot_related_html(
- resp, origin, snapshot, snapshot_sizes, branches, releases
+ resp, origin_with_multiple_visits, snapshot, snapshot_sizes, branches, releases
)
assert_contains(resp, directory_subdir["name"])
assert_contains(resp, f"Branch: {branch_info['name']}")
@@ -233,7 +234,7 @@
ObjectType.DIRECTORY,
directory_subdir["target"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
"anchor": gen_swhid(ObjectType.REVISION, branch_info["revision"]),
"path": "/",
@@ -245,21 +246,23 @@
ObjectType.REVISION,
branch_info["revision"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rev_swhid)
snp_swhid = gen_swhid(
- ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
+ ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin_url,},
)
assert_contains(resp, snp_swhid)
-@given(origin_with_multiple_visits())
-def test_drectory_origin_snapshot_release_browse(client, archive_data, origin):
- visits = archive_data.origin_visit_get(origin["url"])
+def test_drectory_origin_snapshot_release_browse(
+ client, archive_data, origin_with_multiple_visits
+):
+ origin_url = origin_with_multiple_visits["url"]
+ visits = archive_data.origin_visit_get(origin_url)
visit = random.choice(visits)
snapshot = archive_data.snapshot_get(visit["snapshot"])
snapshot_sizes = archive_data.snapshot_count_branches(visit["snapshot"])
@@ -276,7 +279,7 @@
"browse-directory",
url_args={"sha1_git": directory},
query_params={
- "origin_url": origin["url"],
+ "origin_url": origin_url,
"snapshot": snapshot["id"],
"release": release_info["name"],
"path": directory_subdir["name"],
@@ -288,7 +291,7 @@
)
_check_origin_snapshot_related_html(
- resp, origin, snapshot, snapshot_sizes, branches, releases
+ resp, origin_with_multiple_visits, snapshot, snapshot_sizes, branches, releases
)
assert_contains(resp, directory_subdir["name"])
assert_contains(resp, f"Release: {release_info['name']}")
@@ -297,7 +300,7 @@
ObjectType.DIRECTORY,
directory_subdir["target"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
"anchor": gen_swhid(ObjectType.RELEASE, release_info["id"]),
"path": "/",
@@ -309,7 +312,7 @@
ObjectType.REVISION,
release_info["target"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
@@ -319,21 +322,23 @@
ObjectType.RELEASE,
release_info["id"],
metadata={
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
},
)
assert_contains(resp, rel_swhid)
snp_swhid = gen_swhid(
- ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin["url"],},
+ ObjectType.SNAPSHOT, snapshot["id"], metadata={"origin": origin_url,},
)
assert_contains(resp, snp_swhid)
-@given(origin_with_multiple_visits())
-def test_directory_origin_snapshot_revision_browse(client, archive_data, origin):
- visits = archive_data.origin_visit_get(origin["url"])
+def test_directory_origin_snapshot_revision_browse(
+ client, archive_data, origin_with_multiple_visits
+):
+ origin_url = origin_with_multiple_visits["url"]
+ visits = archive_data.origin_visit_get(origin_url)
visit = random.choice(visits)
snapshot = archive_data.snapshot_get(visit["snapshot"])
branches, releases, _ = process_snapshot_branches(snapshot)
@@ -349,7 +354,7 @@
"browse-directory",
url_args={"sha1_git": directory},
query_params={
- "origin_url": origin["url"],
+ "origin_url": origin_url,
"snapshot": snapshot["id"],
"revision": branch_info["revision"],
"path": directory_subdir["name"],
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
@@ -13,7 +13,7 @@
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 origin, release, revision, snapshot
+from swh.web.tests.strategies import release, revision, snapshot
from swh.web.tests.utils import check_html_get_response
@@ -173,7 +173,6 @@
check_html_get_response(client, url, status_code=400)
-@given(origin())
def test_legacy_swhid_browse(archive_data, client, origin):
snapshot = archive_data.snapshot_get_latest(origin["url"])
revision = archive_data.snapshot_get_head(snapshot)
diff --git a/swh/web/tests/browse/views/test_origin.py b/swh/web/tests/browse/views/test_origin.py
--- a/swh/web/tests/browse/views/test_origin.py
+++ b/swh/web/tests/browse/views/test_origin.py
@@ -33,43 +33,37 @@
)
from swh.web.tests.data import get_content, random_sha1
from swh.web.tests.django_asserts import assert_contains, assert_not_contains
-from swh.web.tests.strategies import (
- new_origin,
- new_snapshot,
- origin,
- origin_with_multiple_visits,
- origin_with_pull_request_branches,
- origin_with_releases,
-)
+from swh.web.tests.strategies import new_origin, new_snapshot
from swh.web.tests.strategies import release as existing_release
from swh.web.tests.strategies import revisions, unknown_revision, visit_dates
from swh.web.tests.utils import check_html_get_response
-@given(origin_with_multiple_visits())
-def test_origin_visits_browse(client, archive_data, origin):
- url = reverse("browse-origin-visits", query_params={"origin_url": origin["url"]})
+def test_origin_visits_browse(client, archive_data, origin_with_multiple_visits):
+ origin_url = origin_with_multiple_visits["url"]
+ url = reverse("browse-origin-visits", query_params={"origin_url": origin_url})
resp = check_html_get_response(
client, url, status_code=200, template_used="browse/origin-visits.html"
)
- visits = archive_data.origin_visit_get(origin["url"])
+ visits = archive_data.origin_visit_get(origin_url)
for v in visits:
vdate = format_utc_iso_date(v["date"], "%Y-%m-%dT%H:%M:%SZ")
browse_dir_url = reverse(
"browse-origin-directory",
- query_params={"origin_url": origin["url"], "timestamp": vdate},
+ query_params={"origin_url": origin_url, "timestamp": vdate},
)
assert_contains(resp, browse_dir_url)
- _check_origin_link(resp, origin["url"])
+ _check_origin_link(resp, origin_url)
-@given(origin_with_multiple_visits())
-def test_origin_content_view(client, archive_data, swh_scheduler, origin):
- origin_visits = archive_data.origin_visit_get(origin["url"])
+def test_origin_content_view(
+ client, archive_data, swh_scheduler, origin_with_multiple_visits
+):
+ origin_visits = archive_data.origin_visit_get(origin_with_multiple_visits["url"])
def _get_archive_data(visit_idx):
snapshot = archive_data.snapshot_get(origin_visits[visit_idx]["snapshot"])
@@ -93,7 +87,7 @@
_origin_content_view_test_helper(
client,
archive_data,
- origin,
+ origin_with_multiple_visits,
origin_visits[-1],
tdata["snapshot_sizes"],
tdata["branches"],
@@ -105,7 +99,7 @@
_origin_content_view_test_helper(
client,
archive_data,
- origin,
+ origin_with_multiple_visits,
origin_visits[-1],
tdata["snapshot_sizes"],
tdata["branches"],
@@ -118,7 +112,7 @@
_origin_content_view_test_helper(
client,
archive_data,
- origin,
+ origin_with_multiple_visits,
origin_visits[-1],
tdata["snapshot_sizes"],
tdata["branches"],
@@ -133,7 +127,7 @@
_origin_content_view_test_helper(
client,
archive_data,
- origin,
+ origin_with_multiple_visits,
origin_visits[0],
tdata["snapshot_sizes"],
tdata["branches"],
@@ -146,7 +140,7 @@
_origin_content_view_test_helper(
client,
archive_data,
- origin,
+ origin_with_multiple_visits,
origin_visits[0],
tdata["snapshot_sizes"],
tdata["branches"],
@@ -157,7 +151,6 @@
)
-@given(origin())
def test_origin_root_directory_view(client, archive_data, swh_scheduler, origin):
origin_visits = archive_data.origin_visit_get(origin["url"])
@@ -273,7 +266,6 @@
)
-@given(origin())
def test_origin_sub_directory_view(client, archive_data, swh_scheduler, origin):
origin_visits = archive_data.origin_visit_get(origin["url"])
@@ -406,7 +398,6 @@
)
-@given(origin())
def test_origin_branches(client, archive_data, origin):
origin_visits = archive_data.origin_visit_get(origin["url"])
@@ -422,7 +413,6 @@
)
-@given(origin())
def test_origin_releases(client, archive_data, origin):
origin_visits = archive_data.origin_visit_get(origin["url"])
@@ -530,7 +520,6 @@
)
-@given(origin())
def test_browse_origin_directory_no_visit(client, mocker, origin):
mock_get_origin_visits = mocker.patch(
"swh.web.common.origin_visits.get_origin_visits"
@@ -547,7 +536,6 @@
assert not mock_get_origin_visits.called
-@given(origin())
def test_browse_origin_directory_unknown_visit(client, mocker, origin):
mock_get_origin_visits = mocker.patch(
"swh.web.common.origin_visits.get_origin_visits"
@@ -566,7 +554,6 @@
assert mock_get_origin_visits.called
-@given(origin())
def test_browse_origin_directory_not_found(client, origin):
url = reverse(
"browse-origin-directory",
@@ -579,7 +566,6 @@
assert re.search("Directory.*not found", resp.content.decode("utf-8"))
-@given(origin())
def test_browse_origin_content_no_visit(client, mocker, origin):
mock_get_origin_visits = mocker.patch(
"swh.web.common.origin_visits.get_origin_visits"
@@ -599,7 +585,6 @@
assert not mock_get_origin_visits.called
-@given(origin())
def test_browse_origin_content_unknown_visit(client, mocker, origin):
mock_get_origin_visits = mocker.patch(
"swh.web.common.origin_visits.get_origin_visits"
@@ -658,7 +643,6 @@
assert re.search("snapshot.*is empty", resp.content.decode("utf-8"))
-@given(origin())
def test_browse_origin_content_not_found(client, origin):
url = reverse(
"browse-origin-content",
@@ -671,7 +655,6 @@
assert re.search("Directory entry.*not found", resp.content.decode("utf-8"))
-@given(origin())
def test_browse_directory_snapshot_not_found(client, mocker, origin):
mock_get_snapshot_context = mocker.patch(
"swh.web.browse.snapshot_context.get_snapshot_context"
@@ -739,9 +722,9 @@
assert not re.search("swh-tr-link", resp_content)
-@given(origin_with_releases())
-def test_origin_release_browse(client, archive_data, origin):
- snapshot = archive_data.snapshot_get_latest(origin["url"])
+def test_origin_release_browse(client, archive_data, origin_with_releases):
+ origin_url = origin_with_releases["url"]
+ snapshot = archive_data.snapshot_get_latest(origin_url)
release = [
b for b in snapshot["branches"].values() if b["target_type"] == "release"
][-1]
@@ -749,7 +732,7 @@
revision_data = archive_data.revision_get(release_data["target"])
url = reverse(
"browse-origin-directory",
- query_params={"origin_url": origin["url"], "release": release_data["name"]},
+ query_params={"origin_url": origin_url, "release": release_data["name"]},
)
resp = check_html_get_response(
@@ -759,7 +742,7 @@
assert_contains(resp, release["target"])
swhid_context = {
- "origin": origin["url"],
+ "origin": origin_url,
"visit": gen_swhid(ObjectType.SNAPSHOT, snapshot["id"]),
"anchor": gen_swhid(ObjectType.RELEASE, release_data["id"]),
}
@@ -772,13 +755,15 @@
assert_contains(resp, swh_dir_id_url)
-@given(origin_with_releases())
-def test_origin_release_browse_not_found(client, origin):
+def test_origin_release_browse_not_found(client, origin_with_releases):
invalid_release_name = "swh-foo-bar"
url = reverse(
"browse-origin-directory",
- query_params={"origin_url": origin["url"], "release": invalid_release_name},
+ query_params={
+ "origin_url": origin_with_releases["url"],
+ "release": invalid_release_name,
+ },
)
resp = check_html_get_response(
@@ -838,7 +823,6 @@
assert_not_contains(resp, "swh:1:rev:")
-@given(origin())
def test_origin_content_no_path(client, origin):
url = reverse("browse-origin-content", query_params={"origin_url": origin["url"]})
@@ -1300,26 +1284,28 @@
assert_contains(resp, f'href="{browse_origin_url}"')
-@given(origin_with_pull_request_branches())
-def test_pull_request_branches_filtering(client, origin):
+def test_pull_request_branches_filtering(client, origin_with_pull_request_branches):
+ origin_url = origin_with_pull_request_branches.url
# check no pull request branches are displayed in the Branches / Releases dropdown
- url = reverse("browse-origin-directory", query_params={"origin_url": origin.url})
+ url = reverse("browse-origin-directory", query_params={"origin_url": origin_url})
resp = check_html_get_response(
client, url, status_code=200, template_used="browse/directory.html"
)
assert_not_contains(resp, "refs/pull/")
# check no pull request branches are displayed in the branches view
- url = reverse("browse-origin-branches", query_params={"origin_url": origin.url})
+ url = reverse("browse-origin-branches", query_params={"origin_url": origin_url})
resp = check_html_get_response(
client, url, status_code=200, template_used="browse/branches.html"
)
assert_not_contains(resp, "refs/pull/")
-@given(origin_with_pull_request_branches())
-def test_browse_pull_request_branch(client, archive_data, origin):
- snapshot = archive_data.snapshot_get_latest(origin.url)
+def test_browse_pull_request_branch(
+ client, archive_data, origin_with_pull_request_branches
+):
+ origin_url = origin_with_pull_request_branches.url
+ snapshot = archive_data.snapshot_get_latest(origin_url)
pr_branch = random.choice(
[
branch
@@ -1329,7 +1315,7 @@
)
url = reverse(
"browse-origin-directory",
- query_params={"origin_url": origin.url, "branch": pr_branch},
+ query_params={"origin_url": origin_url, "branch": pr_branch},
)
check_html_get_response(
client, url, status_code=200, template_used="browse/directory.html"
diff --git a/swh/web/tests/browse/views/test_release.py b/swh/web/tests/browse/views/test_release.py
--- a/swh/web/tests/browse/views/test_release.py
+++ b/swh/web/tests/browse/views/test_release.py
@@ -13,7 +13,7 @@
from swh.web.common.identifiers import gen_swhid
from swh.web.common.utils import format_utc_iso_date, reverse
from swh.web.tests.django_asserts import assert_contains
-from swh.web.tests.strategies import origin_with_releases, release, unknown_release
+from swh.web.tests.strategies import release, unknown_release
from swh.web.tests.utils import check_html_get_response
@@ -22,9 +22,11 @@
_release_browse_checks(client, release, archive_data)
-@given(origin_with_releases())
-def test_release_browse_with_origin_snapshot(client, archive_data, origin):
- snapshot = archive_data.snapshot_get_latest(origin["url"])
+def test_release_browse_with_origin_snapshot(
+ client, archive_data, origin_with_releases
+):
+ origin_url = origin_with_releases["url"]
+ snapshot = archive_data.snapshot_get_latest(origin_url)
release = random.choice(
[
b["target"]
@@ -33,13 +35,13 @@
]
)
- _release_browse_checks(client, release, archive_data, origin_url=origin["url"])
+ _release_browse_checks(client, release, archive_data, origin_url=origin_url)
_release_browse_checks(client, release, archive_data, snapshot_id=snapshot["id"])
_release_browse_checks(
client,
release,
archive_data,
- origin_url=origin["url"],
+ origin_url=origin_url,
snapshot_id=snapshot["id"],
)
diff --git a/swh/web/tests/browse/views/test_revision.py b/swh/web/tests/browse/views/test_revision.py
--- a/swh/web/tests/browse/views/test_revision.py
+++ b/swh/web/tests/browse/views/test_revision.py
@@ -20,7 +20,6 @@
new_origin,
new_person,
new_swh_date,
- origin,
revision,
unknown_revision,
)
@@ -32,7 +31,6 @@
_revision_browse_checks(client, archive_data, revision)
-@given(origin())
def test_revision_origin_snapshot_browse(client, archive_data, swh_scheduler, origin):
snapshot = archive_data.snapshot_get_latest(origin["url"])
revision = archive_data.snapshot_get_head(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
@@ -35,7 +35,6 @@
new_origin,
new_revision,
non_ancestor_revisions,
- origin,
release,
releases,
revision,
@@ -578,7 +577,6 @@
return branches
-@given(origin())
def test_lookup_revision_log_by(archive_data, origin):
branches = _get_origin_branches(archive_data, origin)
branch_name = random.choice(list(branches.keys()))
@@ -592,7 +590,6 @@
assert actual_log == expected_log
-@given(origin())
def test_lookup_revision_log_by_notfound(origin):
with pytest.raises(NotFoundExc):
archive.lookup_revision_log_by(
@@ -681,13 +678,11 @@
assert actual_directory_ls == []
-@given(origin())
def test_lookup_revision_by_nothing_found(origin):
with pytest.raises(NotFoundExc):
archive.lookup_revision_by(origin["url"], "invalid-branch-name")
-@given(origin())
def test_lookup_revision_by(archive_data, origin):
branches = _get_origin_branches(archive_data, origin)
branch_name = random.choice(list(branches.keys()))
@@ -699,7 +694,7 @@
assert actual_revision == expected_revision
-@given(origin(), revision())
+@given(revision())
def test_lookup_revision_with_context_by_ko(origin, revision):
with pytest.raises(NotFoundExc):
archive.lookup_revision_with_context_by(
@@ -707,7 +702,6 @@
)
-@given(origin())
def test_lookup_revision_with_context_by(archive_data, origin):
branches = _get_origin_branches(archive_data, origin)
branch_name = random.choice(list(branches.keys()))
@@ -740,7 +734,6 @@
archive.lookup_revision_through({"something-unknown": 10})
-@given(origin())
def test_lookup_revision_through_with_context_by(archive_data, origin):
branches = _get_origin_branches(archive_data, origin)
branch_name = random.choice(list(branches.keys()))
@@ -759,7 +752,6 @@
) == archive.lookup_revision_with_context_by(origin["url"], branch_name, None, rev)
-@given(origin())
def test_lookup_revision_through_with_revision_by(archive_data, origin):
branches = _get_origin_branches(archive_data, origin)
branch_name = random.choice(list(branches.keys()))
@@ -952,7 +944,6 @@
assert actual_result == {missing_rev, missing_rel, missing_snp}
-@given(origin())
def test_lookup_origin_extra_trailing_slash(origin):
origin_info = archive.lookup_origin({"url": f"{origin['url']}/"})
assert origin_info["url"] == origin["url"]
@@ -973,7 +964,7 @@
assert origin_info["url"] == origin_url
-@given(origin(), new_origin())
+@given(new_origin())
def test_lookup_origins_get_by_sha1s(origin, unknown_origin):
hasher = hashlib.sha1()
hasher.update(origin["url"].encode("utf-8"))
@@ -994,13 +985,11 @@
assert origins == [origin_info, None]
-@given(origin())
def test_search_origin(origin):
results = archive.search_origin(url_pattern=origin["url"])[0]
assert results == [{"url": origin["url"]}]
-@given(origin())
def test_search_origin_use_ql(mocker, origin):
ORIGIN = [{"url": origin["url"]}]
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
@@ -25,13 +25,7 @@
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 (
- origin,
- origin_with_multiple_visits,
- release,
- revision,
- snapshot,
-)
+from swh.web.tests.strategies import release, revision, snapshot
def test_gen_swhid(content):
@@ -270,14 +264,15 @@
}
-@given(origin_with_multiple_visits())
-def test_get_swhids_info_origin_snapshot_context(archive_data, origin):
+def test_get_swhids_info_origin_snapshot_context(
+ archive_data, origin_with_multiple_visits
+):
"""
Test SWHIDs with contextual info computation under a variety of origin / snapshot
browsing contexts.
"""
-
- visits = archive_data.origin_visit_get(origin["url"])
+ origin_url = origin_with_multiple_visits["url"]
+ visits = archive_data.origin_visit_get(origin_url)
for visit in visits:
snapshot = archive_data.snapshot_get(visit["snapshot"])
@@ -327,12 +322,12 @@
{"anchor_type": ObjectType.REVISION, "anchor_id": revision_id},
),
(
- {"origin_url": origin["url"], "snapshot_id": snapshot_id},
+ {"origin_url": origin_url, "snapshot_id": snapshot_id},
{"anchor_type": ObjectType.REVISION, "anchor_id": head_rev_id},
),
(
{
- "origin_url": origin["url"],
+ "origin_url": origin_url,
"snapshot_id": snapshot_id,
"branch_name": branch_name,
},
@@ -343,7 +338,7 @@
),
(
{
- "origin_url": origin["url"],
+ "origin_url": origin_url,
"snapshot_id": snapshot_id,
"release_name": release_name,
},
@@ -351,7 +346,7 @@
),
(
{
- "origin_url": origin["url"],
+ "origin_url": origin_url,
"snapshot_id": snapshot_id,
"revision_id": revision_id,
},
@@ -429,10 +424,10 @@
expected_snp_context = {}
if "origin_url" in snp_ctx_params:
- expected_cnt_context["origin"] = origin["url"]
- expected_dir_context["origin"] = origin["url"]
- expected_rev_context["origin"] = origin["url"]
- expected_snp_context["origin"] = origin["url"]
+ expected_cnt_context["origin"] = origin_url
+ expected_dir_context["origin"] = origin_url
+ expected_rev_context["origin"] = origin_url
+ expected_snp_context["origin"] = origin_url
assert swhid_cnt_parsed.qualifiers() == expected_cnt_context
assert swhid_dir_parsed.qualifiers() == expected_dir_context
@@ -443,7 +438,6 @@
assert swhid_rel_parsed.qualifiers() == expected_rev_context
-@given(origin())
def test_get_swhids_info_characters_and_url_escaping(archive_data, directory, origin):
snapshot_context = get_snapshot_context(origin_url=origin["url"])
snapshot_context["origin_info"]["url"] = "http://example.org/?project=abc;def%"
@@ -472,9 +466,11 @@
assert parsed_url_swhid.qualifiers()["path"] == "/foo%253B/bar%2525"
-@given(origin_with_multiple_visits())
-def test_resolve_swhids_snapshot_context(client, archive_data, origin):
- visits = archive_data.origin_visit_get(origin["url"])
+def test_resolve_swhids_snapshot_context(
+ client, archive_data, origin_with_multiple_visits
+):
+ origin_url = origin_with_multiple_visits["url"]
+ visits = archive_data.origin_visit_get(origin_url)
visit = random.choice(visits)
snapshot = archive_data.snapshot_get(visit["snapshot"])
head_rev_id = archive_data.snapshot_get_head(snapshot)
@@ -512,7 +508,7 @@
{"revision_id": random_rev_id},
):
snapshot_context = get_snapshot_context(
- snapshot["id"], origin["url"], **snp_ctx_params
+ snapshot["id"], origin_url, **snp_ctx_params
)
_check_resolved_swhid_browse_url(
diff --git a/swh/web/tests/common/test_origin_visits.py b/swh/web/tests/common/test_origin_visits.py
--- a/swh/web/tests/common/test_origin_visits.py
+++ b/swh/web/tests/common/test_origin_visits.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2019 The Software Heritage developers
+# Copyright (C) 2018-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -14,11 +14,7 @@
from swh.web.common.exc import NotFoundExc
from swh.web.common.origin_visits import get_origin_visit, get_origin_visits
from swh.web.common.typing import OriginInfo
-from swh.web.tests.strategies import (
- new_origin,
- new_snapshots,
- origin_with_multiple_visits,
-)
+from swh.web.tests.strategies import new_origin, new_snapshots
@given(new_snapshots(3))
@@ -238,9 +234,8 @@
assert get_origin_visit((OriginInfo(url=new_origin.url))) == expected_visit
-@given(origin_with_multiple_visits())
-def test_get_origin_visit_latest_snapshot(mocker, origin):
- origin_visits = get_origin_visits(origin)
+def test_get_origin_visit_latest_snapshot(mocker, origin_with_multiple_visits):
+ origin_visits = get_origin_visits(origin_with_multiple_visits)
first_visit = origin_visits[0]
latest_visit = origin_visits[-1]
mock_get_origin_visits = mocker.patch(
@@ -248,10 +243,14 @@
)
mock_get_origin_visits.return_value = origin_visits
- visit = get_origin_visit(origin, snapshot_id=latest_visit["snapshot"])
+ visit = get_origin_visit(
+ origin_with_multiple_visits, snapshot_id=latest_visit["snapshot"]
+ )
assert visit == latest_visit
assert not mock_get_origin_visits.called
- visit = get_origin_visit(origin, snapshot_id=first_visit["snapshot"])
+ visit = get_origin_visit(
+ origin_with_multiple_visits, snapshot_id=first_visit["snapshot"]
+ )
assert visit == first_visit
assert mock_get_origin_visits.called
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
@@ -386,6 +386,53 @@
return Directory(entries=()).id.hex()
+@pytest.fixture(scope="function")
+def origin(tests_data):
+ """Fixturee returning a random origin ingested into the test archive.
+ """
+ return random.choice(_known_swh_objects(tests_data, "origins"))
+
+
+@pytest.fixture(scope="function")
+def origin_with_multiple_visits(tests_data):
+ """Fixture returning a random origin with multiple visits ingested
+ into the test archive.
+ """
+ origins = []
+ storage = tests_data["storage"]
+ for origin in tests_data["origins"]:
+ visit_page = storage.origin_visit_get(origin["url"])
+ if len(visit_page.results) > 1:
+ origins.append(origin)
+ return random.choice(origins)
+
+
+@pytest.fixture(scope="function")
+def origin_with_releases(tests_data):
+ """Fixture returning a random origin with releases ingested into the test archive.
+ """
+ origins = []
+ for origin in tests_data["origins"]:
+ snapshot = snapshot_get_latest(tests_data["storage"], origin["url"])
+ if any([b.target_type.value == "release" for b in snapshot.branches.values()]):
+ origins.append(origin)
+ return random.choice(origins)
+
+
+@pytest.fixture(scope="function")
+def origin_with_pull_request_branches(tests_data):
+ """Fixture returning a random origin with pull request branches ingested
+ into the test archive.
+ """
+ origins = []
+ storage = tests_data["storage"]
+ for origin in storage.origin_list(limit=1000).results:
+ snapshot = snapshot_get_latest(storage, origin.url)
+ if any([b"refs/pull/" in b for b in snapshot.branches]):
+ origins.append(origin)
+ return random.choice(origins)
+
+
def _object_type_swhid(tests_data, object_type):
return random.choice(
list(
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
@@ -1,4 +1,4 @@
-# Copyright (C) 2019-2020 The Software Heritage developers
+# Copyright (C) 2019-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -16,7 +16,6 @@
from swh.web.tests.strategies import (
invalid_sha1,
new_origin,
- origin,
release,
revision,
snapshot,
@@ -37,7 +36,6 @@
_test_badge_endpoints(client, "directory", directory)
-@given(origin())
def test_origin_badge(client, origin):
_test_badge_endpoints(client, "origin", origin["url"])
@@ -114,7 +112,7 @@
_check_generated_badge(resp, "", "", error="invalid id")
-@given(origin(), release())
+@given(release())
def test_badge_endpoints_have_cors_header(client, origin, release):
url = reverse(
"swh-badge", url_args={"object_type": "origin", "object_id": origin["url"]}
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
@@ -118,59 +118,6 @@
)
-def origin():
- """
- Hypothesis strategy returning a random origin ingested
- into the test archive.
- """
- return _known_swh_object("origins")
-
-
-def origin_with_multiple_visits():
- """
- Hypothesis strategy returning a random origin ingested
- into the test archive.
- """
- ret = []
- tests_data = get_tests_data()
- storage = tests_data["storage"]
- for origin in tests_data["origins"]:
- visit_page = storage.origin_visit_get(origin["url"])
- if len(visit_page.results) > 1:
- ret.append(origin)
- return sampled_from(ret)
-
-
-def origin_with_releases():
- """
- Hypothesis strategy returning a random origin ingested
- into the test archive.
- """
- ret = []
- tests_data = get_tests_data()
- for origin in tests_data["origins"]:
- snapshot = snapshot_get_latest(tests_data["storage"], origin["url"])
- if any([b.target_type.value == "release" for b in snapshot.branches.values()]):
- ret.append(origin)
- return sampled_from(ret)
-
-
-def origin_with_pull_request_branches():
- """
- Hypothesis strategy returning a random origin with pull request branches
- ingested into the test archive.
- """
- ret = []
- tests_data = get_tests_data()
- storage = tests_data["storage"]
- origins = storage.origin_list(limit=1000)
- for origin in origins.results:
- snapshot = snapshot_get_latest(storage, origin.url)
- if any([b"refs/pull/" in b for b in snapshot.branches]):
- ret.append(origin)
- return sampled_from(ret)
-
-
def new_origin():
"""
Hypothesis strategy returning a random origin not ingested