Page MenuHomeSoftware Heritage

D3135.id11148.diff
No OneTemporary

D3135.id11148.diff

diff --git a/cypress/integration/persistent-identifiers.spec.js b/cypress/integration/persistent-identifiers.spec.js
--- a/cypress/integration/persistent-identifiers.spec.js
+++ b/cypress/integration/persistent-identifiers.spec.js
@@ -7,12 +7,11 @@
let origin, originBadgeUrl, originBrowseUrl;
let url, urlPrefix;
-let browsedObjectMetadata;
-let cntPid, cntPidWithOrigin, cntPidWithOriginAndLines;
-let dirPid, dirPidWithOrigin;
-let relPid, relPidWithOrigin;
-let revPid, revPidWithOrigin;
-let snpPid, snpPidWithOrigin;
+let cntSWHID, cntSWHIDWithContext;
+let dirSWHID, dirSWHIDWithContext;
+let relSWHID, relSWHIDWithContext;
+let revSWHID, revSWHIDWithContext;
+let snpSWHID, snpSWHIDWithContext;
let testsData;
const firstSelLine = 6;
const lastSelLine = 12;
@@ -30,54 +29,54 @@
if (win.location.port) {
urlPrefix += `:${win.location.port}`;
}
- browsedObjectMetadata = win.swh.webapp.getBrowsedSwhObjectMetadata();
- cntPid = `swh:1:cnt:${browsedObjectMetadata.sha1_git}`;
- cntPidWithOrigin = `${cntPid};origin=${origin.url}`;
- cntPidWithOriginAndLines = `${cntPidWithOrigin};lines=${firstSelLine}-${lastSelLine}`;
- dirPid = `swh:1:dir:${browsedObjectMetadata.directory}`;
- dirPidWithOrigin = `${dirPid};origin=${origin.url}`;
- revPid = `swh:1:rev:${browsedObjectMetadata.revision}`;
- revPidWithOrigin = `${revPid};origin=${origin.url}`;
- relPid = `swh:1:rel:${browsedObjectMetadata.release}`;
- relPidWithOrigin = `${relPid};origin=${origin.url}`;
- snpPid = `swh:1:snp:${browsedObjectMetadata.snapshot}`;
- snpPidWithOrigin = `${snpPid};origin=${origin.url}`;
+ const swhids = win.swh.webapp.getSwhIdsContext();
+ cntSWHID = swhids.content.swhid;
+ cntSWHIDWithContext = swhids.content.swhid_with_context;
+ cntSWHIDWithContext += `;lines=${firstSelLine}-${lastSelLine}`;
+ dirSWHID = swhids.directory.swhid;
+ dirSWHIDWithContext = swhids.directory.swhid_with_context;
+ revSWHID = swhids.revision.swhid;
+ revSWHIDWithContext = swhids.revision.swhid_with_context;
+ relSWHID = swhids.release.swhid;
+ relSWHIDWithContext = swhids.release.swhid_with_context;
+ snpSWHID = swhids.snapshot.swhid;
+ snpSWHIDWithContext = swhids.snapshot.swhid_with_context;
testsData = [
{
'objectType': 'content',
- 'objectPids': [cntPidWithOriginAndLines, cntPidWithOrigin, cntPid],
- 'badgeUrl': this.Urls.swh_badge('content', browsedObjectMetadata.sha1_git),
- 'badgePidUrl': this.Urls.swh_badge_pid(cntPidWithOriginAndLines),
- 'browseUrl': this.Urls.browse_swh_id(cntPidWithOriginAndLines)
+ 'objectPids': [cntSWHIDWithContext, cntSWHID],
+ 'badgeUrl': this.Urls.swh_badge('content', swhids.content.object_id),
+ 'badgePidUrl': this.Urls.swh_badge_pid(cntSWHID),
+ 'browseUrl': this.Urls.browse_swh_id(cntSWHIDWithContext)
},
{
'objectType': 'directory',
- 'objectPids': [dirPidWithOrigin, dirPid],
- 'badgeUrl': this.Urls.swh_badge('directory', browsedObjectMetadata.directory),
- 'badgePidUrl': this.Urls.swh_badge_pid(dirPidWithOrigin),
- 'browseUrl': this.Urls.browse_swh_id(dirPidWithOrigin)
+ 'objectPids': [dirSWHIDWithContext, dirSWHID],
+ 'badgeUrl': this.Urls.swh_badge('directory', swhids.directory.object_id),
+ 'badgePidUrl': this.Urls.swh_badge_pid(dirSWHID),
+ 'browseUrl': this.Urls.browse_swh_id(dirSWHIDWithContext)
},
{
'objectType': 'release',
- 'objectPids': [relPidWithOrigin, relPid],
- 'badgeUrl': this.Urls.swh_badge('release', browsedObjectMetadata.release),
- 'badgePidUrl': this.Urls.swh_badge_pid(relPidWithOrigin),
- 'browseUrl': this.Urls.browse_swh_id(relPidWithOrigin)
+ 'objectPids': [relSWHIDWithContext, relSWHID],
+ 'badgeUrl': this.Urls.swh_badge('release', swhids.release.object_id),
+ 'badgePidUrl': this.Urls.swh_badge_pid(relSWHID),
+ 'browseUrl': this.Urls.browse_swh_id(relSWHIDWithContext)
},
{
'objectType': 'revision',
- 'objectPids': [revPidWithOrigin, revPid],
- 'badgeUrl': this.Urls.swh_badge('revision', browsedObjectMetadata.revision),
- 'badgePidUrl': this.Urls.swh_badge_pid(revPidWithOrigin),
- 'browseUrl': this.Urls.browse_swh_id(revPidWithOrigin)
+ 'objectPids': [revSWHIDWithContext, revSWHID],
+ 'badgeUrl': this.Urls.swh_badge('revision', swhids.revision.object_id),
+ 'badgePidUrl': this.Urls.swh_badge_pid(revSWHID),
+ 'browseUrl': this.Urls.browse_swh_id(revSWHIDWithContext)
},
{
'objectType': 'snapshot',
- 'objectPids': [snpPidWithOrigin, snpPid],
- 'badgeUrl': this.Urls.swh_badge('snapshot', browsedObjectMetadata.snapshot),
- 'badgePidUrl': this.Urls.swh_badge_pid(snpPidWithOrigin),
- 'browseUrl': this.Urls.browse_swh_id(snpPidWithOrigin)
+ 'objectPids': [snpSWHIDWithContext, snpSWHID],
+ 'badgeUrl': this.Urls.swh_badge('snapshot', swhids.snapshot.object_id),
+ 'badgePidUrl': this.Urls.swh_badge_pid(snpSWHID),
+ 'browseUrl': this.Urls.browse_swh_id(snpSWHIDWithContext)
}
];
@@ -125,53 +124,12 @@
});
- it('should update content identifier metadata when toggling option checkboxes', function() {
- cy.get('.ui-slideouttab-handle')
- .click();
-
- cy.get(`#swh-id-tab-content .swh-id`)
- .contains(cntPidWithOriginAndLines)
- .should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOriginAndLines));
-
- cy.get('#swh-id-tab-content .swh-id-option-lines')
- .click();
-
- cy.get(`#swh-id-tab-content .swh-id`)
- .contains(cntPidWithOrigin)
- .should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOrigin));
-
- cy.get('#swh-id-tab-content .swh-id-option-origin')
- .click();
-
- cy.get(`#swh-id-tab-content .swh-id`)
- .contains(cntPid)
- .should('have.attr', 'href', this.Urls.browse_swh_id(cntPid));
-
- cy.get('#swh-id-tab-content .swh-id-option-origin')
- .click();
-
- cy.get(`#swh-id-tab-content .swh-id`)
- .contains(cntPidWithOrigin)
- .should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOrigin));
-
- cy.get('#swh-id-tab-content .swh-id-option-lines')
- .click();
-
- cy.get(`#swh-id-tab-content .swh-id`)
- .contains(cntPidWithOriginAndLines)
- .should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOriginAndLines));
-
- });
-
- it('should update other object identifiers metadata when toggling option checkboxes', function() {
+ it('should update other object identifiers contextual info when toggling context checkbox', function() {
cy.get('.ui-slideouttab-handle')
.click();
for (let td of testsData) {
- // already tested
- if (td.objectType === 'content') continue;
-
cy.get(`a[href="#swh-id-tab-${td.objectType}"]`)
.click();
@@ -179,14 +137,14 @@
.contains(td.objectPids[0])
.should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0]));
- cy.get(`#swh-id-tab-${td.objectType} .swh-id-option-origin`)
+ cy.get(`#swh-id-tab-${td.objectType} .swh-id-context-option`)
.click();
cy.get(`#swh-id-tab-${td.objectType} .swh-id`)
.contains(td.objectPids[1])
.should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[1]));
- cy.get(`#swh-id-tab-${td.objectType} .swh-id-option-origin`)
+ cy.get(`#swh-id-tab-${td.objectType} .swh-id-context-option`)
.click();
cy.get(`#swh-id-tab-${td.objectType} .swh-id`)
diff --git a/swh/web/assets/src/bundles/browse/swh-ids-utils.js b/swh/web/assets/src/bundles/browse/swh-ids-utils.js
--- a/swh/web/assets/src/bundles/browse/swh-ids-utils.js
+++ b/swh/web/assets/src/bundles/browse/swh-ids-utils.js
@@ -16,24 +16,27 @@
$(event.target).tab('show');
}
-export function swhIdOptionOriginToggled(event) {
+export function swhIdContextOptionToggled(event) {
event.stopPropagation();
let swhIdElt = $(event.target).closest('.swh-id-ui').find('.swh-id');
- let originPart = ';origin=' + $(event.target).data('swh-origin');
+ let swhIdWithContext = $(event.target).data('swhid-with-context');
let currentSwhId = swhIdElt.text();
if ($(event.target).prop('checked')) {
- if (currentSwhId.indexOf(originPart) === -1) {
- currentSwhId += originPart;
- }
+ currentSwhId = swhIdWithContext;
} else {
- currentSwhId = currentSwhId.replace(originPart, '');
+ const pos = currentSwhId.indexOf(';');
+ if (pos !== -1) {
+ currentSwhId = currentSwhId.slice(0, pos);
+ }
}
swhIdElt.text(currentSwhId);
swhIdElt.attr('href', '/' + currentSwhId + '/');
+
+ addLinesInfo();
}
-function setIdLinesPart(elt) {
- let swhIdElt = $(elt).closest('.swh-id-ui').find('.swh-id');
+function addLinesInfo() {
+ let swhIdElt = $('#swh-id-tab-content').find('.swh-id');
let currentSwhId = swhIdElt.text();
let lines = [];
let linesPart = ';lines=';
@@ -49,22 +52,16 @@
if (lines.length > 1) {
linesPart += '-' + lines[1];
}
- if ($(elt).prop('checked')) {
+
+ if ($('#swh-id-context-option-content').prop('checked')) {
currentSwhId = currentSwhId.replace(/;lines=\d+-*\d*/g, '');
- currentSwhId += linesPart;
- } else {
- currentSwhId = currentSwhId.replace(linesPart, '');
- }
- swhIdElt.text(currentSwhId);
- swhIdElt.attr('href', '/' + currentSwhId + '/');
-}
+ if (lines.length > 0) {
+ currentSwhId += linesPart;
+ }
-export function swhIdOptionLinesToggled(event) {
- event.stopPropagation();
- if (!window.location.hash) {
- return;
+ swhIdElt.text(currentSwhId);
+ swhIdElt.attr('href', '/' + currentSwhId + '/');
}
- setIdLinesPart(event.target);
}
$(document).ready(() => {
@@ -108,11 +105,16 @@
// set the tab visible once the close animation is terminated
$('#swh-identifiers').css('display', 'block');
- $('.swh-id-option-origin').trigger('click');
- $('.swh-id-option-lines').trigger('click');
+ $('.swh-id-context-option').trigger('click');
+ // highlighted code lines changed
$(window).on('hashchange', () => {
- setIdLinesPart('.swh-id-option-lines');
+ addLinesInfo();
+ });
+
+ // highlighted code lines removed
+ $('body').click(() => {
+ addLinesInfo();
});
});
diff --git a/swh/web/assets/src/bundles/webapp/badges.js b/swh/web/assets/src/bundles/webapp/badges.js
--- a/swh/web/assets/src/bundles/webapp/badges.js
+++ b/swh/web/assets/src/bundles/webapp/badges.js
@@ -12,7 +12,12 @@
badgeImageUrl = Urls.swh_badge(objectType, objectPid);
badgeLinkUrl = `${Urls.browse_origin()}?origin_url=${objectPid}`;
} else {
- badgeImageUrl = Urls.swh_badge_pid(objectPid);
+ const pos = objectPid.indexOf(';');
+ if (pos !== -1) {
+ badgeImageUrl = Urls.swh_badge_pid(objectPid.slice(0, pos));
+ } else {
+ badgeImageUrl = Urls.swh_badge_pid(objectPid);
+ }
badgeLinkUrl = Urls.browse_swh_id(objectPid);
}
let urlPrefix = `${window.location.protocol}//${window.location.hostname}`;
diff --git a/swh/web/assets/src/bundles/webapp/webapp.css b/swh/web/assets/src/bundles/webapp/webapp.css
--- a/swh/web/assets/src/bundles/webapp/webapp.css
+++ b/swh/web/assets/src/bundles/webapp/webapp.css
@@ -386,7 +386,11 @@
padding-top: 4px;
}
-.swh-id-option {
+.swh-id {
+ white-space: pre-wrap;
+}
+
+.swh-id .swh-id-option {
display: inline-block;
margin-right: 5px;
line-height: 1rem;
diff --git a/swh/web/browse/views/content.py b/swh/web/browse/views/content.py
--- a/swh/web/browse/views/content.py
+++ b/swh/web/browse/views/content.py
@@ -322,7 +322,7 @@
language=content_data["language"],
licenses=content_data["licenses"],
root_directory=root_dir,
- path=f"/{path}" if path else "",
+ path=f"/{path}" if path else "/",
filename=filename or "",
directory=directory_id,
directory_url=directory_url,
diff --git a/swh/web/browse/views/directory.py b/swh/web/browse/views/directory.py
--- a/swh/web/browse/views/directory.py
+++ b/swh/web/browse/views/directory.py
@@ -131,12 +131,12 @@
dir_metadata = DirectoryMetadata(
object_type=DIRECTORY,
object_id=sha1_git,
- directory=sha1_git,
+ directory=root_sha1_git,
nb_files=len(files),
nb_dirs=len(dirs),
sum_file_sizes=sum_file_sizes,
root_directory=root_sha1_git,
- path=f"/{path}" if path else "",
+ path=f"/{path}" if path else "/",
revision=None,
revision_found=None,
release=None,
diff --git a/swh/web/browse/views/revision.py b/swh/web/browse/views/revision.py
--- a/swh/web/browse/views/revision.py
+++ b/swh/web/browse/views/revision.py
@@ -453,8 +453,7 @@
error_description = ""
extra_context = dict(revision_metadata)
- if path:
- extra_context["path"] = f"/{path}"
+ extra_context["path"] = f"/{path}" if path else "/"
if content_data:
breadcrumbs[-1]["url"] = None
diff --git a/swh/web/common/identifiers.py b/swh/web/common/identifiers.py
--- a/swh/web/common/identifiers.py
+++ b/swh/web/common/identifiers.py
@@ -254,7 +254,7 @@
swhid_context["visit"] = get_swh_persistent_id(
SNAPSHOT, snapshot_context["snapshot_id"]
)
- if object_type not in (RELEASE, REVISION, SNAPSHOT):
+ if object_type in (CONTENT, DIRECTORY):
if snapshot_context["release_id"] is not None:
swhid_context["anchor"] = get_swh_persistent_id(
RELEASE, snapshot_context["release_id"]
@@ -269,6 +269,7 @@
extra_context
and "revision" in extra_context
and extra_context["revision"]
+ and "anchor" not in swhid_context
):
swhid_context["anchor"] = get_swh_persistent_id(
REVISION, extra_context["revision"]
@@ -277,6 +278,7 @@
extra_context
and "root_directory" in extra_context
and extra_context["root_directory"]
+ and "anchor" not in swhid_context
and (
object_type != DIRECTORY
or extra_context["root_directory"] != object_id
diff --git a/swh/web/templates/includes/show-swh-ids.html b/swh/web/templates/includes/show-swh-ids.html
--- a/swh/web/templates/includes/show-swh-ids.html
+++ b/swh/web/templates/includes/show-swh-ids.html
@@ -66,23 +66,13 @@
{% if swhid_info.swhid_with_context is not None %}
<div class="float-left">
<form id="swh-id-options">
- {% if snapshot_context and snapshot_context.origin_info %}
- <div class="form-check swh-id-option">
- <input class="form-check-input swh-id-option-origin" value="option-origin" type="checkbox"
- id="swh-id-option-origin-{{ swhid_info.object_type }}"
- data-swh-origin="{{ snapshot_context.origin_info.url }}"
- onclick="swh.browse.swhIdOptionOriginToggled(event)">
- <label class="form-check-label" for="swh-id-option-origin-{{ swhid_info.object_type }}">Add origin info</label>
- </div>
- {% endif %}
- {% if swhid_info.object_type == 'content' %}
- <div class="form-check swh-id-option">
- <input class="form-check-input swh-id-option-lines" value="option-lines" type="checkbox"
- id="swh-id-option-lines-{{ swhid_info.object_type }}"
- onclick="swh.browse.swhIdOptionLinesToggled(event)">
- <label class="form-check-label" for="swh-id-option-lines-{{ swhid_info.object_type }}">Add selected lines info</label>
- </div>
- {% endif %}
+ <div class="form-check swh-id-option">
+ <input class="form-check-input swh-id-context-option" value="option-origin" type="checkbox"
+ id="swh-id-context-option-{{ swhid_info.object_type }}"
+ data-swhid-with-context="{{ swhid_info.swhid_with_context }}"
+ onclick="swh.browse.swhIdContextOptionToggled(event)">
+ <label class="form-check-label" for="swh-id-context-option-{{ swhid_info.object_type }}">Add contextual information</label>
+ </div>
</form>
</div>
{% endif %}
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
@@ -9,6 +9,7 @@
from hypothesis import given
+from swh.model.identifiers import CONTENT, DIRECTORY
from swh.web.browse.utils import (
get_mimetype_and_encoding_for_content,
prepare_content_for_display,
@@ -60,7 +61,7 @@
assert_contains(resp, escape(content_display["content_data"]))
assert_contains(resp, url_raw)
- swh_cnt_id = get_swh_persistent_id("content", sha1_git)
+ swh_cnt_id = get_swh_persistent_id(CONTENT, sha1_git)
swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
assert_contains(resp, swh_cnt_id_url)
@@ -97,7 +98,7 @@
assert_contains(resp, escape(content_display["content_data"]))
assert_contains(resp, url_raw)
- swh_cnt_id = get_swh_persistent_id("content", sha1_git)
+ swh_cnt_id = get_swh_persistent_id(CONTENT, sha1_git)
swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
@@ -116,7 +117,7 @@
assert resp.status_code == 200
assert_template_used(resp, "browse/content.html")
- swh_cnt_id = get_swh_persistent_id("content", sha1_git)
+ swh_cnt_id = get_swh_persistent_id(CONTENT, sha1_git)
swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
assert_contains(resp, swh_cnt_id_url)
assert_contains(resp, escape(content_display["content_data"]))
@@ -190,6 +191,18 @@
filename = split_path[-1]
path = path.replace(root_dir_sha1 + "/", "").replace(filename, "")
+ swhid_context = {
+ "anchor": get_swh_persistent_id(DIRECTORY, root_dir_sha1),
+ "path": f"/{path}{filename}",
+ }
+
+ swh_cnt_id = get_swh_persistent_id(
+ CONTENT, content["sha1_git"], metadata=swhid_context
+ )
+ swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
+ assert_contains(resp, swh_cnt_id)
+ assert_contains(resp, swh_cnt_id_url)
+
path_info = gen_path_info(path)
root_dir_url = reverse("browse-directory", url_args={"sha1_git": root_dir_sha1})
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
@@ -8,6 +8,7 @@
from hypothesis import given
+from swh.model.identifiers import DIRECTORY
from swh.web.common.identifiers import get_swh_persistent_id
from swh.web.common.utils import gen_path_info, reverse
from swh.web.tests.django_asserts import assert_contains, assert_template_used
@@ -20,16 +21,16 @@
@given(directory())
-def test_root_directory_view(client, archive_data, directory):
- _directory_view(client, directory, archive_data.directory_ls(directory))
+def test_root_directory_view_checks(client, archive_data, directory):
+ _directory_view_checks(client, directory, archive_data.directory_ls(directory))
@given(directory_with_subdirs())
-def test_sub_directory_view(client, archive_data, directory):
+def test_sub_directory_view_checks(client, archive_data, directory):
dir_content = archive_data.directory_ls(directory)
subdir = random.choice([e for e in dir_content if e["type"] == "dir"])
subdir_content = archive_data.directory_ls(subdir["target"])
- _directory_view(client, directory, subdir_content, subdir["name"])
+ _directory_view_checks(client, directory, subdir_content, subdir["name"])
@given(invalid_sha1(), unknown_directory())
@@ -73,10 +74,10 @@
resp = client.get(url)
assert resp.status_code == 200
- assert_contains(resp, 'id="swh-id-option-origin-directory"')
+ assert_contains(resp, 'id="swh-id-context-option-directory"')
-def _directory_view(client, root_directory_sha1, directory_entries, path=None):
+def _directory_view_checks(client, root_directory_sha1, directory_entries, path=None):
dirs = [e for e in directory_entries if e["type"] in ("dir", "rev")]
files = [e for e in directory_entries if e["type"] == "file"]
@@ -144,10 +145,8 @@
assert_contains(resp, "vault-cook-directory")
- swh_dir_id = get_swh_persistent_id("directory", directory_entries[0]["dir_id"])
+ swh_dir_id = get_swh_persistent_id(DIRECTORY, directory_entries[0]["dir_id"])
swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
- assert_contains(resp, swh_dir_id)
- assert_contains(resp, swh_dir_id_url)
assert_contains(
resp,
@@ -161,3 +160,19 @@
" " * 4,
),
)
+
+ swhid_context = {}
+ if root_directory_sha1 != directory_entries[0]["dir_id"]:
+ swhid_context["anchor"] = get_swh_persistent_id(DIRECTORY, root_directory_sha1)
+
+ swhid_context["path"] = f"/{path}/" if path else "/"
+
+ if root_directory_sha1 != directory_entries[0]["dir_id"]:
+ swhid_context["anchor"] = get_swh_persistent_id(DIRECTORY, root_directory_sha1)
+
+ swh_dir_id = get_swh_persistent_id(
+ DIRECTORY, directory_entries[0]["dir_id"], metadata=swhid_context
+ )
+ swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
+ assert_contains(resp, swh_dir_id)
+ assert_contains(resp, swh_dir_id_url)
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
@@ -14,6 +14,7 @@
from hypothesis import given
from swh.model.hashutil import hash_to_bytes
+from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT
from swh.model.model import (
Snapshot,
SnapshotBranch,
@@ -28,7 +29,6 @@
format_utc_iso_date,
parse_timestamp,
)
-from swh.web.config import get_config
from swh.web.tests.data import get_content, random_sha1
from swh.web.tests.django_asserts import assert_contains, assert_template_used
from swh.web.tests.strategies import (
@@ -95,8 +95,9 @@
_origin_content_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ origin_visits[-1],
tdata["branches"],
tdata["releases"],
tdata["root_dir_sha1"],
@@ -105,8 +106,9 @@
_origin_content_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ origin_visits[-1],
tdata["branches"],
tdata["releases"],
tdata["root_dir_sha1"],
@@ -119,8 +121,9 @@
_origin_content_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ origin_visits[-1],
tdata["branches"],
tdata["releases"],
tdata["root_dir_sha1"],
@@ -132,8 +135,9 @@
_origin_content_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ origin_visits[0],
tdata["branches"],
tdata["releases"],
tdata["root_dir_sha1"],
@@ -157,13 +161,21 @@
visit_unix_ts = int(visit_unix_ts)
_origin_directory_view_test_helper(
- client, origin, origin_visits, branches, releases, root_dir_sha1, dir_content
+ client,
+ archive_data,
+ origin,
+ visit,
+ branches,
+ releases,
+ root_dir_sha1,
+ dir_content,
)
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -173,8 +185,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -184,8 +197,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -197,13 +211,21 @@
del origin["type"]
_origin_directory_view_test_helper(
- client, origin, origin_visits, branches, releases, root_dir_sha1, dir_content
+ client,
+ archive_data,
+ origin,
+ visit,
+ branches,
+ releases,
+ root_dir_sha1,
+ dir_content,
)
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -213,8 +235,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -224,8 +247,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -259,8 +283,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -270,8 +295,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -282,8 +308,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -294,8 +321,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -309,8 +337,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -320,8 +349,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -332,8 +362,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -344,8 +375,9 @@
_origin_directory_view_test_helper(
client,
+ archive_data,
origin,
- origin_visits,
+ visit,
branches,
releases,
root_dir_sha1,
@@ -620,27 +652,35 @@
@given(origin_with_releases())
def test_origin_release_browse(client, archive_data, origin):
- # for swh.web.browse.snapshot_context.get_snapshot_content to only return one branch
- config = get_config()
- snapshot_max_size = int(config["snapshot_content_max_size"])
- config["snapshot_content_max_size"] = 1
- try:
- snapshot = archive_data.snapshot_get_latest(origin["url"])
- release = [
- b for b in snapshot["branches"].values() if b["target_type"] == "release"
- ][-1]
- release_data = archive_data.release_get(release["target"])
- url = reverse(
- "browse-origin-directory",
- query_params={"origin_url": origin["url"], "release": release_data["name"]},
- )
+ snapshot = archive_data.snapshot_get_latest(origin["url"])
+ release = [
+ b for b in snapshot["branches"].values() if b["target_type"] == "release"
+ ][-1]
+ release_data = archive_data.release_get(release["target"])
+ revision_data = archive_data.revision_get(release_data["target"])
+ url = reverse(
+ "browse-origin-directory",
+ query_params={"origin_url": origin["url"], "release": release_data["name"]},
+ )
- resp = client.get(url)
- assert resp.status_code == 200
- assert_contains(resp, release_data["name"])
- assert_contains(resp, release["target"])
- finally:
- config["snapshot_content_max_size"] = snapshot_max_size
+ resp = client.get(url)
+ assert resp.status_code == 200
+ assert_contains(resp, release_data["name"])
+ assert_contains(resp, release["target"])
+
+ swhid_context = {
+ "origin": origin["url"],
+ "visit": get_swh_persistent_id(SNAPSHOT, snapshot["id"]),
+ "anchor": get_swh_persistent_id(RELEASE, release_data["id"]),
+ "path": f"/",
+ }
+
+ swh_dir_id = get_swh_persistent_id(
+ DIRECTORY, revision_data["directory"], metadata=swhid_context
+ )
+ swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
+ assert_contains(resp, swh_dir_id)
+ assert_contains(resp, swh_dir_id_url)
@given(origin_with_releases())
@@ -724,8 +764,9 @@
def _origin_content_view_test_helper(
client,
+ archive_data,
origin_info,
- origin_visits,
+ origin_visit,
origin_branches,
origin_releases,
root_dir_sha1,
@@ -736,7 +777,7 @@
content_path = "/".join(content["path"].split("/")[1:])
if not visit_id:
- visit_id = origin_visits[-1]["visit"]
+ visit_id = origin_visit["visit"]
query_params = {"origin_url": origin_info["url"], "path": content_path}
@@ -818,9 +859,9 @@
query_params["path"] = content_path
for branch in origin_branches:
- query_params["branch"] = branch["name"]
root_dir_branch_url = reverse(
- "browse-origin-content", query_params=query_params
+ "browse-origin-content",
+ query_params={"branch": branch["name"], **query_params},
)
assert_contains(resp, '<a href="%s">' % root_dir_branch_url)
@@ -829,9 +870,9 @@
query_params["branch"] = None
for release in origin_releases:
- query_params["release"] = release["name"]
root_dir_release_url = reverse(
- "browse-origin-content", query_params=query_params
+ "browse-origin-content",
+ query_params={"release": release["name"], **query_params},
)
assert_contains(resp, '<a href="%s">' % root_dir_release_url)
@@ -842,7 +883,19 @@
assert resp.status_code == 200
assert_template_used(resp, "browse/content.html")
- swh_cnt_id = get_swh_persistent_id("content", content["sha1_git"])
+ snapshot = archive_data.snapshot_get(origin_visit["snapshot"])
+ head_rev_id = archive_data.snapshot_get_head(snapshot)
+
+ swhid_context = {
+ "origin": origin_info["url"],
+ "visit": get_swh_persistent_id(SNAPSHOT, snapshot["id"]),
+ "anchor": get_swh_persistent_id(REVISION, head_rev_id),
+ "path": f"/{content_path}",
+ }
+
+ swh_cnt_id = get_swh_persistent_id(
+ CONTENT, content["sha1_git"], metadata=swhid_context
+ )
swh_cnt_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_cnt_id})
assert_contains(resp, swh_cnt_id)
assert_contains(resp, swh_cnt_id_url)
@@ -854,8 +907,9 @@
def _origin_directory_view_test_helper(
client,
+ archive_data,
origin_info,
- origin_visits,
+ origin_visit,
origin_branches,
origin_releases,
root_directory_sha1,
@@ -868,7 +922,7 @@
files = [e for e in directory_entries if e["type"] == "file"]
if not visit_id:
- visit_id = origin_visits[-1]["visit"]
+ visit_id = origin_visit["visit"]
query_params = {"origin_url": origin_info["url"]}
@@ -976,7 +1030,19 @@
assert_contains(resp, "vault-cook-directory")
assert_contains(resp, "vault-cook-revision")
- swh_dir_id = get_swh_persistent_id("directory", directory_entries[0]["dir_id"])
+ snapshot = archive_data.snapshot_get(origin_visit["snapshot"])
+ head_rev_id = archive_data.snapshot_get_head(snapshot)
+
+ swhid_context = {
+ "origin": origin_info["url"],
+ "visit": get_swh_persistent_id(SNAPSHOT, snapshot["id"]),
+ "anchor": get_swh_persistent_id(REVISION, head_rev_id),
+ "path": f"/{path}" if path else "/",
+ }
+
+ swh_dir_id = get_swh_persistent_id(
+ DIRECTORY, directory_entries[0]["dir_id"], metadata=swhid_context
+ )
swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
assert_contains(resp, swh_dir_id)
assert_contains(resp, swh_dir_id_url)
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
@@ -8,6 +8,7 @@
from django.utils.html import escape
from hypothesis import given
+from swh.model.identifiers import DIRECTORY, REVISION, SNAPSHOT
from swh.web.common.identifiers import get_swh_persistent_id
from swh.web.common.utils import reverse, format_utc_iso_date, parse_timestamp
from swh.web.tests.django_asserts import assert_contains, assert_template_used
@@ -51,7 +52,7 @@
assert_contains(resp, escape(message_lines[0]))
assert_contains(resp, escape("\n".join(message_lines[1:])))
- swh_rev_id = get_swh_persistent_id("revision", revision)
+ swh_rev_id = get_swh_persistent_id(REVISION, revision)
swh_rev_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id})
assert_contains(
@@ -67,6 +68,14 @@
),
)
+ swhid_context = {"anchor": swh_rev_id, "path": "/"}
+
+ swh_dir_id = get_swh_persistent_id(DIRECTORY, dir_id, metadata=swhid_context)
+ swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
+
+ assert_contains(resp, swh_dir_id)
+ assert_contains(resp, swh_dir_id_url)
+
@given(origin())
def test_revision_origin_browse(client, archive_data, origin):
@@ -101,12 +110,20 @@
assert_contains(resp, "vault-cook-directory")
assert_contains(resp, "vault-cook-revision")
- swh_rev_id = get_swh_persistent_id("revision", revision)
+ swhid_context = {
+ "origin": origin["url"],
+ "visit": get_swh_persistent_id(SNAPSHOT, snapshot["id"]),
+ }
+
+ swh_rev_id = get_swh_persistent_id(REVISION, revision, metadata=swhid_context)
swh_rev_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id})
assert_contains(resp, swh_rev_id)
assert_contains(resp, swh_rev_id_url)
- swh_dir_id = get_swh_persistent_id("directory", dir_id)
+ swhid_context["anchor"] = get_swh_persistent_id(REVISION, revision)
+ swhid_context["path"] = "/"
+
+ swh_dir_id = get_swh_persistent_id(DIRECTORY, dir_id, metadata=swhid_context)
swh_dir_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_dir_id})
assert_contains(resp, swh_dir_id)
assert_contains(resp, swh_dir_id_url)
@@ -227,7 +244,7 @@
resp, '<a class="page-link" href="%s">Older</a>' % escape(next_page_url),
)
- swh_rev_id = get_swh_persistent_id("revision", revision)
+ swh_rev_id = get_swh_persistent_id(REVISION, revision)
swh_rev_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id})
assert_contains(

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 17, 12:56 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218884

Event Timeline