Coverage for /home/marco/Code/django-simple-captcha/captcha/validators.py: 72.73%
18 statements
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-15 09:22 +0100
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-15 09:22 +0100
1from rest_framework import exceptions
3from django.utils import timezone
4from django.utils.translation import gettext_lazy as gettext_lazy
6from captcha.conf import settings
7from captcha.models import CaptchaStore
10def captcha_validate(hashkey, response):
11 hashkey, response = hashkey.lower(), response.lower()
13 if not settings.CAPTCHA_GET_FROM_POOL: 13 ↛ 15line 13 didn't jump to line 15 because the condition on line 13 was always true
14 CaptchaStore.remove_expired()
15 if settings.CAPTCHA_TEST_MODE and response.lower() == "passed": 15 ↛ 16line 15 didn't jump to line 16 because the condition on line 15 was never true
16 try:
17 CaptchaStore.objects.get(hashkey=hashkey).delete()
18 except CaptchaStore.DoesNotExist:
19 pass
20 else:
21 try:
22 CaptchaStore.objects.get(
23 response=response, hashkey=hashkey, expiration__gt=timezone.now()
24 ).delete()
25 except CaptchaStore.DoesNotExist:
26 raise exceptions.ValidationError({"error": gettext_lazy("Invalid CAPTCHA")})