Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_origin.py
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | _origin_content_view_test_helper( | ||||
origin_visits[-1], | origin_visits[-1], | ||||
tdata["branches"], | tdata["branches"], | ||||
tdata["releases"], | tdata["releases"], | ||||
tdata["root_dir_sha1"], | tdata["root_dir_sha1"], | ||||
tdata["content"], | tdata["content"], | ||||
timestamp=visit_unix_ts, | timestamp=visit_unix_ts, | ||||
) | ) | ||||
_origin_content_view_test_helper( | |||||
client, | |||||
archive_data, | |||||
origin, | |||||
origin_visits[-1], | |||||
tdata["branches"], | |||||
tdata["releases"], | |||||
tdata["root_dir_sha1"], | |||||
tdata["content"], | |||||
snapshot_id=tdata["visit"]["snapshot"], | |||||
) | |||||
tdata = _get_archive_data(0) | tdata = _get_archive_data(0) | ||||
_origin_content_view_test_helper( | _origin_content_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
origin_visits[0], | origin_visits[0], | ||||
tdata["branches"], | tdata["branches"], | ||||
tdata["releases"], | tdata["releases"], | ||||
tdata["root_dir_sha1"], | tdata["root_dir_sha1"], | ||||
tdata["content"], | tdata["content"], | ||||
visit_id=tdata["visit"]["visit"], | visit_id=tdata["visit"]["visit"], | ||||
) | ) | ||||
_origin_content_view_test_helper( | |||||
client, | |||||
archive_data, | |||||
origin, | |||||
origin_visits[0], | |||||
tdata["branches"], | |||||
tdata["releases"], | |||||
tdata["root_dir_sha1"], | |||||
tdata["content"], | |||||
snapshot_id=tdata["visit"]["snapshot"], | |||||
) | |||||
@given(origin()) | @given(origin()) | ||||
def test_origin_root_directory_view(client, archive_data, origin): | def test_origin_root_directory_view(client, archive_data, origin): | ||||
origin_visits = archive_data.origin_visit_get(origin["url"]) | origin_visits = archive_data.origin_visit_get(origin["url"]) | ||||
visit = origin_visits[-1] | visit = origin_visits[-1] | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
head_rev_id = archive_data.snapshot_get_head(snapshot) | head_rev_id = archive_data.snapshot_get_head(snapshot) | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | _origin_directory_view_test_helper( | ||||
visit, | visit, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
origin = dict(origin) | _origin_directory_view_test_helper( | ||||
del origin["type"] | client, | ||||
archive_data, | |||||
origin, | |||||
visit, | |||||
branches, | |||||
releases, | |||||
root_dir_sha1, | |||||
dir_content, | |||||
snapshot_id=visit["snapshot"], | |||||
) | |||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
Show All 32 Lines | _origin_directory_view_test_helper( | ||||
visit, | visit, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
dir_content, | dir_content, | ||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | |||||
client, | |||||
archive_data, | |||||
origin, | |||||
visit, | |||||
branches, | |||||
releases, | |||||
root_dir_sha1, | |||||
dir_content, | |||||
snapshot_id=visit["snapshot"], | |||||
) | |||||
@given(origin()) | @given(origin()) | ||||
def test_origin_sub_directory_view(client, archive_data, origin): | def test_origin_sub_directory_view(client, archive_data, origin): | ||||
origin_visits = archive_data.origin_visit_get(origin["url"]) | origin_visits = archive_data.origin_visit_get(origin["url"]) | ||||
visit = origin_visits[-1] | visit = origin_visits[-1] | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
head_rev_id = archive_data.snapshot_get_head(snapshot) | head_rev_id = archive_data.snapshot_get_head(snapshot) | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | _origin_directory_view_test_helper( | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
origin = dict(origin) | _origin_directory_view_test_helper( | ||||
del origin["type"] | client, | ||||
archive_data, | |||||
origin, | |||||
visit, | |||||
branches, | |||||
releases, | |||||
root_dir_sha1, | |||||
subdir_content, | |||||
path=subdir_path, | |||||
snapshot_id=visit["snapshot"], | |||||
) | |||||
_origin_directory_view_test_helper( | _origin_directory_view_test_helper( | ||||
client, | client, | ||||
archive_data, | archive_data, | ||||
origin, | origin, | ||||
visit, | visit, | ||||
branches, | branches, | ||||
releases, | releases, | ||||
Show All 36 Lines | _origin_directory_view_test_helper( | ||||
branches, | branches, | ||||
releases, | releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
subdir_content, | subdir_content, | ||||
path=subdir_path, | path=subdir_path, | ||||
timestamp=visit["date"], | timestamp=visit["date"], | ||||
) | ) | ||||
_origin_directory_view_test_helper( | |||||
client, | |||||
archive_data, | |||||
origin, | |||||
visit, | |||||
branches, | |||||
releases, | |||||
root_dir_sha1, | |||||
subdir_content, | |||||
path=subdir_path, | |||||
snapshot_id=visit["snapshot"], | |||||
) | |||||
@given(origin()) | @given(origin()) | ||||
def test_origin_branches(client, archive_data, origin): | def test_origin_branches(client, archive_data, origin): | ||||
origin_visits = archive_data.origin_visit_get(origin["url"]) | origin_visits = archive_data.origin_visit_get(origin["url"]) | ||||
visit = origin_visits[-1] | visit = origin_visits[-1] | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
snapshot_content = process_snapshot_branches(snapshot) | snapshot_content = process_snapshot_branches(snapshot) | ||||
_origin_branches_test_helper(client, origin, snapshot_content) | _origin_branches_test_helper(client, origin, snapshot_content) | ||||
origin = dict(origin) | _origin_branches_test_helper( | ||||
origin["type"] = None | client, origin, snapshot_content, snapshot_id=visit["snapshot"] | ||||
) | |||||
_origin_branches_test_helper(client, origin, snapshot_content) | |||||
@given(origin()) | @given(origin()) | ||||
def test_origin_releases(client, archive_data, origin): | def test_origin_releases(client, archive_data, origin): | ||||
origin_visits = archive_data.origin_visit_get(origin["url"]) | origin_visits = archive_data.origin_visit_get(origin["url"]) | ||||
visit = origin_visits[-1] | visit = origin_visits[-1] | ||||
snapshot = archive_data.snapshot_get(visit["snapshot"]) | snapshot = archive_data.snapshot_get(visit["snapshot"]) | ||||
snapshot_content = process_snapshot_branches(snapshot) | snapshot_content = process_snapshot_branches(snapshot) | ||||
_origin_releases_test_helper(client, origin, snapshot_content) | _origin_releases_test_helper(client, origin, snapshot_content) | ||||
origin = dict(origin) | _origin_releases_test_helper( | ||||
origin["type"] = None | client, origin, snapshot_content, snapshot_id=visit["snapshot"] | ||||
) | |||||
_origin_releases_test_helper(client, origin, snapshot_content) | |||||
@given( | @given( | ||||
new_origin(), | new_origin(), | ||||
new_snapshot(min_size=4, max_size=4), | new_snapshot(min_size=4, max_size=4), | ||||
visit_dates(), | visit_dates(), | ||||
revisions(min_size=3, max_size=3), | revisions(min_size=3, max_size=3), | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 340 Lines • ▼ Show 20 Lines | def _origin_content_view_test_helper( | ||||
origin_info, | origin_info, | ||||
origin_visit, | origin_visit, | ||||
origin_branches, | origin_branches, | ||||
origin_releases, | origin_releases, | ||||
root_dir_sha1, | root_dir_sha1, | ||||
content, | content, | ||||
visit_id=None, | visit_id=None, | ||||
timestamp=None, | timestamp=None, | ||||
snapshot_id=None, | |||||
): | ): | ||||
content_path = "/".join(content["path"].split("/")[1:]) | content_path = "/".join(content["path"].split("/")[1:]) | ||||
if not visit_id: | if not visit_id and not snapshot_id: | ||||
visit_id = origin_visit["visit"] | visit_id = origin_visit["visit"] | ||||
query_params = {"origin_url": origin_info["url"], "path": content_path} | query_params = {"origin_url": origin_info["url"], "path": content_path} | ||||
if timestamp: | if timestamp: | ||||
query_params["timestamp"] = timestamp | query_params["timestamp"] = timestamp | ||||
if visit_id: | if visit_id: | ||||
query_params["visit_id"] = visit_id | query_params["visit_id"] = visit_id | ||||
elif snapshot_id: | |||||
query_params["snapshot"] = snapshot_id | |||||
url = reverse("browse-origin-content", query_params=query_params) | url = reverse("browse-origin-content", query_params=query_params) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/content.html") | assert_template_used(resp, "browse/content.html") | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | def _origin_directory_view_test_helper( | ||||
origin_info, | origin_info, | ||||
origin_visit, | origin_visit, | ||||
origin_branches, | origin_branches, | ||||
origin_releases, | origin_releases, | ||||
root_directory_sha1, | root_directory_sha1, | ||||
directory_entries, | directory_entries, | ||||
visit_id=None, | visit_id=None, | ||||
timestamp=None, | timestamp=None, | ||||
snapshot_id=None, | |||||
path=None, | path=None, | ||||
): | ): | ||||
dirs = [e for e in directory_entries if e["type"] in ("dir", "rev")] | dirs = [e for e in directory_entries if e["type"] in ("dir", "rev")] | ||||
files = [e for e in directory_entries if e["type"] == "file"] | files = [e for e in directory_entries if e["type"] == "file"] | ||||
if not visit_id: | if not visit_id and not snapshot_id: | ||||
visit_id = origin_visit["visit"] | visit_id = origin_visit["visit"] | ||||
query_params = {"origin_url": origin_info["url"]} | query_params = {"origin_url": origin_info["url"]} | ||||
if timestamp: | if timestamp: | ||||
query_params["timestamp"] = timestamp | query_params["timestamp"] = timestamp | ||||
else: | elif visit_id: | ||||
query_params["visit_id"] = visit_id | query_params["visit_id"] = visit_id | ||||
else: | |||||
query_params["snapshot"] = snapshot_id | |||||
if path: | if path: | ||||
query_params["path"] = path | query_params["path"] = path | ||||
url = reverse("browse-origin-directory", query_params=query_params) | url = reverse("browse-origin-directory", query_params=query_params) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | ): | ||||
assert_contains(resp, swh_dir_id) | assert_contains(resp, swh_dir_id) | ||||
assert_contains(resp, swh_dir_id_url) | assert_contains(resp, swh_dir_id_url) | ||||
assert_contains(resp, "swh-take-new-snapshot") | assert_contains(resp, "swh-take-new-snapshot") | ||||
_check_origin_view_title(resp, origin_info["url"], "directory") | _check_origin_view_title(resp, origin_info["url"], "directory") | ||||
def _origin_branches_test_helper(client, origin_info, origin_snapshot): | def _origin_branches_test_helper( | ||||
query_params = {"origin_url": origin_info["url"]} | client, origin_info, origin_snapshot, snapshot_id=None | ||||
): | |||||
query_params = {"origin_url": origin_info["url"], "snapshot": snapshot_id} | |||||
url = reverse("browse-origin-branches", query_params=query_params) | url = reverse("browse-origin-branches", query_params=query_params) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/branches.html") | assert_template_used(resp, "browse/branches.html") | ||||
origin_branches = origin_snapshot[0] | origin_branches = origin_snapshot[0] | ||||
origin_releases = origin_snapshot[1] | origin_releases = origin_snapshot[1] | ||||
origin_branches_url = reverse("browse-origin-branches", query_params=query_params) | origin_branches_url = reverse("browse-origin-branches", query_params=query_params) | ||||
assert_contains( | assert_contains( | ||||
resp, | resp, | ||||
'<a href="%s">Branches (%s)</a>' % (origin_branches_url, len(origin_branches)), | '<a href="%s">Branches (%s)</a>' | ||||
% (escape(origin_branches_url), len(origin_branches)), | |||||
) | ) | ||||
origin_releases_url = reverse("browse-origin-releases", query_params=query_params) | origin_releases_url = reverse("browse-origin-releases", query_params=query_params) | ||||
nb_releases = len(origin_releases) | nb_releases = len(origin_releases) | ||||
if nb_releases > 0: | if nb_releases > 0: | ||||
assert_contains( | assert_contains( | ||||
resp, '<a href="%s">Releases (%s)</a>' % (origin_releases_url, nb_releases) | resp, | ||||
'<a href="%s">Releases (%s)</a>' | |||||
% (escape(origin_releases_url), nb_releases), | |||||
) | ) | ||||
assert_contains(resp, '<tr class="swh-branch-entry', count=len(origin_branches)) | assert_contains(resp, '<tr class="swh-branch-entry', count=len(origin_branches)) | ||||
for branch in origin_branches: | for branch in origin_branches: | ||||
browse_branch_url = reverse( | browse_branch_url = reverse( | ||||
"browse-origin-directory", | "browse-origin-directory", | ||||
query_params={"origin_url": origin_info["url"], "branch": branch["name"]}, | query_params={"branch": branch["name"], **query_params}, | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">' % escape(browse_branch_url)) | assert_contains(resp, '<a href="%s">' % escape(browse_branch_url)) | ||||
browse_revision_url = reverse( | browse_revision_url = reverse( | ||||
"browse-revision", | "browse-revision", | ||||
url_args={"sha1_git": branch["revision"]}, | url_args={"sha1_git": branch["revision"]}, | ||||
query_params={"origin_url": origin_info["url"]}, | query_params=query_params, | ||||
) | ) | ||||
assert_contains(resp, '<a href="%s">' % escape(browse_revision_url)) | assert_contains(resp, '<a href="%s">' % escape(browse_revision_url)) | ||||
_check_origin_view_title(resp, origin_info["url"], "branches") | _check_origin_view_title(resp, origin_info["url"], "branches") | ||||
def _origin_releases_test_helper(client, origin_info, origin_snapshot): | def _origin_releases_test_helper( | ||||
query_params = {"origin_url": origin_info["url"]} | client, origin_info, origin_snapshot, snapshot_id=None | ||||
): | |||||
query_params = {"origin_url": origin_info["url"], "snapshot": snapshot_id} | |||||
url = reverse("browse-origin-releases", query_params=query_params) | url = reverse("browse-origin-releases", query_params=query_params) | ||||
resp = client.get(url) | resp = client.get(url) | ||||
assert resp.status_code == 200 | assert resp.status_code == 200 | ||||
assert_template_used(resp, "browse/releases.html") | assert_template_used(resp, "browse/releases.html") | ||||
origin_branches = origin_snapshot[0] | origin_branches = origin_snapshot[0] | ||||
origin_releases = origin_snapshot[1] | origin_releases = origin_snapshot[1] | ||||
origin_branches_url = reverse("browse-origin-branches", query_params=query_params) | origin_branches_url = reverse("browse-origin-branches", query_params=query_params) | ||||
assert_contains( | assert_contains( | ||||
resp, | resp, | ||||
'<a href="%s">Branches (%s)</a>' % (origin_branches_url, len(origin_branches)), | '<a href="%s">Branches (%s)</a>' | ||||
% (escape(origin_branches_url), len(origin_branches)), | |||||
) | ) | ||||
origin_releases_url = reverse("browse-origin-releases", query_params=query_params) | origin_releases_url = reverse("browse-origin-releases", query_params=query_params) | ||||
nb_releases = len(origin_releases) | nb_releases = len(origin_releases) | ||||
if nb_releases > 0: | if nb_releases > 0: | ||||
assert_contains( | assert_contains( | ||||
resp, '<a href="%s">Releases (%s)</a>' % (origin_releases_url, nb_releases) | resp, | ||||
'<a href="%s">Releases (%s)</a>' | |||||
% (escape(origin_releases_url), nb_releases), | |||||
) | ) | ||||
assert_contains(resp, '<tr class="swh-release-entry', count=nb_releases) | assert_contains(resp, '<tr class="swh-release-entry', count=nb_releases) | ||||
for release in origin_releases: | for release in origin_releases: | ||||
browse_release_url = reverse( | browse_release_url = reverse( | ||||
"browse-release", | "browse-release", | ||||
url_args={"sha1_git": release["id"]}, | url_args={"sha1_git": release["id"]}, | ||||
query_params={"origin_url": origin_info["url"]}, | query_params=query_params, | ||||
) | ) | ||||
browse_revision_url = reverse( | browse_revision_url = reverse( | ||||
"browse-revision", | "browse-revision", | ||||
url_args={"sha1_git": release["target"]}, | url_args={"sha1_git": release["target"]}, | ||||
query_params={"origin_url": origin_info["url"]}, | query_params=query_params, | ||||
) | ) | ||||
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_view_title(resp, origin_info["url"], "releases") | _check_origin_view_title(resp, origin_info["url"], "releases") | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |