Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_origin.py
Show All 30 Lines | from swh.web.common.utils import ( | ||||
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 ( | from swh.web.tests.strategies import ( | ||||
new_origin, | new_origin, | ||||
new_snapshot, | new_snapshot, | ||||
revisions, | |||||
unknown_revision, | unknown_revision, | ||||
visit_dates, | 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"] | ||||
▲ Show 20 Lines • Show All 380 Lines • ▼ Show 20 Lines | def test_origin_releases(client, archive_data, origin): | ||||
_origin_releases_test_helper(client, origin, snapshot_content, snapshot_sizes) | _origin_releases_test_helper(client, origin, snapshot_content, snapshot_sizes) | ||||
_origin_releases_test_helper( | _origin_releases_test_helper( | ||||
client, origin, snapshot_content, snapshot_sizes, snapshot_id=visit["snapshot"] | client, origin, snapshot_content, snapshot_sizes, snapshot_id=visit["snapshot"] | ||||
) | ) | ||||
@given( | @given( | ||||
new_origin(), | new_origin(), new_snapshot(min_size=4, max_size=4), visit_dates(), | ||||
new_snapshot(min_size=4, max_size=4), | |||||
visit_dates(), | |||||
revisions(min_size=3, max_size=3), | |||||
) | ) | ||||
def test_origin_snapshot_null_branch( | def test_origin_snapshot_null_branch( | ||||
client, archive_data, new_origin, new_snapshot, visit_dates, revisions | client, archive_data, revisions_list, new_origin, new_snapshot, visit_dates, | ||||
): | ): | ||||
revisions = revisions_list(size=4) | |||||
snp_dict = new_snapshot.to_dict() | snp_dict = new_snapshot.to_dict() | ||||
archive_data.origin_add([new_origin]) | archive_data.origin_add([new_origin]) | ||||
for i, branch in enumerate(snp_dict["branches"].keys()): | for i, branch in enumerate(snp_dict["branches"].keys()): | ||||
if i == 0: | if i == 0: | ||||
snp_dict["branches"][branch] = None | snp_dict["branches"][branch] = None | ||||
else: | else: | ||||
snp_dict["branches"][branch] = { | snp_dict["branches"][branch] = { | ||||
"target_type": "revision", | "target_type": "revision", | ||||
Show All 18 Lines | ): | ||||
) | ) | ||||
check_html_get_response( | check_html_get_response( | ||||
client, url, status_code=200, template_used="browse/directory.html" | client, url, status_code=200, template_used="browse/directory.html" | ||||
) | ) | ||||
@given( | @given( | ||||
new_origin(), | new_origin(), new_snapshot(min_size=4, max_size=4), visit_dates(), | ||||
new_snapshot(min_size=4, max_size=4), | |||||
visit_dates(), | |||||
revisions(min_size=4, max_size=4), | |||||
) | ) | ||||
def test_origin_snapshot_invalid_branch( | def test_origin_snapshot_invalid_branch( | ||||
client, archive_data, new_origin, new_snapshot, visit_dates, revisions | client, archive_data, revisions_list, new_origin, new_snapshot, visit_dates, | ||||
): | ): | ||||
revisions = revisions_list(size=4) | |||||
snp_dict = new_snapshot.to_dict() | snp_dict = new_snapshot.to_dict() | ||||
archive_data.origin_add([new_origin]) | archive_data.origin_add([new_origin]) | ||||
for i, branch in enumerate(snp_dict["branches"].keys()): | for i, branch in enumerate(snp_dict["branches"].keys()): | ||||
snp_dict["branches"][branch] = { | snp_dict["branches"][branch] = { | ||||
"target_type": "revision", | "target_type": "revision", | ||||
"target": hash_to_bytes(revisions[i]), | "target": hash_to_bytes(revisions[i]), | ||||
} | } | ||||
▲ Show 20 Lines • Show All 734 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), | new_origin(), visit_dates(), | ||||
) | ) | ||||
def test_origin_branches_pagination_with_alias( | def test_origin_branches_pagination_with_alias( | ||||
client, archive_data, mocker, release, new_origin, visit_dates, revisions, | client, archive_data, mocker, release, revisions_list, new_origin, visit_dates, | ||||
): | ): | ||||
""" | """ | ||||
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. | ||||
""" | """ | ||||
revisions = revisions_list(size=10) | |||||
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]), | ||||
} | } | ||||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |