Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_origin.py
Show All 27 Lines | |||||
from swh.web.common.utils import ( | from swh.web.common.utils import ( | ||||
format_utc_iso_date, | format_utc_iso_date, | ||||
gen_path_info, | gen_path_info, | ||||
parse_iso8601_date_to_utc, | parse_iso8601_date_to_utc, | ||||
reverse, | reverse, | ||||
) | ) | ||||
from swh.web.tests.data import get_content, random_sha1 | 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.django_asserts import assert_contains, assert_not_contains | ||||
from swh.web.tests.strategies import new_origin, new_snapshot | from swh.web.tests.strategies import ( | ||||
from swh.web.tests.strategies import release as existing_release | new_origin, | ||||
from swh.web.tests.strategies import revisions, unknown_revision, visit_dates | new_snapshot, | ||||
revisions, | |||||
unknown_revision, | |||||
visit_dates, | |||||
) | |||||
from swh.web.tests.utils import check_html_get_response | from swh.web.tests.utils import check_html_get_response | ||||
def test_origin_visits_browse(client, archive_data, origin_with_multiple_visits): | def test_origin_visits_browse(client, archive_data, origin_with_multiple_visits): | ||||
origin_url = origin_with_multiple_visits["url"] | origin_url = origin_with_multiple_visits["url"] | ||||
url = reverse("browse-origin-visits", query_params={"origin_url": origin_url}) | url = reverse("browse-origin-visits", query_params={"origin_url": origin_url}) | ||||
resp = check_html_get_response( | resp = check_html_get_response( | ||||
▲ Show 20 Lines • Show All 1,177 Lines • ▼ Show 20 Lines | for release in origin_releases: | ||||
assert_contains(resp, '<a href="%s">' % escape(browse_release_url)) | assert_contains(resp, '<a href="%s">' % escape(browse_release_url)) | ||||
assert_contains(resp, '<a href="%s">' % escape(browse_revision_url)) | assert_contains(resp, '<a href="%s">' % escape(browse_revision_url)) | ||||
_check_origin_link(resp, origin_info["url"]) | _check_origin_link(resp, origin_info["url"]) | ||||
@given( | @given( | ||||
new_origin(), visit_dates(), revisions(min_size=10, max_size=10), existing_release() | new_origin(), visit_dates(), revisions(min_size=10, max_size=10), | ||||
) | ) | ||||
def test_origin_branches_pagination_with_alias( | def test_origin_branches_pagination_with_alias( | ||||
client, archive_data, mocker, new_origin, visit_dates, revisions, existing_release | client, archive_data, mocker, release, new_origin, visit_dates, revisions, | ||||
): | ): | ||||
""" | """ | ||||
When a snapshot contains a branch or a release alias, pagination links | When a snapshot contains a branch or a release alias, pagination links | ||||
in the branches / releases view should be displayed. | in the branches / releases view should be displayed. | ||||
""" | """ | ||||
mocker.patch("swh.web.browse.snapshot_context.PER_PAGE", len(revisions) / 2) | mocker.patch("swh.web.browse.snapshot_context.PER_PAGE", len(revisions) / 2) | ||||
snp_dict = {"branches": {}, "id": hash_to_bytes(random_sha1())} | snp_dict = {"branches": {}, "id": hash_to_bytes(random_sha1())} | ||||
for i in range(len(revisions)): | for i in range(len(revisions)): | ||||
branch = "".join(random.choices(string.ascii_lowercase, k=8)) | branch = "".join(random.choices(string.ascii_lowercase, k=8)) | ||||
snp_dict["branches"][branch.encode()] = { | snp_dict["branches"][branch.encode()] = { | ||||
"target_type": "revision", | "target_type": "revision", | ||||
"target": hash_to_bytes(revisions[i]), | "target": hash_to_bytes(revisions[i]), | ||||
} | } | ||||
release = "".join(random.choices(string.ascii_lowercase, k=8)) | release_name = "".join(random.choices(string.ascii_lowercase, k=8)) | ||||
snp_dict["branches"][b"RELEASE_ALIAS"] = { | snp_dict["branches"][b"RELEASE_ALIAS"] = { | ||||
"target_type": "alias", | "target_type": "alias", | ||||
"target": release.encode(), | "target": release_name.encode(), | ||||
} | } | ||||
snp_dict["branches"][release.encode()] = { | snp_dict["branches"][release_name.encode()] = { | ||||
"target_type": "release", | "target_type": "release", | ||||
"target": hash_to_bytes(existing_release), | "target": hash_to_bytes(release), | ||||
} | } | ||||
archive_data.origin_add([new_origin]) | archive_data.origin_add([new_origin]) | ||||
archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | archive_data.snapshot_add([Snapshot.from_dict(snp_dict)]) | ||||
visit = archive_data.origin_visit_add( | visit = archive_data.origin_visit_add( | ||||
[OriginVisit(origin=new_origin.url, date=visit_dates[0], type="git",)] | [OriginVisit(origin=new_origin.url, date=visit_dates[0], type="git",)] | ||||
)[0] | )[0] | ||||
visit_status = OriginVisitStatus( | visit_status = OriginVisitStatus( | ||||
origin=new_origin.url, | origin=new_origin.url, | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |