Skip to content

Commit

Permalink
Fix part of the failing tests #98
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Nov 14, 2024
1 parent ed37abe commit 750b65a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 17 deletions.
1 change: 1 addition & 0 deletions component_catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@ def only_rendering_fields(self):
*PACKAGE_URL_FIELDS,
"filename",
"license_expression",
"risk_score",
"dataspace__name",
"dataspace__show_usage_policy_in_user_views",
)
Expand Down
1 change: 1 addition & 0 deletions dje/copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"project_uuid",
"default_assignee",
"affected_by_vulnerabilities",
"risk_score",
]


Expand Down
3 changes: 3 additions & 0 deletions dje/tests/testfiles/test_dataset_cc_only.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"last_modified_date": "2011-08-24T09:20:01Z",
"reference_notes": "",
"usage_policy": null,
"risk_score": null,
"declared_license_expression": "",
"other_license_expression": "",
"holder": "",
Expand Down Expand Up @@ -114,6 +115,7 @@
"last_modified_date": "2011-08-24T09:20:01Z",
"reference_notes": "",
"usage_policy": null,
"risk_score": null,
"declared_license_expression": "",
"other_license_expression": "",
"holder": "",
Expand Down Expand Up @@ -280,6 +282,7 @@
"version": "",
"qualifiers": "",
"subpath": "",
"risk_score": null,
"declared_license_expression": "",
"other_license_expression": "",
"holder": "",
Expand Down
1 change: 1 addition & 0 deletions dje/tests/testfiles/test_dataset_pp_only.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"version": "",
"qualifiers": "",
"subpath": "",
"risk_score": null,
"declared_license_expression": "",
"other_license_expression": "",
"holder": "",
Expand Down
8 changes: 4 additions & 4 deletions product_portfolio/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ def test_product_portfolio_detail_view_tab_vulnerability_view_filters(self):
self.client.login(username="nexb_user", password="secret")
url = self.product1.get_url("tab_vulnerabilities")
response = self.client.get(url)
self.assertContains(response, "?vulnerabilities-max_score=#vulnerabilities")
self.assertContains(response, "?vulnerabilities-sort=max_score#vulnerabilities")
response = self.client.get(url + "?vulnerabilities-sort=max_score#vulnerabilities")
self.assertContains(response, "?vulnerabilities-sort=-max_score#vulnerabilities")
self.assertContains(response, "?vulnerabilities-risk_score=#vulnerabilities")
self.assertContains(response, "?vulnerabilities-sort=risk_score#vulnerabilities")
response = self.client.get(url + "?vulnerabilities-sort=risk_score#vulnerabilities")
self.assertContains(response, "?vulnerabilities-sort=-risk_score#vulnerabilities")

@mock.patch("dejacode_toolkit.vulnerablecode.VulnerableCode.is_configured")
def test_product_portfolio_detail_view_tab_vulnerability_label(self, mock_is_configured):
Expand Down
1 change: 1 addition & 0 deletions reporting/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,7 @@ def test_get_model_data_for_component_column_template(self):
{"group": "Direct Fields", "value": "reference_notes", "label": "reference_notes"},
{"group": "Direct Fields", "label": "release_date", "value": "release_date"},
{"group": "Direct Fields", "label": "request_count", "value": "request_count"},
{"group": "Direct Fields", "label": "risk_score", "value": "risk_score"},
{
"group": "Direct Fields",
"label": "sublicense_allowed",
Expand Down
4 changes: 4 additions & 0 deletions vulnerabilities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Vulnerability(HistoryDateFieldsMixin, DataspacedModel):
)
exploitability = models.DecimalField(
null=True,
blank=True,
max_digits=4,
decimal_places=2,
help_text=_(
Expand All @@ -114,6 +115,7 @@ class Vulnerability(HistoryDateFieldsMixin, DataspacedModel):
)
weighted_severity = models.DecimalField(
null=True,
blank=True,
max_digits=4,
decimal_places=2,
help_text=_(
Expand All @@ -123,6 +125,7 @@ class Vulnerability(HistoryDateFieldsMixin, DataspacedModel):
)
risk_score = models.DecimalField(
null=True,
blank=True,
max_digits=4,
decimal_places=2,
help_text=_(
Expand Down Expand Up @@ -363,6 +366,7 @@ class AffectedByVulnerabilityMixin(models.Model):
# Based on vulnerablecode.vulnerabilities.models.Package
risk_score = models.DecimalField(
null=True,
blank=True,
max_digits=4,
decimal_places=2,
help_text=_(
Expand Down
13 changes: 0 additions & 13 deletions vulnerabilities/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,8 @@ def test_vulnerability_model_create_from_data(self):
self.assertEqual(vulnerability_data["aliases"], vulnerability1.aliases)
self.assertEqual(vulnerability_data["references"], vulnerability1.references)
self.assertEqual(vulnerability_data["resource_url"], vulnerability1.resource_url)
self.assertEqual(7.5, vulnerability1.min_score)
self.assertEqual(7.5, vulnerability1.max_score)
self.assertQuerySetEqual(vulnerability1.affected_packages.all(), [package1])

def test_vulnerability_model_create_from_data_computed_scores(self):
response_file = self.data / "vulnerabilities" / "idna_3.6_response.json"
json_data = json.loads(response_file.read_text())
affected_by_vulnerabilities = json_data["results"][0]["affected_by_vulnerabilities"]
vulnerability1 = Vulnerability.create_from_data(
dataspace=self.dataspace,
data=affected_by_vulnerabilities[0],
)
self.assertEqual(2.1, vulnerability1.min_score)
self.assertEqual(7.5, vulnerability1.max_score)

def test_vulnerability_model_queryset_count_methods(self):
package1 = make_package(self.dataspace)
package2 = make_package(self.dataspace)
Expand Down

0 comments on commit 750b65a

Please sign in to comment.