Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tushar Goel <[email protected]>
  • Loading branch information
TG1999 committed Jan 6, 2025
1 parent da1862e commit a9cfe8d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions vulnerabilities/tests/test_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def test_filter_vulnerabilities_multiple_ids(self):
url = reverse("vulnerability-v2-list")
with self.assertNumQueries(5):
response = self.client.get(
url, {"vulnerability_id": ["VCID-1234", "VCID-5678"]}, format="json"
)
url, {"vulnerability_id": ["VCID-1234", "VCID-5678"]}, format="json"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data["results"]["vulnerabilities"]), 2)

Expand All @@ -136,8 +136,8 @@ def test_filter_vulnerabilities_multiple_aliases(self):
url = reverse("vulnerability-v2-list")
with self.assertNumQueries(5):
response = self.client.get(
url, {"alias": ["CVE-2021-1234", "CVE-2021-5678"]}, format="json"
)
url, {"alias": ["CVE-2021-1234", "CVE-2021-5678"]}, format="json"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data["results"]["vulnerabilities"]), 2)

Expand Down Expand Up @@ -250,7 +250,9 @@ def test_filter_packages_by_affected_vulnerability(self):
"""
url = reverse("package-v2-list")
with self.assertNumQueries(19):
response = self.client.get(url, {"affected_by_vulnerability": "VCID-1234"}, format="json")
response = self.client.get(
url, {"affected_by_vulnerability": "VCID-1234"}, format="json"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data["results"]["packages"]), 1)
self.assertEqual(response.data["results"]["packages"][0]["purl"], "pkg:pypi/[email protected]")
Expand Down Expand Up @@ -346,7 +348,9 @@ def test_invalid_vulnerability_filter(self):
"""
url = reverse("package-v2-list")
with self.assertNumQueries(4):
response = self.client.get(url, {"affected_by_vulnerability": "VCID-9999"}, format="json")
response = self.client.get(
url, {"affected_by_vulnerability": "VCID-9999"}, format="json"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data["results"]["packages"]), 0)

Expand All @@ -357,7 +361,9 @@ def test_invalid_purl_filter(self):
"""
url = reverse("package-v2-list")
with self.assertNumQueries(4):
response = self.client.get(url, {"purl": "pkg:nonexistent/[email protected]"}, format="json")
response = self.client.get(
url, {"purl": "pkg:nonexistent/[email protected]"}, format="json"
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data["results"]["packages"]), 0)

Expand Down

0 comments on commit a9cfe8d

Please sign in to comment.