Page MenuHomeSoftware Heritage

D3317.diff
No OneTemporary

D3317.diff

diff --git a/cypress/integration/origin-browse.spec.js b/cypress/integration/origin-browse.spec.js
new file mode 100644
--- /dev/null
+++ b/cypress/integration/origin-browse.spec.js
@@ -0,0 +1,87 @@
+/**
+ * Copyright (C) 2020 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
+ */
+
+describe('Test origin browse', function() {
+ beforeEach(function() {
+ const url = `${this.Urls.browse_origin()}?origin_url=${this.origin[1].url}`;
+ cy.visit(url);
+ });
+
+ it('should have code tab active by default', function() {
+ cy.get('#swh-browse-code-nav-link')
+ .should('have.class', 'active');
+ });
+
+ it('should load branches view when clicking on the Branches tab', function() {
+ cy.get('#swh-browse-snapshot-branches-nav-link')
+ .click();
+
+ cy.location('pathname')
+ .should('eq', this.Urls.browse_origin_branches());
+
+ cy.location('search')
+ .should('eq', `?origin_url=${this.origin[1].url}`);
+
+ cy.get('#swh-browse-snapshot-branches-nav-link')
+ .should('have.class', 'active');
+ });
+
+ it('should load releases view when clicking on the Releases tab', function() {
+ cy.get('#swh-browse-snapshot-releases-nav-link')
+ .click();
+
+ cy.location('pathname')
+ .should('eq', this.Urls.browse_origin_releases());
+
+ cy.location('search')
+ .should('eq', `?origin_url=${this.origin[1].url}`);
+
+ cy.get('#swh-browse-snapshot-releases-nav-link')
+ .should('have.class', 'active');
+ });
+
+ it('should load visits view when clicking on the Visits tab', function() {
+ cy.get('#swh-browse-origin-visits-nav-link')
+ .click();
+
+ cy.location('pathname')
+ .should('eq', this.Urls.browse_origin_visits());
+
+ cy.location('search')
+ .should('eq', `?origin_url=${this.origin[1].url}`);
+
+ cy.get('#swh-browse-origin-visits-nav-link')
+ .should('have.class', 'active');
+ });
+
+ it('should load code view when clicking on the Code tab', function() {
+ cy.get('#swh-browse-origin-visits-nav-link')
+ .click();
+
+ cy.get('#swh-browse-code-nav-link')
+ .click();
+
+ cy.location('pathname')
+ .should('eq', this.Urls.browse_origin_directory());
+
+ cy.location('search')
+ .should('eq', `?origin_url=${this.origin[1].url}`);
+
+ cy.get('#swh-browse-code-nav-link')
+ .should('have.class', 'active');
+
+ });
+
+ it('should have Releases tab link disabled when there is no releases', function() {
+ const url = `${this.Urls.browse_origin()}?origin_url=${this.origin[0].url}`;
+ cy.visit(url);
+
+ cy.get('#swh-browse-snapshot-releases-nav-link')
+ .should('have.class', 'disabled');
+ });
+
+});
diff --git a/swh/web/assets/src/bundles/browse/browse-utils.js b/swh/web/assets/src/bundles/browse/browse-utils.js
--- a/swh/web/assets/src/bundles/browse/browse-utils.js
+++ b/swh/web/assets/src/bundles/browse/browse-utils.js
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2018-2019 The Software Heritage developers
+ * Copyright (C) 2018-2020 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
@@ -70,3 +70,17 @@
});
});
+
+export function initBrowseNavbar() {
+ if (window.location.pathname === Urls.browse_origin_visits()) {
+ $('#swh-browse-origin-visits-nav-link').addClass('active');
+ } else if (window.location.pathname === Urls.browse_origin_branches() ||
+ window.location.pathname === Urls.browse_snapshot_branches()) {
+ $('#swh-browse-snapshot-branches-nav-link').addClass('active');
+ } else if (window.location.pathname === Urls.browse_origin_releases() ||
+ window.location.pathname === Urls.browse_snapshot_releases()) {
+ $('#swh-browse-snapshot-releases-nav-link').addClass('active');
+ } else {
+ $('#swh-browse-code-nav-link').addClass('active');
+ }
+}
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
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2018-2019 The Software Heritage developers
+ * Copyright (C) 2018-2020 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
@@ -385,10 +385,6 @@
height: auto;
}
- .swh-navbar-content h4 {
- font-size: 1rem;
- }
-
.swh-donate-link {
display: none;
}
diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py
--- a/swh/web/common/utils.py
+++ b/swh/web/common/utils.py
@@ -38,6 +38,7 @@
"branches": "mdi mdi-source-branch",
"content": "mdi mdi-file-document",
"directory": "mdi mdi-folder",
+ "origin": "mdi mdi-source-repository",
"person": "mdi mdi-account",
"revisions history": "mdi mdi-history",
"release": "mdi mdi-tag",
diff --git a/swh/web/templates/browse/browse.html b/swh/web/templates/browse/browse.html
--- a/swh/web/templates/browse/browse.html
+++ b/swh/web/templates/browse/browse.html
@@ -13,36 +13,9 @@
{% block navbar-content %}
-{% if snapshot_context %}
- <h4>
- <i class="{{ swh_object_icons|key_value:swh_object_name.lower }} mdi-fw" aria-hidden="true"></i>
-
- {% if snapshot_context.origin_info %}
- Browse archived {{ swh_object_name.lower }} for origin
- <a href="{% url 'browse-origin' %}?origin_url={{ snapshot_context.origin_info.url }}">
- {{ snapshot_context.origin_info.url }}
- </a>
- {% if snapshot_context.origin_info.url|slice:"0:4" == "http" %}
- <a href="{{ snapshot_context.origin_info.url }}" title="Go to origin">
- <i class="mdi mdi-open-in-new" aria-hidden="true"></i>
- </a>
- {% endif %}
- {% else %}
- Browse archived {{ swh_object_name.lower }} for snapshot
- <a href="{% url 'browse-swh-id' snapshot_context.snapshot_swhid %}">
- {{ snapshot_context.snapshot_swhid }}
- </a>
- {% endif %}
- </h4>
-{% else %}
- <h4>
- <i class="{{ swh_object_icons|key_value:swh_object_name.lower }} mdi-fw" aria-hidden="true"></i>
- Browse archived {{ swh_object_name.lower }}
- <a href="{% url 'browse-swh-id' swh_object_id %}">
- {{ swh_object_id }}
- </a>
- </h4>
-{% endif %}
+<h4>
+ Browse the archive
+</h4>
{% endblock %}
diff --git a/swh/web/templates/browse/origin-visits.html b/swh/web/templates/browse/origin-visits.html
--- a/swh/web/templates/browse/origin-visits.html
+++ b/swh/web/templates/browse/origin-visits.html
@@ -1,7 +1,7 @@
{% extends "./browse.html" %}
{% comment %}
-Copyright (C) 2017-2018 The Software Heritage developers
+Copyright (C) 2017-2020 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
@@ -18,61 +18,64 @@
{% block swh-browse-content %}
-<h4>Overview</h4>
-
-<ul>
- <li class="d-inline-block">
- <b>Total number of visits: </b>{{ origin_visits|length }}
- <i class="mdi mdi-fw" aria-hidden="true"></i>
- </li>
- <li class="d-inline-block">
- <b>Last full visit: </b><span style="margin-left: 20px;" id="swh-last-full-visit"></span>
- <i class="mdi mdi-fw" aria-hidden="true"></i>
- </li>
- <li class="d-inline-block">
- <b>First full visit: </b><span style="margin-left: 20px;" id="swh-first-full-visit"></span>
- <i class="mdi mdi-fw" aria-hidden="true"></i>
- </li>
- <li class="d-inline-block">
- <b>Last visit: </b><span style="margin-left: 20px;" id="swh-last-visit"></span>
- <i class="mdi mdi-fw" aria-hidden="true"></i>
- </li>
-</ul>
-
-<h4>History</h4>
-
-<form class="text-center">
- <div class="custom-control custom-radio custom-control-inline">
- <input class="custom-control-input" type="radio" id="swh-different-snapshot-visits" name="swh-visits" value="option1" checked>
- <label class="custom-control-label font-weight-normal" for="swh-different-snapshot-visits" onclick="swh.origin.showFullVisitsDifferentSnapshots(event)">
- Show full visits with different snapshots
- </label>
- </div>
- <div class="custom-control custom-radio custom-control-inline">
- <input class="custom-control-input" type="radio" id="swh-full-visits" name="swh-visits" value="option2">
- <label class="custom-control-label font-weight-normal" for="swh-full-visits" onclick="swh.origin.showFullVisits(event)">
- Show all full visits
- </label>
- </div>
- <div class="custom-control custom-radio custom-control-inline">
- <input class="custom-control-input" type="radio" id="swh-all-visits" name="swh-visits" value="option3">
- <label class="custom-control-label font-weight-normal" for="swh-all-visits" onclick="swh.origin.showAllVisits(event)">
- Show all visits
- </label>
- </div>
-</form>
-
-<h5>Calendar</h5>
-
-<div id="swh-visits-calendar"></div>
-
-<h5>List</h5>
-
-<div id="swh-visits-list"></div>
-
-<h5>Timeline</h5>
-
-<div id="swh-visits-timeline" class="d3-wrapper"></div>
+<div class="p-3">
+
+ <h4>Overview</h4>
+
+ <ul>
+ <li class="d-inline-block">
+ <b>Total number of visits: </b>{{ origin_visits|length }}
+ <i class="mdi mdi-fw" aria-hidden="true"></i>
+ </li>
+ <li class="d-inline-block">
+ <b>Last full visit: </b><span style="margin-left: 20px;" id="swh-last-full-visit"></span>
+ <i class="mdi mdi-fw" aria-hidden="true"></i>
+ </li>
+ <li class="d-inline-block">
+ <b>First full visit: </b><span style="margin-left: 20px;" id="swh-first-full-visit"></span>
+ <i class="mdi mdi-fw" aria-hidden="true"></i>
+ </li>
+ <li class="d-inline-block">
+ <b>Last visit: </b><span style="margin-left: 20px;" id="swh-last-visit"></span>
+ <i class="mdi mdi-fw" aria-hidden="true"></i>
+ </li>
+ </ul>
+
+ <h4>History</h4>
+
+ <form class="text-center">
+ <div class="custom-control custom-radio custom-control-inline">
+ <input class="custom-control-input" type="radio" id="swh-different-snapshot-visits" name="swh-visits" value="option1" checked>
+ <label class="custom-control-label font-weight-normal" for="swh-different-snapshot-visits" onclick="swh.origin.showFullVisitsDifferentSnapshots(event)">
+ Show full visits with different snapshots
+ </label>
+ </div>
+ <div class="custom-control custom-radio custom-control-inline">
+ <input class="custom-control-input" type="radio" id="swh-full-visits" name="swh-visits" value="option2">
+ <label class="custom-control-label font-weight-normal" for="swh-full-visits" onclick="swh.origin.showFullVisits(event)">
+ Show all full visits
+ </label>
+ </div>
+ <div class="custom-control custom-radio custom-control-inline">
+ <input class="custom-control-input" type="radio" id="swh-all-visits" name="swh-visits" value="option3">
+ <label class="custom-control-label font-weight-normal" for="swh-all-visits" onclick="swh.origin.showAllVisits(event)">
+ Show all visits
+ </label>
+ </div>
+ </form>
+
+ <h5>Calendar</h5>
+
+ <div id="swh-visits-calendar"></div>
+
+ <h5>List</h5>
+
+ <div id="swh-visits-list"></div>
+
+ <h5>Timeline</h5>
+
+ <div id="swh-visits-timeline" class="d3-wrapper"></div>
+</div>
<script>
// all origin visits
diff --git a/swh/web/templates/includes/snapshot-context.html b/swh/web/templates/includes/snapshot-context.html
--- a/swh/web/templates/includes/snapshot-context.html
+++ b/swh/web/templates/includes/snapshot-context.html
@@ -1,5 +1,5 @@
{% comment %}
-Copyright (C) 2017-2018 The Software Heritage developers
+Copyright (C) 2017-2020 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,25 +7,80 @@
{% load swh_templatetags %}
-<hr class="mt-1 mb-1">
-<div class="swh-origin-visit-details">
- <ul>
- {% if snapshot_context.origin_info %}
- <li><i class="{{ swh_object_icons.visits }} mdi-fw"></i><a href="{{ snapshot_context.origin_visits_url }}">Visits</a></li>
- {% endif %}
- {% if snapshot_context.visit_info %}
- <li><i class="{{ swh_object_icons.snapshot }} mdi-fw" aria-hidden="true"></i> Snapshot date: <a href="{{ snapshot_context.visit_info.url }}">{{ snapshot_context.visit_info.formatted_date }}</a></li>
- {% endif %}
- {% if not snapshot_context.snapshot_sizes.revision %}
- <li><i class="{{ swh_object_icons.branches }} mdi-fw" aria-hidden="true"></i> Branches (0)</li>
- {% else %}
- <li><i class="{{ swh_object_icons.branches }} mdi-fw" aria-hidden="true"></i> <a href="{{ snapshot_context.branches_url }}">Branches ({{ snapshot_context.snapshot_sizes.revision}})</a></li>
- {% endif %}
- {% if not snapshot_context.snapshot_sizes.release %}
- <li><i class="{{ swh_object_icons.releases }} mdi-fw" aria-hidden="true"></i> Releases (0)</li>
- {% else %}
- <li><i class="{{ swh_object_icons.releases }} mdi-fw" aria-hidden="true"></i> <a href="{{ snapshot_context.releases_url }}">Releases ({{ snapshot_context.snapshot_sizes.release }})</a></li>
- {% endif %}
- </ul>
-</div>
-<hr class="mt-1 mb-1">
\ No newline at end of file
+<h5>
+{% if snapshot_context.origin_info %}
+ <i class="{{ swh_object_icons.origin }} mdi-fw" aria-hidden="true" title="Origin"></i>
+ <a class="swh-heading-color" href="{% url 'browse-origin' %}?origin_url={{ snapshot_context.origin_info.url }}">
+ {{ snapshot_context.origin_info.url }}
+ </a>
+ {% if snapshot_context.origin_info.url|slice:"0:4" == "http" %}
+ <a href="{{ snapshot_context.origin_info.url }}" title="Go to origin">
+ <i class="mdi mdi-open-in-new" aria-hidden="true"></i>
+ </a>
+ {% endif %}
+{% else %}
+ <i class="{{ swh_object_icons.snapshot }} mdi-fw" aria-hidden="true" title="Snapshot"></i>
+ <a class="swh-heading-color" href="{% url 'browse-swh-id' snapshot_context.snapshot_swhid %}">
+ {{ snapshot_context.snapshot_swhid }}
+ </a>
+{% endif %}
+</h5>
+{% if snapshot_context.visit_info %}
+ <div class="mb-1 pl-1">
+ <i class="{{ swh_object_icons.snapshot }} mdi-fw" aria-hidden="true" title="Snapshot date"></i>
+ <a href="{{ snapshot_context.visit_info.url }}">
+ {{ snapshot_context.visit_info.formatted_date }}
+ </a>
+ </div>
+{% endif %}
+
+<ul class="nav nav-tabs" id="swh-snapshot-context-nav" style="padding-left: 5px;">
+ <li class="nav-item">
+ <a class="nav-link" id="swh-browse-code-nav-link" href="{{ snapshot_context.visit_info.url }}">
+ <i class="mdi mdi-code-tags mdi-fw" aria-hidden="true"></i>
+ Code
+ </a>
+ </li>
+ {% if not snapshot_context.snapshot_sizes.revision %}
+ <li class="nav-item">
+ <a class="nav-link disabled" id="swh-browse-snapshot-branches-nav-link" href="#">
+ <i class="{{ swh_object_icons.branches }} mdi-fw" aria-hidden="true"></i>
+ Branches (0)
+ </a>
+ </li>
+ {% else %}
+ <li class="nav-item">
+ <a class="nav-link" id="swh-browse-snapshot-branches-nav-link" href="{{ snapshot_context.branches_url }}">
+ <i class="{{ swh_object_icons.branches }} mdi-fw" aria-hidden="true"></i>
+ Branches ({{ snapshot_context.snapshot_sizes.revision}})
+ </a>
+ </li>
+ {% endif %}
+ {% if not snapshot_context.snapshot_sizes.release %}
+ <li class="nav-item">
+ <a class="nav-link disabled" id="swh-browse-snapshot-releases-nav-link" href="#">
+ <i class="{{ swh_object_icons.releases }} mdi-fw" aria-hidden="true"></i>
+ Releases (0)
+ </a>
+ </li>
+ {% else %}
+ <li class="nav-item">
+ <a class="nav-link" id="swh-browse-snapshot-releases-nav-link" href="{{ snapshot_context.releases_url }}">
+ <i class="{{ swh_object_icons.releases }} mdi-fw" aria-hidden="true"></i>
+ Releases ({{ snapshot_context.snapshot_sizes.release }})
+ </a>
+ </li>
+ {% endif %}
+ {% if snapshot_context.origin_info %}
+ <li class="nav-item">
+ <a class="nav-link" id="swh-browse-origin-visits-nav-link" href="{{ snapshot_context.origin_visits_url }}">
+ <i class="{{ swh_object_icons.visits }} mdi-fw"></i>
+ Visits
+ </a>
+ </li>
+ {% endif %}
+</ul>
+
+<script>
+ swh.browse.initBrowseNavbar();
+</script>
\ No newline at end of file
diff --git a/swh/web/templates/includes/top-navigation.html b/swh/web/templates/includes/top-navigation.html
--- a/swh/web/templates/includes/top-navigation.html
+++ b/swh/web/templates/includes/top-navigation.html
@@ -1,5 +1,5 @@
{% comment %}
-Copyright (C) 2017-2019 The Software Heritage developers
+Copyright (C) 2017-2020 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,7 +7,7 @@
{% load swh_templatetags %}
-<div class="swh-browse-top-navigation d-flex align-items-start justify-content-between flex-wrap">
+<div class="swh-browse-top-navigation d-flex align-items-start justify-content-between flex-wrap mt-1">
{% if snapshot_context %}
{% if snapshot_context.branch or snapshot_context.release %}
<div class="dropdown" id="swh-branches-releases-dd">
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
@@ -4,7 +4,6 @@
# See top-level LICENSE file for more information
import random
-import textwrap
from django.utils.html import escape
@@ -68,18 +67,6 @@
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)
- assert_contains(
- resp,
- textwrap.indent(
- (
- f"Browse archived content\n"
- f'<a href="{swh_cnt_id_url}">\n'
- f" {swh_cnt_id}\n"
- f"</a>"
- ),
- " " * 4,
- ),
- )
@given(content_text_no_highlight())
@@ -580,38 +567,23 @@
browse_origin_url = reverse(
"browse-origin", query_params={"origin_url": origin["url"]}
)
- assert_contains(
- resp,
- textwrap.indent(
- (
- "Browse archived content for origin\n"
- f'<a href="{browse_origin_url}">\n'
- f" {origin['url']}\n"
- f"</a>"
- ),
- " " * 6,
- ),
- )
+ assert_contains(resp, f'href="{browse_origin_url}"')
origin_branches_url = reverse(
"browse-origin-branches",
query_params={"origin_url": origin["url"], "snapshot": snapshot["id"]},
)
- assert_contains(
- resp,
- '<a href="%s">Branches (%s)</a>' % (escape(origin_branches_url), len(branches)),
- )
+ assert_contains(resp, f'href="{escape(origin_branches_url)}"')
+ assert_contains(resp, f"Branches ({len(branches)})")
origin_releases_url = reverse(
"browse-origin-releases",
query_params={"origin_url": origin["url"], "snapshot": snapshot["id"]},
)
- assert_contains(
- resp,
- '<a href="%s">Releases (%s)</a>' % (escape(origin_releases_url), len(releases)),
- )
+ assert_contains(resp, f'href="{escape(origin_releases_url)}"')
+ assert_contains(resp, f"Releases ({len(releases)})")
assert_contains(resp, '<li class="swh-branch">', count=len(branches))
assert_contains(resp, '<li class="swh-release">', count=len(releases))
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
@@ -4,7 +4,6 @@
# See top-level LICENSE file for more information
import random
-import textwrap
from django.utils.html import escape
from hypothesis import given
@@ -215,38 +214,24 @@
browse_origin_url = reverse(
"browse-origin", query_params={"origin_url": origin["url"]}
)
- assert_contains(
- resp,
- textwrap.indent(
- (
- "Browse archived directory for origin\n"
- f'<a href="{browse_origin_url}">\n'
- f" {origin['url']}\n"
- f"</a>"
- ),
- " " * 6,
- ),
- )
+
+ assert_contains(resp, f'href="{browse_origin_url}"')
origin_branches_url = reverse(
"browse-origin-branches",
query_params={"origin_url": origin["url"], "snapshot": snapshot["id"]},
)
- assert_contains(
- resp,
- '<a href="%s">Branches (%s)</a>' % (escape(origin_branches_url), len(branches)),
- )
+ assert_contains(resp, f'href="{escape(origin_branches_url)}"')
+ assert_contains(resp, f"Branches ({len(branches)})")
origin_releases_url = reverse(
"browse-origin-releases",
query_params={"origin_url": origin["url"], "snapshot": snapshot["id"]},
)
- assert_contains(
- resp,
- '<a href="%s">Releases (%s)</a>' % (escape(origin_releases_url), len(releases)),
- )
+ assert_contains(resp, f'href="{escape(origin_releases_url)}"')
+ assert_contains(resp, f"Releases ({len(releases)})")
assert_contains(resp, '<li class="swh-branch">', count=len(branches))
assert_contains(resp, '<li class="swh-release">', count=len(releases))
@@ -328,19 +313,6 @@
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,
- textwrap.indent(
- (
- f"Browse archived directory\n"
- f'<a href="{swh_dir_id_url}">\n'
- f" {swh_dir_id}\n"
- f"</a>"
- ),
- " " * 4,
- ),
- )
-
swhid_context = {}
if root_directory_sha1 != directory_entries[0]["dir_id"]:
swhid_context["anchor"] = get_swh_persistent_id(DIRECTORY, root_directory_sha1)
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
@@ -6,7 +6,6 @@
import random
import re
import string
-import textwrap
from django.utils.html import escape
@@ -71,7 +70,7 @@
)
assert_contains(resp, browse_dir_url)
- _check_origin_view_title(resp, origin["url"], "visits")
+ _check_origin_link(resp, origin["url"])
@given(origin_with_multiple_visits())
@@ -955,19 +954,13 @@
origin_branches_url = reverse("browse-origin-branches", query_params=query_params)
- assert_contains(
- resp,
- '<a href="%s">Branches (%s)</a>'
- % (escape(origin_branches_url), len(origin_branches)),
- )
+ assert_contains(resp, f'href="{escape(origin_branches_url)}"')
+ assert_contains(resp, f"Branches ({len(origin_branches)})")
origin_releases_url = reverse("browse-origin-releases", query_params=query_params)
- assert_contains(
- resp,
- '<a href="%s">Releases (%s)</a>'
- % (escape(origin_releases_url), len(origin_releases)),
- )
+ assert_contains(resp, f'href="{escape(origin_releases_url)}">')
+ assert_contains(resp, f"Releases ({len(origin_releases)})")
assert_contains(resp, '<li class="swh-branch">', count=len(origin_branches))
@@ -1017,7 +1010,7 @@
assert_contains(resp, "swh-take-new-snapshot")
- _check_origin_view_title(resp, origin_info["url"], "content")
+ _check_origin_link(resp, origin_info["url"])
def _origin_directory_view_test_helper(
@@ -1105,21 +1098,15 @@
origin_branches_url = reverse("browse-origin-branches", query_params=query_params)
- assert_contains(
- resp,
- '<a href="%s">Branches (%s)</a>'
- % (escape(origin_branches_url), len(origin_branches)),
- )
+ assert_contains(resp, f'href="{escape(origin_branches_url)}"')
+ assert_contains(resp, f"Branches ({len(origin_branches)})")
origin_releases_url = reverse("browse-origin-releases", query_params=query_params)
nb_releases = len(origin_releases)
if nb_releases > 0:
- assert_contains(
- resp,
- '<a href="%s">Releases (%s)</a>'
- % (escape(origin_releases_url), nb_releases),
- )
+ assert_contains(resp, f'href="{escape(origin_releases_url)}"')
+ assert_contains(resp, f"Releases ({nb_releases})")
if path:
query_params["path"] = path
@@ -1143,7 +1130,7 @@
"browse-origin-directory", query_params=query_params
)
- assert_contains(resp, '<a href="%s">' % root_dir_release_url)
+ assert_contains(resp, 'href="%s"' % root_dir_release_url)
assert_contains(resp, "vault-cook-directory")
assert_contains(resp, "vault-cook-revision")
@@ -1167,7 +1154,7 @@
assert_contains(resp, "swh-take-new-snapshot")
- _check_origin_view_title(resp, origin_info["url"], "directory")
+ _check_origin_link(resp, origin_info["url"])
def _origin_branches_test_helper(
@@ -1187,21 +1174,15 @@
origin_branches_url = reverse("browse-origin-branches", query_params=query_params)
- assert_contains(
- resp,
- '<a href="%s">Branches (%s)</a>'
- % (escape(origin_branches_url), len(origin_branches)),
- )
+ assert_contains(resp, f'href="{escape(origin_branches_url)}"')
+ assert_contains(resp, f"Branches ({len(origin_branches)})")
origin_releases_url = reverse("browse-origin-releases", query_params=query_params)
nb_releases = len(origin_releases)
if nb_releases > 0:
- assert_contains(
- resp,
- '<a href="%s">Releases (%s)</a>'
- % (escape(origin_releases_url), nb_releases),
- )
+ assert_contains(resp, f'href="{escape(origin_releases_url)}">')
+ assert_contains(resp, f"Releases ({nb_releases})")
assert_contains(resp, '<tr class="swh-branch-entry', count=len(origin_branches))
@@ -1219,7 +1200,7 @@
)
assert_contains(resp, '<a href="%s">' % escape(browse_revision_url))
- _check_origin_view_title(resp, origin_info["url"], "branches")
+ _check_origin_link(resp, origin_info["url"])
def _origin_releases_test_helper(
@@ -1238,21 +1219,15 @@
origin_branches_url = reverse("browse-origin-branches", query_params=query_params)
- assert_contains(
- resp,
- '<a href="%s">Branches (%s)</a>'
- % (escape(origin_branches_url), len(origin_branches)),
- )
+ assert_contains(resp, f'href="{escape(origin_branches_url)}"')
+ assert_contains(resp, f"Branches ({len(origin_branches)})")
origin_releases_url = reverse("browse-origin-releases", query_params=query_params)
nb_releases = len(origin_releases)
if nb_releases > 0:
- assert_contains(
- resp,
- '<a href="%s">Releases (%s)</a>'
- % (escape(origin_releases_url), nb_releases),
- )
+ assert_contains(resp, f'href="{escape(origin_releases_url)}"')
+ assert_contains(resp, f"Releases ({nb_releases})")
assert_contains(resp, '<tr class="swh-release-entry', count=nb_releases)
@@ -1271,7 +1246,7 @@
assert_contains(resp, '<a href="%s">' % escape(browse_release_url))
assert_contains(resp, '<a href="%s">' % escape(browse_revision_url))
- _check_origin_view_title(resp, origin_info["url"], "releases")
+ _check_origin_link(resp, origin_info["url"])
@given(
@@ -1332,20 +1307,8 @@
assert_contains(resp, '<ul class="pagination')
-def _check_origin_view_title(resp, origin_url, object_type):
+def _check_origin_link(resp, origin_url):
browse_origin_url = reverse(
"browse-origin", query_params={"origin_url": origin_url}
)
-
- assert_contains(
- resp,
- textwrap.indent(
- (
- f"Browse archived {object_type} for origin\n"
- f'<a href="{browse_origin_url}">\n'
- f" {origin_url}\n"
- f"</a>"
- ),
- " " * 6,
- ),
- )
+ assert_contains(resp, f'href="{browse_origin_url}"')
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
@@ -4,7 +4,6 @@
# See top-level LICENSE file for more information
import random
-import textwrap
from django.utils.html import escape
from hypothesis import given
@@ -115,35 +114,11 @@
browse_origin_url = reverse(
"browse-origin", query_params={"origin_url": origin_url}
)
- title = (
- f"Browse archived release for origin\n"
- f'<a href="{browse_origin_url}">\n'
- f" {origin_url}\n"
- f"</a>"
- )
- indent = " " * 6
+ assert_contains(resp, f'href="{browse_origin_url}"')
elif snapshot_id:
swh_snp_id = get_swh_persistent_id("snapshot", snapshot_id)
swh_snp_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_snp_id})
- title = (
- f"Browse archived release for snapshot\n"
- f'<a href="{swh_snp_id_url}">\n'
- f" {swh_snp_id}\n"
- f"</a>"
- )
- indent = " " * 6
- else:
- title = (
- f"Browse archived release\n"
- f'<a href="{swh_rel_id_url}">\n'
- f" {swh_rel_id}\n"
- f"</a>"
- )
- indent = " " * 4
-
- assert_contains(
- resp, textwrap.indent(title, indent),
- )
+ assert_contains(resp, f'href="{swh_snp_id_url}"')
if release_data["target_type"] == "revision":
if origin_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
@@ -4,7 +4,6 @@
# See top-level LICENSE file for more information
import random
-import textwrap
from django.utils.html import escape
from hypothesis import given
@@ -149,22 +148,6 @@
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_url = reverse("browse-swh-id", url_args={"swh_id": swh_rev_id})
-
- assert_contains(
- resp,
- textwrap.indent(
- (
- f"Browse archived revisions history\n"
- f'<a href="{swh_rev_id_url}">\n'
- f" {swh_rev_id}\n"
- f"</a>"
- ),
- " " * 4,
- ),
- )
-
@given(revision(), unknown_revision(), new_origin())
def test_revision_request_errors(client, revision, unknown_revision, new_origin):
@@ -285,35 +268,11 @@
browse_origin_url = reverse(
"browse-origin", query_params={"origin_url": origin_url}
)
- title = (
- f"Browse archived revision for origin\n"
- f'<a href="{browse_origin_url}">\n'
- f" {origin_url}\n"
- f"</a>"
- )
- indent = " " * 6
+ assert_contains(resp, f'href="{browse_origin_url}"')
elif snapshot:
swh_snp_id = get_swh_persistent_id("snapshot", snapshot["id"])
swh_snp_id_url = reverse("browse-swh-id", url_args={"swh_id": swh_snp_id})
- title = (
- f"Browse archived revision for snapshot\n"
- f'<a href="{swh_snp_id_url}">\n'
- f" {swh_snp_id}\n"
- f"</a>"
- )
- indent = " " * 6
- else:
- title = (
- f"Browse archived revision\n"
- f'<a href="{swh_rev_id_url}">\n'
- f" {swh_rev_id}\n"
- f"</a>"
- )
- indent = " " * 4
-
- assert_contains(
- resp, textwrap.indent(title, indent),
- )
+ assert_contains(resp, f'href="{swh_snp_id_url}"')
swhid_context = {}
if origin_url:

File Metadata

Mime Type
text/plain
Expires
Tue, Jun 3, 7:22 PM (5 d, 16 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218592

Event Timeline