Add tests for payment management commands

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-02-25 18:58:26 +01:00
parent 9829541289
commit 348004320c
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 53 additions and 0 deletions

View File

@ -4,10 +4,13 @@
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.management import call_command
from django.test import LiveServerTestCase, override_settings, TestCase
from django.urls import reverse
from django.utils import translation
from registration.models import CoachRegistration, Payment, StudentRegistration
from .models import Participation, Team, Tournament
@ -874,6 +877,30 @@ class TestPayment(TestCase):
payment.refresh_from_db()
self.assertFalse(payment.valid)
def test_payment_reminder(self):
"""
Check that the payment reminder command works correctly.
"""
translation.activate('fr')
self.assertEqual(len(mail.outbox), 0)
call_command('remind_payments')
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(mail.outbox[0].subject, "[TFJM²] Rappel pour votre paiement")
payment = Payment.objects.get(registrations=self.user.registration, final=False)
payment2 = Payment.objects.get(registrations=self.second_user.registration, final=False)
payment.type = 'other'
payment.valid = True
payment.save()
payment2.type = 'bank_transfer'
payment2.valid = None
payment2.save()
mail.outbox = []
call_command('remind_payments')
self.assertEqual(len(mail.outbox), 0)
@override_settings(HELLOASSO_TEST_ENDPOINT=True, ROOT_URLCONF="tfjm.helloasso.test_urls")
class TestHelloAssoPayment(LiveServerTestCase):
@ -1076,6 +1103,32 @@ class TestHelloAssoPayment(LiveServerTestCase):
checkout_intent = payment.get_checkout_intent()
self.assertIn('order', checkout_intent)
def test_hello_asso_payment_verification(self):
"""
Check that a payment that is pending verification can be verified.
"""
with self.settings(HELLOASSO_TEST_ENDPOINT_URL=self.live_server_url):
payment = Payment.objects.get(registrations=self.user.registration, final=False)
self.assertFalse(payment.valid)
call_command('check_hello_asso')
payment.refresh_from_db()
self.assertFalse(payment.valid)
self.client.get(reverse('registration:payment_hello_asso', args=(payment.pk,)),
follow=True)
payment.refresh_from_db()
payment.valid = None
payment.additional_information = ""
payment.save()
self.assertIsNone(payment.valid)
call_command('check_hello_asso')
payment.refresh_from_db()
self.assertTrue(payment.valid)
self.assertTrue(payment.additional_information)
class TestAdmin(TestCase):
def setUp(self) -> None: