Skip to content

Commit

Permalink
Fix unit tests #102
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Dec 24, 2024
1 parent 36d714e commit 17ba3f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions product_portfolio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,12 @@ def annotate_weighted_risk_score(self):
)

def update_weighted_risk_score(self):
"""
Updates the `weighted_risk_score` for all objects in the queryset.
This directly writes to the database and doesn't trigger model `save()`
methods, so any side effects in `save()` won't be executed.
"""
"""
Update the weighted_risk_score using the computed annotation from
`self.annotate_weighted_risk_score()`
Expand Down
18 changes: 12 additions & 6 deletions product_portfolio/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,21 @@ def test_product_portfolio_tab_vulnerability_view_filters(self):
def test_product_portfolio_tab_vulnerability_view_packages_row_rendering(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)
p1 = make_package(self.dataspace)
p2 = make_package(self.dataspace)
vulnerability1 = make_vulnerability(self.dataspace, affecting=[p1, p2])
product1 = make_product(self.dataspace, inventory=[p1, p2, p3])
make_vulnerability(self.dataspace, affecting=[p1])
product1 = make_product(self.dataspace, inventory=[p1, p2])

url = product1.get_url("tab_vulnerabilities")
response = self.client.get(url)
expected = f'<td rowspan="2"><strong>{vulnerability1.vcid}</strong></td>'
expected = f"""
<td rowspan="2">
<strong>
<a href="{p1.get_absolute_url()}#vulnerabilities" target="_blank">{p1}</a>
</strong>
</td>
"""
self.assertContains(response, expected, html=True)

expected = f"""
Expand Down Expand Up @@ -471,7 +477,7 @@ def test_product_portfolio_detail_view_tab_vulnerability_label(self, mock_is_con
package1 = make_package(self.dataspace, is_vulnerable=True)
make_product_package(self.product1, package=package1)
response = self.client.get(url)
expected = '<span class="badge badge-vulnerability">1</span>'
expected = 'Vulnerabilities<span class="badge badge-vulnerability'
self.assertContains(response, expected)

def test_product_portfolio_detail_view_object_type_filter_in_inventory_tab(self):
Expand Down

0 comments on commit 17ba3f3

Please sign in to comment.