Skip to content

Commit 9056185

Browse files
committed
Fix tests
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 7972776 commit 9056185

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

vulnerabilities/api_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def get_affected_by_vulnerabilities(self, package):
379379

380380
for hash in grouped_advisories:
381381
advs.append(grouped_advisories[hash])
382-
382+
383383
result = []
384384

385385
for advisory in advs:

vulnerabilities/tests/test_api_v2.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -850,37 +850,39 @@ def setUp(self):
850850
)
851851

852852
self.package = PackageV2.objects.from_purl(purl="pkg:pypi/sample@1.0.0")
853-
self.impact = ImpactedPackage.objects.create(advisory=self.advisory)
853+
self.impact = ImpactedPackage.objects.create(
854+
advisory=self.advisory, base_purl="pkg:pypi/sample"
855+
)
854856
self.impact.affecting_packages.add(self.package)
855857

856858
self.client = APIClient(enforce_csrf_checks=True)
857859

858860
def test_list_with_purl_filter(self):
859861
url = reverse("package-v3-list")
860-
with self.assertNumQueries(23):
862+
with self.assertNumQueries(29):
861863
response = self.client.get(url, {"purl": "pkg:pypi/sample@1.0.0"})
862864
assert response.status_code == 200
863865
assert "packages" in response.data["results"]
864-
assert "advisories" in response.data["results"]
865-
assert self.advisory.avid in response.data["results"]["advisories"]
866+
assert "advisories_by_id" in response.data["results"]
867+
assert self.advisory.avid in response.data["results"]["advisories_by_id"]
866868

867869
def test_bulk_lookup(self):
868870
url = reverse("package-v3-bulk-lookup")
869-
with self.assertNumQueries(22):
871+
with self.assertNumQueries(28):
870872
response = self.client.post(url, {"purls": ["pkg:pypi/sample@1.0.0"]}, format="json")
871873
assert response.status_code == 200
872874
assert "packages" in response.data
873-
assert "advisories" in response.data
874-
assert self.advisory.avid in response.data["advisories"]
875+
assert "advisories_by_id" in response.data
876+
assert self.advisory.avid in response.data["advisories_by_id"]
875877

876878
def test_bulk_search_plain(self):
877879
url = reverse("package-v3-bulk-search")
878880
payload = {"purls": ["pkg:pypi/sample@1.0.0"], "plain_purl": True, "purl_only": False}
879-
with self.assertNumQueries(22):
881+
with self.assertNumQueries(28):
880882
response = self.client.post(url, payload, format="json")
881883
assert response.status_code == 200
882884
assert "packages" in response.data
883-
assert "advisories" in response.data
885+
assert "advisories_by_id" in response.data
884886

885887
def test_bulk_search_purl_only(self):
886888
url = reverse("package-v3-bulk-search")
@@ -892,7 +894,7 @@ def test_bulk_search_purl_only(self):
892894

893895
def test_lookup_single_package(self):
894896
url = reverse("package-v3-lookup")
895-
with self.assertNumQueries(15):
897+
with self.assertNumQueries(21):
896898
response = self.client.post(url, {"purl": "pkg:pypi/sample@1.0.0"}, format="json")
897899
assert response.status_code == 200
898900
assert any(pkg["purl"] == "pkg:pypi/sample@1.0.0" for pkg in response.data)

vulnerabilities/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ def get_context_data(self, **kwargs):
214214
for hash in fixing_avid_by_hash:
215215
fixing_advs.append(fixing_avid_by_hash[hash])
216216

217-
218217
context["package"] = package
219218
context["next_non_vulnerable"] = next_non_vulnerable
220219
context["latest_non_vulnerable"] = latest_non_vulnerable

0 commit comments

Comments
 (0)