Add tests for registration ability outer registration dates
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
fe399c869d
commit
ab2e49e8fb
|
@ -1,6 +1,5 @@
|
|||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from datetime import datetime
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
|
@ -8,6 +7,7 @@ from django.contrib.auth.forms import UserCreationForm
|
|||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.forms import FileInput
|
||||
from django.utils import timezone
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
@ -40,15 +40,15 @@ class SignupForm(UserCreationForm):
|
|||
|
||||
def clean(self):
|
||||
# Check that registrations are opened
|
||||
now = datetime.now()
|
||||
now = timezone.now()
|
||||
if now < settings.REGISTRATION_DATES['open']:
|
||||
self.add_error(None, format_lazy(_("Registrations are not opened yet. "
|
||||
"They will open on the {opening_date:%Y-%m-%d %H:%M}."),
|
||||
opening_date=settings.REGISTRATION_DATES['open']))
|
||||
"They will open on the {opening_date:%Y-%m-%d %H:%M}."),
|
||||
opening_date=settings.REGISTRATION_DATES['open']))
|
||||
elif now > settings.REGISTRATION_DATES['close']:
|
||||
self.add_error(None, format_lazy(_("Registrations for this year are closed since "
|
||||
"{opening_date:%Y-%m-%d %H:%M}."),
|
||||
opening_date=settings.REGISTRATION_DATES['close']))
|
||||
"{closing_date:%Y-%m-%d %H:%M}."),
|
||||
closing_date=settings.REGISTRATION_DATES['close']))
|
||||
return super().clean()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from datetime import date, datetime
|
||||
from datetime import date
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
|
@ -774,7 +774,7 @@ class Payment(models.Model):
|
|||
return checkout_intent
|
||||
|
||||
tournament = self.tournament
|
||||
year = datetime.now().year
|
||||
year = timezone.now().year
|
||||
base_site = "https://" + Site.objects.first().domain
|
||||
checkout_intent = helloasso.create_checkout_intent(
|
||||
amount=100 * self.amount,
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from datetime import timedelta
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.test import TestCase
|
||||
from django.test import override_settings, TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.http import urlsafe_base64_encode
|
||||
from participation.models import Team
|
||||
|
@ -114,6 +117,9 @@ class TestRegistration(TestCase):
|
|||
self.assertRedirects(response, "http://" + Site.objects.get().domain +
|
||||
str(self.coach.registration.get_absolute_url()), 302, 200)
|
||||
|
||||
# Ensure that we are between registration dates
|
||||
@override_settings(REGISTRATION_DATES={'open': timezone.now() - timedelta(days=1),
|
||||
'close': timezone.now() + timedelta(days=1)})
|
||||
def test_registration(self):
|
||||
"""
|
||||
Ensure that the signup form is working successfully.
|
||||
|
@ -223,6 +229,52 @@ class TestRegistration(TestCase):
|
|||
response = self.client.get(reverse("registration:email_validation_resend", args=(user.pk,)))
|
||||
self.assertRedirects(response, reverse("registration:email_validation_sent"), 302, 200)
|
||||
|
||||
def test_registration_dates(self):
|
||||
"""
|
||||
Test that registrations are working only between registration dates.
|
||||
"""
|
||||
self.client.logout()
|
||||
|
||||
# Test that registration between open and close dates are working
|
||||
with override_settings(REGISTRATION_DATES={'open': timezone.now() - timedelta(days=2),
|
||||
'close': timezone.now() + timedelta(days=2)}):
|
||||
response = self.client.get(reverse("registration:signup"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("<i class=\"fas fa-user-plus\"></i> Register", response.content.decode())
|
||||
self.assertNotIn("registrations are not opened", response.content.decode())
|
||||
self.assertNotIn("Registrations are closed", response.content.decode())
|
||||
|
||||
response = self.client.post(reverse("registration:signup"))
|
||||
self.assertFormError(response.context['form'], None, [])
|
||||
|
||||
# Test that registration before open date is not working
|
||||
with override_settings(REGISTRATION_DATES={'open': timezone.now() + timedelta(days=1),
|
||||
'close': timezone.now() + timedelta(days=2)}):
|
||||
response = self.client.get(reverse("registration:signup"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotIn("<i class=\"fas fa-user-plus\"></i> Register", response.content.decode())
|
||||
self.assertIn("registrations are not opened", response.content.decode())
|
||||
|
||||
response = self.client.post(reverse("registration:signup"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertFormError(response.context['form'], None,
|
||||
"Registrations are not opened yet. They will open on the "
|
||||
f"{settings.REGISTRATION_DATES['open']:%Y-%m-%d %H:%M}.")
|
||||
|
||||
# Test that registration after close date is not working
|
||||
with override_settings(REGISTRATION_DATES={'open': timezone.now() - timedelta(days=2),
|
||||
'close': timezone.now() - timedelta(days=1)}):
|
||||
response = self.client.get(reverse("registration:signup"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotIn("<i class=\"fas fa-user-plus\"></i> Register", response.content.decode())
|
||||
self.assertIn("Registrations are closed", response.content.decode())
|
||||
|
||||
response = self.client.post(reverse("registration:signup"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertFormError(response.context['form'], None,
|
||||
"Registrations for this year are closed since "
|
||||
f"{settings.REGISTRATION_DATES['close']:%Y-%m-%d %H:%M}.")
|
||||
|
||||
def test_login(self):
|
||||
"""
|
||||
With a registered user, try to log in
|
||||
|
|
Loading…
Reference in New Issue