Skip to content

Commit 8b8d061

Browse files
committed
Fix test_package_endpoint_throttling by clearing cache in setUp
The throttle cache was not being reset between test runs, causing request counts from previous tests to spill over and trigger the rate limit prematurely. Fix by calling cache.clear() at the start of setUp(). Fixes #<replace-with-your-issue-number> Signed-off-by: clencyc <clency2023@gmail.com>
1 parent fa44d92 commit 8b8d061

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packagedb/tests/test_throttling.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
from unittest.mock import patch
1111

1212
from django.contrib.auth.models import User
13-
13+
from django.core.cache import cache
1414
from rest_framework.test import APIClient
1515
from rest_framework.test import APITestCase
1616

1717

1818
@patch("rest_framework.throttling.UserRateThrottle.get_rate", lambda x: "20/day")
1919
@patch("rest_framework.throttling.AnonRateThrottle.get_rate", lambda x: "10/day")
2020
class ThrottleApiTests(APITestCase):
21+
2122
def setUp(self):
23+
cache.clear()
2224
# create a basic user
2325
self.user = User.objects.create_user(
2426
username="username",

0 commit comments

Comments
 (0)