Skip to content

Commit 2d09f04

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

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

vulnerabilities/tests/test_api_v3.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ def setUp(self):
5656

5757
self.client = APIClient(enforce_csrf_checks=True)
5858

59+
self.allow_request_patcher = patch(
60+
"vulnerabilities.throttling.PermissionBasedUserRateThrottle.allow_request",
61+
return_value=True,
62+
)
63+
self.allow_request_patcher.start()
64+
self.addCleanup(self.allow_request_patcher.stop)
65+
66+
self.anon_patcher = patch(
67+
"rest_framework.throttling.AnonRateThrottle.allow_request",
68+
return_value=True,
69+
)
70+
self.anon_patcher.start()
71+
self.addCleanup(self.anon_patcher.stop)
72+
5973
def test_packages_post_without_details(self):
6074
url = reverse("package-v3-list")
6175

@@ -199,6 +213,19 @@ def setUp(self):
199213
advisory_obj.save()
200214

201215
self.client = APIClient(enforce_csrf_checks=True)
216+
self.allow_request_patcher = patch(
217+
"vulnerabilities.throttling.PermissionBasedUserRateThrottle.allow_request",
218+
return_value=True,
219+
)
220+
self.allow_request_patcher.start()
221+
self.addCleanup(self.allow_request_patcher.stop)
222+
223+
self.anon_patcher = patch(
224+
"rest_framework.throttling.AnonRateThrottle.allow_request",
225+
return_value=True,
226+
)
227+
self.anon_patcher.start()
228+
self.addCleanup(self.anon_patcher.stop)
202229

203230
def test_advisories_post(self):
204231
url = reverse("advisory-v3-list")
@@ -247,6 +274,20 @@ def setUp(self):
247274

248275
self.client = APIClient(enforce_csrf_checks=True)
249276

277+
self.allow_request_patcher = patch(
278+
"vulnerabilities.throttling.PermissionBasedUserRateThrottle.allow_request",
279+
return_value=True,
280+
)
281+
self.allow_request_patcher.start()
282+
self.addCleanup(self.allow_request_patcher.stop)
283+
284+
self.anon_patcher = patch(
285+
"rest_framework.throttling.AnonRateThrottle.allow_request",
286+
return_value=True,
287+
)
288+
self.anon_patcher.start()
289+
self.addCleanup(self.anon_patcher.stop)
290+
250291
def test_get_all_vulnerable_purls(self):
251292
url = reverse("package-v3-list")
252293

@@ -293,6 +334,20 @@ def setUp(self):
293334
url="https://github.com/aboutcode-org/sample",
294335
)
295336

337+
self.allow_request_patcher = patch(
338+
"vulnerabilities.throttling.PermissionBasedUserRateThrottle.allow_request",
339+
return_value=True,
340+
)
341+
self.allow_request_patcher.start()
342+
self.addCleanup(self.allow_request_patcher.stop)
343+
344+
self.anon_patcher = patch(
345+
"rest_framework.throttling.AnonRateThrottle.allow_request",
346+
return_value=True,
347+
)
348+
self.anon_patcher.start()
349+
self.addCleanup(self.anon_patcher.stop)
350+
296351
self.advisory = insert_advisory_v2(self.advisory, "importer_1", print, 100)
297352
self.advisory.is_latest = True
298353
self.advisory._all_impacts_unfurled_at = timezone.now()
@@ -356,6 +411,20 @@ def setUp(self):
356411
defaults={"name": "sample", "type": "pypi", "version": "1.0.0"},
357412
)
358413

414+
self.allow_request_patcher = patch(
415+
"vulnerabilities.throttling.PermissionBasedUserRateThrottle.allow_request",
416+
return_value=True,
417+
)
418+
self.allow_request_patcher.start()
419+
self.addCleanup(self.allow_request_patcher.stop)
420+
421+
self.anon_patcher = patch(
422+
"rest_framework.throttling.AnonRateThrottle.allow_request",
423+
return_value=True,
424+
)
425+
self.anon_patcher.start()
426+
self.addCleanup(self.anon_patcher.stop)
427+
359428
self.advisory_data = AdvisoryDataV2(
360429
advisory_id="AVID-123",
361430
aliases=[],
@@ -490,6 +559,21 @@ def test_advisory_set_member_patches_aggregation(self):
490559

491560

492561
class TestPackageTypesView(APITestCase):
562+
def setUp(self):
563+
self.allow_request_patcher = patch(
564+
"vulnerabilities.throttling.PermissionBasedUserRateThrottle.allow_request",
565+
return_value=True,
566+
)
567+
self.allow_request_patcher.start()
568+
self.addCleanup(self.allow_request_patcher.stop)
569+
570+
self.anon_patcher = patch(
571+
"rest_framework.throttling.AnonRateThrottle.allow_request",
572+
return_value=True,
573+
)
574+
self.anon_patcher.start()
575+
self.addCleanup(self.anon_patcher.stop)
576+
493577
def test_returns_distinct_types_and_caches_response(self):
494578
cache.delete("package_types")
495579

0 commit comments

Comments
 (0)