Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Django REST Framework's Request.data #302

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update Django REST Framework tests
ronanboiteau committed Jun 2, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit faeb9e5b5d3c54c1954c92d53533e17fb498ab34
2 changes: 1 addition & 1 deletion .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ runs:
python -m pip install --upgrade pip
if [[ ${{ inputs.django-version }} != 'main' ]]; then pip install --pre -q "Django>=${{ inputs.django-version }},<${{ inputs.django-version }}.99"; fi
if [[ ${{ inputs.django-version }} == 'main' ]]; then pip install https://github.com/django/django/archive/main.tar.gz; fi
pip install flake8 django-redis pymemcache
pip install flake8 django-redis pymemcache djangorestframework

- name: Test
shell: sh
11 changes: 6 additions & 5 deletions django_ratelimit/tests.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
from django.views.generic import View

from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.test import APIRequestFactory

from django_ratelimit.decorators import ratelimit
@@ -160,12 +161,12 @@ def test_key_data(self):
@api_view(['POST'])
@ratelimit(key='data:foo', rate='1/m', block=False)
def view(request):
return request.limited
return Response(request.limited)

assert not view(rest_rf.post('/', {'foo': 'a'}))
assert view(rest_rf.post('/', {'foo': 'a'}))
assert not view(rest_rf.post('/', {'foo': 'b'}))
assert view(rest_rf.post('/', {'foo': 'b'}))
assert not view(rest_rf.post('/', {'foo': 'a'})).data
assert view(rest_rf.post('/', {'foo': 'a'})).data
assert not view(rest_rf.post('/', {'foo': 'b'})).data
assert view(rest_rf.post('/', {'foo': 'b'})).data

def test_key_header(self):
def _req():
4 changes: 3 additions & 1 deletion test_settings.py
Original file line number Diff line number Diff line change
@@ -3,8 +3,10 @@
SILENCED_SYSTEM_CHECKS = ['django_ratelimit.E003', 'django_ratelimit.W001']

INSTALLED_APPS = (
'django_ratelimit',
'django.contrib.auth',
'django.contrib.contenttypes',
'rest_framework',
'django_ratelimit',
)

RATELIMIT_USE_CACHE = 'default'