Skip to content

Commit 17f3310

Browse files
committed
add missing distinct on filter
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 0bee32d commit 17f3310

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

product_portfolio/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class ProductFilterSet(DataspacedAPIFilterSet):
211211
has_reachable_vulnerability = django_filters.BooleanFilter(
212212
field_name="vulnerability_analyses__is_reachable",
213213
label="Has reachable vulnerability",
214+
distinct=True,
214215
)
215216

216217
class Meta:
@@ -893,6 +894,7 @@ class ProductPackageFilterSet(DataspacedAPIFilterSet):
893894
has_reachable_vulnerability = django_filters.BooleanFilter(
894895
field_name="vulnerability_analyses__is_reachable",
895896
label="Has reachable vulnerability",
897+
distinct=True,
896898
)
897899

898900
class Meta:

product_portfolio/tests/test_api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,28 @@ def test_api_product_has_reachable_vulnerability_filter(self):
15821582
response = self.client.get(self.product_list_url, data)
15831583
self.assertEqual(0, response.data["count"])
15841584

1585+
def test_api_product_has_reachable_vulnerability_filter_no_duplicates(self):
1586+
self.client.login(username="super_user", password="secret")
1587+
vulnerability1 = make_vulnerability(self.dataspace, affecting=self.package1)
1588+
vulnerability2 = make_vulnerability(self.dataspace, affecting=self.package1)
1589+
make_vulnerability_analysis(self.pp1, vulnerability1, is_reachable=True)
1590+
make_vulnerability_analysis(self.pp1, vulnerability2, is_reachable=True)
1591+
1592+
data = {"has_reachable_vulnerability": "true"}
1593+
response = self.client.get(self.product_list_url, data)
1594+
self.assertEqual(1, response.data["count"])
1595+
1596+
def test_api_productpackage_has_reachable_vulnerability_filter_no_duplicates(self):
1597+
self.client.login(username="super_user", password="secret")
1598+
vulnerability1 = make_vulnerability(self.dataspace, affecting=self.package1)
1599+
vulnerability2 = make_vulnerability(self.dataspace, affecting=self.package1)
1600+
make_vulnerability_analysis(self.pp1, vulnerability1, is_reachable=True)
1601+
make_vulnerability_analysis(self.pp1, vulnerability2, is_reachable=True)
1602+
1603+
data = {"has_reachable_vulnerability": "true"}
1604+
response = self.client.get(self.productpackage_list_url, data)
1605+
self.assertEqual(1, response.data["count"])
1606+
15851607
def test_api_codebaseresource_list_endpoint_results(self):
15861608
self.client.login(username="super_user", password="secret")
15871609
response = self.client.get(self.codebase_resource_list_url)

0 commit comments

Comments
 (0)