Skip to content

Commit

Permalink
Add unit test for patch method on VulnerabilityAnalysis API endpoint #…
Browse files Browse the repository at this point in the history
…103

Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Dec 11, 2024
1 parent e1a5730 commit 52b6f3a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Release notes
- Add new `is_reachable` field on the VulnerabilityAnalysis model.
It can be used to declare if a this vulnerability is reachable, not reachable, or
if this fact is not known in the context of a Product Package.
Reachability column added in the "Vulnerability" tab.
Add filter by "Reachability" from the column header.
The is_reachable value can be set from the "Vulnerability analysis" modal form.
Add a VulnerabilityAnalysis REST API endpoint.
https://github.com/aboutcode-org/dejacode/issues/103

### Version 5.2.1
Expand Down
22 changes: 21 additions & 1 deletion vulnerabilities/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_api_vulnerability_analysis_detail_endpoint(self):
make_vulnerability_analysis(self.product_package1, self.vulnerability2)
make_vulnerability_analysis(self.product_package1, self.vulnerability3)

with self.assertNumQueries(6):
with self.assertNumQueries(5):
response = self.client.get(detail_url)

self.assertContains(response, detail_url)
Expand Down Expand Up @@ -191,3 +191,23 @@ def test_api_vulnerability_analysis_endpoint_create(self):
self.assertEqual("detail", response.data["detail"])
self.assertEqual(["can_not_fix"], response.data["responses"])
self.assertTrue(response.data["is_reachable"])

def test_api_vulnerability_analysis_endpoint_patch(self):
self.client.login(username="super_user", password="secret")
analysis1 = make_vulnerability_analysis(self.product_package1, self.vulnerability1)
self.assertIsNone(analysis1.is_reachable)
detail_url = reverse("api_v2:vulnerabilityanalysis-detail", args=[analysis1.uuid])

data = {"is_reachable": True}
response = self.client.patch(detail_url, data, content_type="application/json")
self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertTrue(response.data["is_reachable"])
analysis1.refresh_from_db()
self.assertTrue(analysis1.is_reachable)

data = {"is_reachable": False}
response = self.client.patch(detail_url, data, content_type="application/json")
self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertFalse(response.data["is_reachable"])
analysis1.refresh_from_db()
self.assertFalse(analysis1.is_reachable)

0 comments on commit 52b6f3a

Please sign in to comment.