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

Test throttle rates #1679

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft

Test throttle rates #1679

wants to merge 3 commits into from

Conversation

ar-jan
Copy link
Contributor

@ar-jan ar-jan commented Oct 11, 2024

WiP, some things to resolve here still:

The throttle rate from the fixture is not actually applied, although its value is read correctly in the test function (same for @override_settings). The settings that are actually used are the defaults from common_settings.py.
I thought I might have to use the rest_framework.test APIClient for this, but it seems to behave the same whether I use the default client or drf_client I added here.

cache issue In addition, this is strange: when I test manually with `'registration': '1/minute'`, the first registration succeeds and the second one gets a 429, as expected. But with the default rate of `'registration': '5/minute'` that is (apparently?) picked up by pytest, we get this:

Request 1 status: 201
Request 2 status: 201
Request 3 status: 201
Request 4 status: 201
Request 5 status: 429
Request 6 status: 429

I would've expected Request 5 to still succeed. Caching issue?

@ar-jan
Copy link
Contributor Author

ar-jan commented Oct 17, 2024

The last point was indeed due to the cache from the first registration test.

@@ -46,3 +52,44 @@ def test_register_verification(client, db, django_user_model):
assert allauth_email.email == creds.get('email')
assert allauth_email.verified is True
assert allauth_email.primary is True


def test_register_throttling(client, throttle_settings):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The throttle rate from the fixture is not actually applied, although its value is read correctly in the test function

Perhaps an obvious suggestion, but did you try this?

Suggested change
def test_register_throttling(client, throttle_settings):
def test_register_throttling(throttle_settings, client):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now tried this, but the result is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants