From a217acfe7668de4e71547030852eef597d7f86ad Mon Sep 17 00:00:00 2001 From: tdruez Date: Wed, 4 Sep 2024 14:28:59 +0200 Subject: [PATCH] Move resource in proper locations #95 Signed-off-by: tdruez --- .../component_list_table.html | 0 .../package_list_table.html | 0 component_catalog/tests/test_command.py | 24 ---------- component_catalog/views.py | 5 +- .../tables/vulnerability_list_table.html | 0 .../vulnerabilities}/vulnerability_list.html | 0 vulnerabilities/tests/test_commands.py | 46 +++++++++++++++++++ vulnerabilities/views.py | 5 +- 8 files changed, 50 insertions(+), 30 deletions(-) rename component_catalog/templates/component_catalog/{includes => tables}/component_list_table.html (100%) rename component_catalog/templates/component_catalog/{includes => tables}/package_list_table.html (100%) rename {component_catalog/templates/component_catalog => vulnerabilities/templates/vulnerabilities}/tables/vulnerability_list_table.html (100%) rename {component_catalog/templates/component_catalog => vulnerabilities/templates/vulnerabilities}/vulnerability_list.html (100%) create mode 100644 vulnerabilities/tests/test_commands.py diff --git a/component_catalog/templates/component_catalog/includes/component_list_table.html b/component_catalog/templates/component_catalog/tables/component_list_table.html similarity index 100% rename from component_catalog/templates/component_catalog/includes/component_list_table.html rename to component_catalog/templates/component_catalog/tables/component_list_table.html diff --git a/component_catalog/templates/component_catalog/includes/package_list_table.html b/component_catalog/templates/component_catalog/tables/package_list_table.html similarity index 100% rename from component_catalog/templates/component_catalog/includes/package_list_table.html rename to component_catalog/templates/component_catalog/tables/package_list_table.html diff --git a/component_catalog/tests/test_command.py b/component_catalog/tests/test_command.py index dd712e40..9de66692 100644 --- a/component_catalog/tests/test_command.py +++ b/component_catalog/tests/test_command.py @@ -7,7 +7,6 @@ # from io import StringIO -from unittest import mock from django.core import management from django.core.management.base import CommandError @@ -126,26 +125,3 @@ def test_componentfrompackage_management_command(self): expected = "Error: the following arguments are required: dataspace, username" self.assertEqual(expected, str(error.exception)) - - @mock.patch("vulnerabilities.fetch.fetch_from_vulnerablecode") - @mock.patch("dejacode_toolkit.vulnerablecode.VulnerableCode.is_configured") - def test_fetchvulnerabilities_management_command(self, mock_is_configured, mock_fetch): - mock_is_configured.return_value = False - self.assertFalse(self.dataspace.enable_vulnerablecodedb_access) - - options = [self.dataspace.name] - with self.assertRaises(CommandError) as error: - management.call_command("fetchvulnerabilities", *options) - expected = "VulnerableCode is not enabled on this Dataspace." - self.assertEqual(expected, str(error.exception)) - - self.dataspace.enable_vulnerablecodedb_access = True - self.dataspace.save() - with self.assertRaises(CommandError) as error: - management.call_command("fetchvulnerabilities", *options) - expected = "VulnerableCode is not configured." - self.assertEqual(expected, str(error.exception)) - - mock_is_configured.return_value = True - management.call_command("fetchvulnerabilities", *options) - mock_fetch.assert_called_once() diff --git a/component_catalog/views.py b/component_catalog/views.py index 5b6bf3f4..05bca001 100644 --- a/component_catalog/views.py +++ b/component_catalog/views.py @@ -76,7 +76,6 @@ from dejacode_toolkit.scancodeio import ScanCodeIO from dejacode_toolkit.scancodeio import get_package_download_url from dejacode_toolkit.scancodeio import get_scan_results_as_file_url -from dejacode_toolkit.vulnerablecode import VulnerableCode from dje import tasks from dje.client_data import add_client_data from dje.models import DejacodeUser @@ -347,7 +346,7 @@ class ComponentListView( add_to_product_perm = "product_portfolio.add_productcomponent" template_name = "component_catalog/base_component_package_list.html" filterset_class = ComponentFilterSet - template_list_table = "component_catalog/includes/component_list_table.html" + template_list_table = "component_catalog/tables/component_list_table.html" include_reference_dataspace = True put_results_in_session = True paginate_by = settings.PAGINATE_BY or 200 @@ -961,7 +960,7 @@ class PackageListView( add_to_product_perm = "product_portfolio.add_productpackage" filterset_class = PackageFilterSet template_name = "component_catalog/package_list.html" - template_list_table = "component_catalog/includes/package_list_table.html" + template_list_table = "component_catalog/tables/package_list_table.html" include_reference_dataspace = True put_results_in_session = True table_headers = ( diff --git a/component_catalog/templates/component_catalog/tables/vulnerability_list_table.html b/vulnerabilities/templates/vulnerabilities/tables/vulnerability_list_table.html similarity index 100% rename from component_catalog/templates/component_catalog/tables/vulnerability_list_table.html rename to vulnerabilities/templates/vulnerabilities/tables/vulnerability_list_table.html diff --git a/component_catalog/templates/component_catalog/vulnerability_list.html b/vulnerabilities/templates/vulnerabilities/vulnerability_list.html similarity index 100% rename from component_catalog/templates/component_catalog/vulnerability_list.html rename to vulnerabilities/templates/vulnerabilities/vulnerability_list.html diff --git a/vulnerabilities/tests/test_commands.py b/vulnerabilities/tests/test_commands.py new file mode 100644 index 00000000..67e33829 --- /dev/null +++ b/vulnerabilities/tests/test_commands.py @@ -0,0 +1,46 @@ +# +# Copyright (c) nexB Inc. and others. All rights reserved. +# DejaCode is a trademark of nexB Inc. +# SPDX-License-Identifier: AGPL-3.0-only +# See https://github.com/aboutcode-org/dejacode for support or download. +# See https://aboutcode.org for more information about AboutCode FOSS projects. +# + +from unittest import mock + +from django.core import management +from django.core.management.base import CommandError +from django.test import TestCase + +from component_catalog.models import Component +from dje.models import Dataspace +from dje.tests import create_superuser + + +class VulnerabilityManagementCommandsTestCase(TestCase): + def setUp(self): + self.dataspace = Dataspace.objects.create(name="nexB") + self.super_user = create_superuser("super_user", self.dataspace) + + @mock.patch("vulnerabilities.fetch.fetch_from_vulnerablecode") + @mock.patch("dejacode_toolkit.vulnerablecode.VulnerableCode.is_configured") + def test_fetchvulnerabilities_management_command(self, mock_is_configured, mock_fetch): + mock_is_configured.return_value = False + self.assertFalse(self.dataspace.enable_vulnerablecodedb_access) + + options = [self.dataspace.name] + with self.assertRaises(CommandError) as error: + management.call_command("fetchvulnerabilities", *options) + expected = "VulnerableCode is not enabled on this Dataspace." + self.assertEqual(expected, str(error.exception)) + + self.dataspace.enable_vulnerablecodedb_access = True + self.dataspace.save() + with self.assertRaises(CommandError) as error: + management.call_command("fetchvulnerabilities", *options) + expected = "VulnerableCode is not configured." + self.assertEqual(expected, str(error.exception)) + + mock_is_configured.return_value = True + management.call_command("fetchvulnerabilities", *options) + mock_fetch.assert_called_once() diff --git a/vulnerabilities/views.py b/vulnerabilities/views.py index f75fdc41..7480031f 100644 --- a/vulnerabilities/views.py +++ b/vulnerabilities/views.py @@ -11,7 +11,6 @@ from django.http import Http404 from django.utils.translation import gettext_lazy as _ -from dejacode_toolkit.vulnerablecode import VulnerableCode from dje.views import DataspacedFilterView from dje.views import Header from vulnerabilities.filters import VulnerabilityFilterSet @@ -24,8 +23,8 @@ class VulnerabilityListView( ): model = Vulnerability filterset_class = VulnerabilityFilterSet - template_name = "component_catalog/vulnerability_list.html" - template_list_table = "component_catalog/tables/vulnerability_list_table.html" + template_name = "vulnerabilities/vulnerability_list.html" + template_list_table = "vulnerabilities/tables/vulnerability_list_table.html" table_headers = ( Header("vulnerability_id", _("Vulnerability")), Header("aliases", _("Aliases")),