Skip to content

Commit

Permalink
Add a unit test for the queries triggerd by the tab_vulnerability #98
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Dec 2, 2024
1 parent eb4f5e0 commit 571866b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions product_portfolio/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,41 @@ def test_product_portfolio_tab_vulnerability_view_packages_row_rendering(self):
"""
self.assertContains(response, expected, html=True)

def test_product_portfolio_tab_vulnerability_view_queries(self):
self.client.login(username="nexb_user", password="secret")
# Each have a unique vulnerability, and p1 p2 are sharing a common one.
p1 = make_package(self.dataspace, is_vulnerable=True)
p2 = make_package(self.dataspace, is_vulnerable=True)
p3 = make_package(self.dataspace, is_vulnerable=True)
vulnerability1 = make_vulnerability(self.dataspace, affecting=[p1, p2])
vulnerability2 = make_vulnerability(self.dataspace, affecting=[p2, p3])
product1 = make_product(self.dataspace, inventory=[p3])

product_package1 = make_product_package(product1, package=p1)
product_package2 = make_product_package(product1, package=p2)
VulnerabilityAnalysis.objects.create(
product_package=product_package1,
vulnerability=vulnerability1,
state=VulnerabilityAnalysis.State.RESOLVED,
dataspace=self.dataspace,
)
VulnerabilityAnalysis.objects.create(
product_package=product_package2,
vulnerability=vulnerability1,
state=VulnerabilityAnalysis.State.RESOLVED,
dataspace=self.dataspace,
)
VulnerabilityAnalysis.objects.create(
product_package=product_package2,
vulnerability=vulnerability2,
state=VulnerabilityAnalysis.State.RESOLVED,
dataspace=self.dataspace,
)

url = product1.get_url("tab_vulnerabilities")
with self.assertNumQueries(10):
self.client.get(url)

def test_product_portfolio_tab_vulnerability_view_analysis_rendering(self):
self.client.login(username="nexb_user", password="secret")
# Each have a unique vulnerability, and p1 p2 are sharing a common one.
Expand Down

0 comments on commit 571866b

Please sign in to comment.