-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete refactoring to new vulnerabilities module #95
Signed-off-by: tdruez <tdruez@nexb.com>
- Loading branch information
Showing
4 changed files
with
70 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# | ||
# 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 django.test import TestCase | ||
|
||
from dje.models import Dataspace | ||
from vulnerabilities.filters import VulnerabilityFilterSet | ||
from vulnerabilities.tests import make_vulnerability | ||
|
||
|
||
class VulnerabilityFilterSetTestCase(TestCase): | ||
def setUp(self): | ||
self.dataspace = Dataspace.objects.create(name="Reference") | ||
self.vulnerability1 = make_vulnerability(self.dataspace, max_score=10.0) | ||
self.vulnerability2 = make_vulnerability( | ||
self.dataspace, max_score=5.5, aliases=["ALIAS-V2"] | ||
) | ||
self.vulnerability3 = make_vulnerability(self.dataspace, max_score=2.0) | ||
self.vulnerability4 = make_vulnerability(self.dataspace, max_score=None) | ||
|
||
def test_vulnerability_filterset_search(self): | ||
data = {"q": self.vulnerability1.vulnerability_id} | ||
filterset = VulnerabilityFilterSet(dataspace=self.dataspace, data=data) | ||
self.assertQuerySetEqual(filterset.qs, [self.vulnerability1]) | ||
|
||
data = {"q": "ALIAS-V2"} | ||
filterset = VulnerabilityFilterSet(dataspace=self.dataspace, data=data) | ||
self.assertQuerySetEqual(filterset.qs, [self.vulnerability2]) | ||
|
||
def test_vulnerability_filterset_sort_nulls_last_ordering(self): | ||
data = {"sort": "max_score"} | ||
filterset = VulnerabilityFilterSet(dataspace=self.dataspace, data=data) | ||
expected = [ | ||
self.vulnerability3, | ||
self.vulnerability2, | ||
self.vulnerability1, | ||
self.vulnerability4, # The max_score=None are always last | ||
] | ||
self.assertQuerySetEqual(filterset.qs, expected) | ||
|
||
data = {"sort": "-max_score"} | ||
filterset = VulnerabilityFilterSet(dataspace=self.dataspace, data=data) | ||
expected = [ | ||
self.vulnerability1, | ||
self.vulnerability2, | ||
self.vulnerability3, | ||
self.vulnerability4, # The max_score=None are always last | ||
] | ||
self.assertQuerySetEqual(filterset.qs, expected) | ||
|
||
def test_vulnerability_filterset_max_score(self): | ||
data = {"max_score": "critical"} | ||
filterset = VulnerabilityFilterSet(dataspace=self.dataspace, data=data) | ||
self.assertQuerySetEqual(filterset.qs, [self.vulnerability1]) | ||
data = {"max_score": "high"} | ||
filterset = VulnerabilityFilterSet(dataspace=self.dataspace, data=data) | ||
self.assertQuerySetEqual(filterset.qs, []) | ||
data = {"max_score": "medium"} | ||
filterset = VulnerabilityFilterSet(dataspace=self.dataspace, data=data) | ||
self.assertQuerySetEqual(filterset.qs, [self.vulnerability2]) | ||
data = {"max_score": "low"} | ||
filterset = VulnerabilityFilterSet(dataspace=self.dataspace, data=data) | ||
self.assertQuerySetEqual(filterset.qs, [self.vulnerability3]) |