File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 1010from unittest .mock import patch
1111
1212from django .contrib .auth .models import User
13+ from django .core .cache import cache
1314from django .db .models import Prefetch
1415from django .urls import reverse
1516from rest_framework import status
@@ -670,6 +671,12 @@ def test_lookup_with_invalid_purl_format(self):
670671
671672class PipelineScheduleV2ViewSetTest (APITestCase ):
672673 def setUp (self ):
674+ # Reset the api throttling for anon user to properly test the
675+ # access on schedule endpoint.
676+ # DRF stores throttling state in cache, clear cache to reset throttling.
677+ # See https://www.django-rest-framework.org/api-guide/throttling/#setting-up-the-cache
678+ cache .clear ()
679+
673680 patcher = patch .object (PipelineSchedule , "create_new_job" )
674681 self .mock_create_new_job = patcher .start ()
675682 self .addCleanup (patcher .stop )
Original file line number Diff line number Diff line change 99
1010import json
1111
12+ from django .core .cache import cache
1213from rest_framework .test import APIClient
1314from rest_framework .test import APITestCase
1415
1718
1819class ThrottleApiTests (APITestCase ):
1920 def setUp (self ):
21+ # Reset the api throttling to properly test the rate limit on anon users.
22+ # DRF stores throttling state in cache, clear cache to reset throttling.
23+ # See https://www.django-rest-framework.org/api-guide/throttling/#setting-up-the-cache
24+ cache .clear ()
25+
2026 # create a basic user
2127 self .
user = ApiUser .
objects .
create_api_user (
username = "[email protected] " )
2228 self .auth = f"Token { self .user .auth_token .key } "
You can’t perform that action at this time.
0 commit comments