2022-12-02 15:46:43 -08:00
|
|
|
import pytest
|
2022-12-15 14:55:33 -08:00
|
|
|
from django.test.client import Client
|
|
|
|
from pytest_django.asserts import assertContains
|
2022-12-02 15:46:43 -08:00
|
|
|
|
2022-12-15 14:55:33 -08:00
|
|
|
from users.models import Identity
|
2022-12-02 15:46:43 -08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db
|
2023-05-03 21:42:37 -07:00
|
|
|
def test_rate_limit(identity: Identity, client_with_user: Client):
|
2022-12-15 14:55:33 -08:00
|
|
|
"""
|
|
|
|
Tests that the posting rate limit comes into force
|
|
|
|
"""
|
|
|
|
# First post should go through
|
|
|
|
assert identity.posts.count() == 0
|
2023-05-03 21:42:37 -07:00
|
|
|
response = client_with_user.post(
|
|
|
|
f"/@{identity.handle}/compose/", data={"text": "post 1", "visibility": "0"}
|
2022-12-15 14:55:33 -08:00
|
|
|
)
|
|
|
|
assert response.status_code == 302
|
|
|
|
assert identity.posts.count() == 1
|
|
|
|
# Second should not
|
2023-05-03 21:42:37 -07:00
|
|
|
response = client_with_user.post(
|
|
|
|
f"/@{identity.handle}/compose/", data={"text": "post 2", "visibility": "0"}
|
2022-12-15 14:55:33 -08:00
|
|
|
)
|
|
|
|
assertContains(response, "You must wait at least", status_code=200)
|
|
|
|
assert identity.posts.count() == 1
|