Add Docker-executed pytest suite with >90% coverage
This commit is contained in:
26
apps/comments/tests/test_more.py
Normal file
26
apps/comments/tests/test_more.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import pytest
|
||||
from django.core.cache import cache
|
||||
|
||||
from apps.comments.forms import CommentForm
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_comment_form_rejects_blank_body():
|
||||
form = CommentForm(data={"author_name": "A", "author_email": "a@a.com", "body": " ", "article_id": 1})
|
||||
assert not form.is_valid()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_comment_rate_limit(client, article_page):
|
||||
cache.clear()
|
||||
payload = {
|
||||
"article_id": article_page.id,
|
||||
"author_name": "T",
|
||||
"author_email": "t@example.com",
|
||||
"body": "Hi",
|
||||
"honeypot": "",
|
||||
}
|
||||
for _ in range(3):
|
||||
client.post("/comments/post/", payload)
|
||||
resp = client.post("/comments/post/", payload)
|
||||
assert resp.status_code == 429
|
||||
Reference in New Issue
Block a user