Skip to content

Commit

Permalink
Move resource in proper locations #95
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Sep 4, 2024
1 parent 3cc94c2 commit a217acf
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 30 deletions.
24 changes: 0 additions & 24 deletions component_catalog/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#

from io import StringIO
from unittest import mock

from django.core import management
from django.core.management.base import CommandError
Expand Down Expand Up @@ -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()
5 changes: 2 additions & 3 deletions component_catalog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = (
Expand Down
46 changes: 46 additions & 0 deletions vulnerabilities/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 2 additions & 3 deletions vulnerabilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")),
Expand Down

0 comments on commit a217acf

Please sign in to comment.