diff --git a/swh/web/archive_coverage/__init__.py b/swh/web/archive_coverage/__init__.py new file mode 100644 diff --git a/swh/web/templates/misc/coverage.html b/swh/web/archive_coverage/templates/archive-coverage.html rename from swh/web/templates/misc/coverage.html rename to swh/web/archive_coverage/templates/archive-coverage.html diff --git a/swh/web/archive_coverage/urls.py b/swh/web/archive_coverage/urls.py new file mode 100644 --- /dev/null +++ b/swh/web/archive_coverage/urls.py @@ -0,0 +1,12 @@ +# Copyright (C) 2018-2022 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 + +from django.urls import re_path as url + +from swh.web.archive_coverage.views import swh_coverage + +urlpatterns = [ + url(r"^coverage/$", swh_coverage, name="swh-coverage"), +] diff --git a/swh/web/misc/coverage.py b/swh/web/archive_coverage/views.py rename from swh/web/misc/coverage.py rename to swh/web/archive_coverage/views.py --- a/swh/web/misc/coverage.py +++ b/swh/web/archive_coverage/views.py @@ -10,7 +10,6 @@ from django.http.request import HttpRequest from django.http.response import HttpResponse from django.shortcuts import render -from django.urls import re_path as url from django.views.decorators.cache import never_cache from django.views.decorators.clickjacking import xframe_options_exempt @@ -383,7 +382,7 @@ @xframe_options_exempt @never_cache -def _swh_coverage(request: HttpRequest) -> HttpResponse: +def swh_coverage(request: HttpRequest) -> HttpResponse: use_cache = is_swh_web_production(request) listers_metrics = _get_listers_metrics(use_cache) @@ -484,7 +483,7 @@ return render( request, - "misc/coverage.html", + "archive-coverage.html", { "origins": { "Regular crawling": listed_origins, @@ -494,8 +493,3 @@ "focus": focus, }, ) - - -urlpatterns = [ - url(r"^coverage/$", _swh_coverage, name="swh-coverage"), -] diff --git a/swh/web/config.py b/swh/web/config.py --- a/swh/web/config.py +++ b/swh/web/config.py @@ -164,6 +164,7 @@ "swh.web.save_code_now", "swh.web.deposit", "swh.web.badges", + "swh.web.archive_coverage", ], ), } diff --git a/swh/web/misc/urls.py b/swh/web/misc/urls.py --- a/swh/web/misc/urls.py +++ b/swh/web/misc/urls.py @@ -61,7 +61,6 @@ urlpatterns = [ - url(r"^", include("swh.web.misc.coverage")), url(r"^jslicenses/$", _jslicenses, name="jslicenses"), url(r"^stat_counters/$", _stat_counters, name="stat-counters"), url(r"^metrics/prometheus/$", prometheus_metrics, name="metrics-prometheus"), diff --git a/swh/web/templates/homepage.html b/swh/web/templates/homepage.html --- a/swh/web/templates/homepage.html +++ b/swh/web/templates/homepage.html @@ -52,11 +52,15 @@

-
-

Content

+{% if "swh.web.archive_coverage" in SWH_DJANGO_APPS %} - -
+
+

Content

+ + +
+ +{% endif %}

Size

diff --git a/swh/web/tests/archive_coverage/__init__.py b/swh/web/tests/archive_coverage/__init__.py new file mode 100644 diff --git a/swh/web/tests/archive_coverage/test_app.py b/swh/web/tests/archive_coverage/test_app.py new file mode 100644 --- /dev/null +++ b/swh/web/tests/archive_coverage/test_app.py @@ -0,0 +1,33 @@ +# Copyright (C) 2022 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 + +import pytest + +from django.urls import get_resolver + +from swh.web.archive_coverage.urls import urlpatterns +from swh.web.tests.django_asserts import assert_not_contains +from swh.web.tests.helpers import check_html_get_response +from swh.web.utils import reverse + + +@pytest.mark.django_db +def test_archive_coverage_deactivate(client, django_settings): + """Check Add forge now feature is deactivated when the swh.web.archive_coverage django + application is not in installed apps.""" + + django_settings.SWH_DJANGO_APPS = [ + app + for app in django_settings.SWH_DJANGO_APPS + if app != "swh.web.archive_coverage" + ] + + url = reverse("swh-web-homepage") + resp = check_html_get_response(client, url, status_code=200) + assert_not_contains(resp, "swh-coverage-iframe") + + archive_coverage_view_names = set(urlpattern.name for urlpattern in urlpatterns) + all_view_names = set(get_resolver().reverse_dict.keys()) + assert archive_coverage_view_names & all_view_names == set() diff --git a/swh/web/tests/misc/test_coverage.py b/swh/web/tests/archive_coverage/test_coverage.py rename from swh/web/tests/misc/test_coverage.py rename to swh/web/tests/archive_coverage/test_coverage.py --- a/swh/web/tests/misc/test_coverage.py +++ b/swh/web/tests/archive_coverage/test_coverage.py @@ -16,8 +16,12 @@ from django.utils.html import escape from swh.scheduler.model import LastVisitStatus, ListedOrigin, OriginVisitStats +from swh.web.archive_coverage.views import ( + deposited_origins, + legacy_origins, + listed_origins, +) from swh.web.config import SWH_WEB_SERVER_NAME -from swh.web.misc.coverage import deposited_origins, legacy_origins, listed_origins from swh.web.tests.django_asserts import assert_contains, assert_not_contains from swh.web.tests.helpers import check_html_get_response, check_http_get_response from swh.web.utils import reverse @@ -30,7 +34,7 @@ """ url = reverse("swh-coverage") check_html_get_response( - client, url, status_code=200, template_used="misc/coverage.html" + client, url, status_code=200, template_used="archive-coverage.html" ) @@ -43,7 +47,7 @@ that will be consumed by the archive coverage view. """ # mock calls to get nixguix origin counts - mock_archive = mocker.patch("swh.web.misc.coverage.archive") + mock_archive = mocker.patch("swh.web.archive_coverage.views.archive") mock_archive.lookup_latest_origin_snapshot.return_value = {"id": "some-snapshot"} mock_archive.lookup_snapshot_sizes.return_value = {"release": 30095} @@ -98,7 +102,7 @@ "status": "done", } ) - get_deposits_list = mocker.patch("swh.web.misc.coverage.get_deposits_list") + get_deposits_list = mocker.patch("swh.web.archive_coverage.views.get_deposits_list") get_deposits_list.return_value = deposits @@ -107,7 +111,7 @@ # check view gets rendered without errors url = reverse("swh-coverage") resp = check_html_get_response( - client, url, status_code=200, template_used="misc/coverage.html" + client, url, status_code=200, template_used="archive-coverage.html" ) # check logos and origins search links are present in the rendered page @@ -153,7 +157,7 @@ # check view gets rendered without errors url = reverse("swh-coverage", query_params={"focus": ",".join(focus)}) resp = check_html_get_response( - client, url, status_code=200, template_used="misc/coverage.html" + client, url, status_code=200, template_used="archive-coverage.html" ) # check focused elements @@ -174,7 +178,7 @@ @pytest.fixture def archive_coverage_data_with_non_visited_origins(mocker, swh_scheduler): # mock calls to get nixguix origin counts - mock_archive = mocker.patch("swh.web.misc.coverage.archive") + mock_archive = mocker.patch("swh.web.archive_coverage.views.archive") mock_archive.lookup_latest_origin_snapshot.return_value = {"id": "some-snapshot"} mock_archive.lookup_snapshot_sizes.return_value = {"release": 30095} @@ -223,7 +227,7 @@ swh_scheduler.update_metrics() # set deposit origins as empty - get_deposits_list = mocker.patch("swh.web.misc.coverage.get_deposits_list") + get_deposits_list = mocker.patch("swh.web.archive_coverage.views.get_deposits_list") get_deposits_list.return_value = [] @@ -239,7 +243,7 @@ client, url, status_code=200, - template_used="misc/coverage.html", + template_used="archive-coverage.html", server_name=SWH_WEB_SERVER_NAME, )