Skip to content

Commit 06e11cb

Browse files
committed
OpenConceptLab/ocl_issues#2121 | throttling | lite --> standard
1 parent 561c915 commit 06e11cb

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

core/common/throttling.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class GuestDayThrottle(UserRateThrottle):
1111
scope = 'guest_day'
1212

1313

14-
class LiteMinuteThrottle(UserRateThrottle):
15-
scope = 'lite_minute'
14+
class StandardMinuteThrottle(UserRateThrottle):
15+
scope = 'standard_minute'
1616

1717

18-
class LiteDayThrottle(UserRateThrottle):
19-
scope = 'lite_day'
18+
class StandardDayThrottle(UserRateThrottle):
19+
scope = 'standard_day'
2020

2121

2222
class ThrottleUtil:
@@ -42,4 +42,4 @@ def get_throttles_by_user_plan(user):
4242
# order is important, first one has to be minute throttle
4343
if get(user, 'api_rate_limit.is_guest') or not get(user, 'is_authenticated'):
4444
return [GuestMinuteThrottle(), GuestDayThrottle()]
45-
return [LiteMinuteThrottle(), LiteDayThrottle()]
45+
return [StandardMinuteThrottle(), StandardDayThrottle()]

core/integration_tests/tests_users.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def setUp(self):
792792

793793
def test_put_bad_request(self):
794794
user = UserProfileFactory()
795-
self.assertEqual(user.api_rate_limit.rate_plan, 'lite')
795+
self.assertEqual(user.api_rate_limit.rate_plan, 'standard')
796796

797797
response = self.client.put(
798798
f'/users/{user.username}/rate-limit/',
@@ -805,12 +805,12 @@ def test_put_bad_request(self):
805805
response.data,
806806
{
807807
'detail': ErrorDetail(
808-
string='"rate_plan" needs to be one of "guest" or "lite"', code='bad_request')
808+
string='"rate_plan" needs to be one of "guest" or "standard"', code='bad_request')
809809
}
810810
)
811811

812812
user.refresh_from_db()
813-
self.assertEqual(user.api_rate_limit.rate_plan, 'lite')
813+
self.assertEqual(user.api_rate_limit.rate_plan, 'standard')
814814

815815
response = self.client.put(
816816
f'/users/{user.username}/rate-limit/',
@@ -821,7 +821,7 @@ def test_put_bad_request(self):
821821
self.assertEqual(response.status_code, 400)
822822
self.assertEqual(response.data, {'rate_plan': ["Value 'blah' is not a valid choice."]})
823823

824-
self.assertEqual(user.api_rate_limit.rate_plan, 'lite')
824+
self.assertEqual(user.api_rate_limit.rate_plan, 'standard')
825825

826826
response = self.client.put(
827827
f'/users/{user.username}/rate-limit/',
@@ -833,7 +833,7 @@ def test_put_bad_request(self):
833833

834834
def test_put_204(self):
835835
user = UserProfileFactory()
836-
self.assertEqual(user.api_rate_limit.rate_plan, 'lite')
836+
self.assertEqual(user.api_rate_limit.rate_plan, 'standard')
837837

838838
response = self.client.put(
839839
f'/users/{user.username}/rate-limit/',

core/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@
182182
REST_FRAMEWORK['DEFAULT_THROTTLE_RATES'] = {
183183
'guest_minute': '400/minute',
184184
'guest_day': '10000/day',
185-
'lite_minute': '500/minute',
186-
'lite_day': '20000/day',
185+
'standard_minute': '500/minute',
186+
'standard_day': '20000/day',
187187
}
188188
MIDDLEWARE = [*MIDDLEWARE, 'core.middlewares.middlewares.ThrottleHeadersMiddleware']
189189

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 4.2.16 on 2025-03-18 02:12
2+
3+
from django.db import migrations
4+
5+
6+
def update_api_rate_limit_plan(apps, schema_editor):
7+
UserRateLimit = apps.get_model('users', 'UserRateLimit')
8+
UserRateLimit.objects.update(rate_plan='standard')
9+
10+
11+
class Migration(migrations.Migration):
12+
13+
dependencies = [
14+
('users', '0032_alter_userratelimit_rate_plan'),
15+
]
16+
17+
operations = [
18+
migrations.RunPython(update_api_rate_limit_plan),
19+
]

core/users/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,34 @@ def uri(self):
4444

4545

4646
class UserRateLimit(BaseModel):
47-
LITE_PLAN = 'lite'
47+
STANDARD_PLAN = 'standard'
4848
GUEST_PLAN = 'guest'
4949

5050
class Meta:
5151
db_table = 'user_api_rate_limits'
5252

5353
RATE_PLANS = (
54-
(LITE_PLAN, LITE_PLAN),
54+
(STANDARD_PLAN, STANDARD_PLAN),
5555
(GUEST_PLAN, GUEST_PLAN),
5656
)
5757

5858
user = models.OneToOneField('users.UserProfile', on_delete=models.CASCADE, related_name='api_rate_limit')
59-
rate_plan = models.CharField(choices=RATE_PLANS, max_length=100, default=LITE_PLAN)
59+
rate_plan = models.CharField(choices=RATE_PLANS, max_length=100, default=STANDARD_PLAN)
6060
public_access = None
6161
uri = None
6262
extras = None
6363

6464
@property
65-
def is_lite(self):
66-
return self.rate_plan == self.LITE_PLAN
65+
def is_standard(self):
66+
return self.rate_plan == self.STANDARD_PLAN
6767

6868
@property
6969
def is_guest(self):
7070
return self.rate_plan == self.GUEST_PLAN
7171

7272
def clean(self):
7373
if not self.rate_plan:
74-
self.rate_plan = self.LITE_PLAN
74+
self.rate_plan = self.STANDARD_PLAN
7575
super().clean()
7676

7777
@classmethod

core/users/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def update(self, request, *args, **kwargs):
475475
rate_plan = self.request.data.get('rate_plan', None)
476476

477477
if not rate_plan:
478-
raise Http400('"rate_plan" needs to be one of "guest" or "lite"')
478+
raise Http400('"rate_plan" needs to be one of "guest" or "standard"')
479479
try:
480480
UserRateLimit.upsert(self.get_object(), rate_plan, request.user)
481481
except ValidationError as ex:

0 commit comments

Comments
 (0)