From 9661751df2c8a3cc1874c77297d86706d21cf56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 6 Oct 2019 10:32:18 +0200 Subject: [PATCH 1/3] Fix crash on /bda/revente//manage `annotate_paid` method is a method of the Participant object manager, not the Participant class itself --- bda/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bda/views.py b/bda/views.py index 0c4d7665..1ead6a43 100644 --- a/bda/views.py +++ b/bda/views.py @@ -381,7 +381,7 @@ def revente_manage(request, tirage_id): - Annulation d'une revente après que le tirage a eu lieu """ tirage = get_object_or_404(Tirage, id=tirage_id) - participant, created = Participant.annotate_paid().get_or_create( + participant, created = Participant.objects.annotate_paid().get_or_create( user=request.user, tirage=tirage ) From 8c9de4303b695d87287aff1f456ca8df0a07c3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 6 Oct 2019 10:57:15 +0200 Subject: [PATCH 2/3] Add a testcase for issue #228 --- bda/tests/test_views.py | 44 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/bda/tests/test_views.py b/bda/tests/test_views.py index 3dc1b4d1..d13fcf6c 100644 --- a/bda/tests/test_views.py +++ b/bda/tests/test_views.py @@ -1,12 +1,17 @@ import json from datetime import timedelta +from unittest import mock -from django.test import TestCase +from django.contrib.auth import get_user_model +from django.test import Client, TestCase +from django.urls import reverse from django.utils import formats, timezone -from ..models import Participant +from ..models import Participant, Tirage from .testcases import BdATestHelpers, BdAViewTestCaseMixin +User = get_user_model() + class InscriptionViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase): url_name = "bda-tirage-inscription" @@ -320,6 +325,41 @@ class CatalogueViewTestCase(BdATestHelpers, BdAViewTestCaseMixin, TestCase): ) +# ----- BdA Revente --------------------------------------- # + + +def make_participant(name: str, tirage: Tirage) -> User: + user = User.objects.create_user(username=name, password=name) + user.profile.is_cof = True + user.profile.save() + Participant.objects.create(user=user, tirage=tirage) + return user + + +class TestReventeManageTest(TestCase): + def setUp(self): + self.tirage = Tirage.objects.create( + title="tirage1", + ouverture=timezone.now(), + fermeture=timezone.now() + timedelta(days=90), + ) + self.user = make_participant("toto", self.tirage) + self.url = reverse("bda-revente-manage", args=[self.tirage.id]) + + # Signals handlers on login/logout send messages. + # Due to the way the Django' test Client performs login, this raise an + # error. As workaround, we mock the Django' messages module. + patcher_messages = mock.patch("gestioncof.signals.messages") + patcher_messages.start() + self.addCleanup(patcher_messages.stop) + + def test_can_get(self): + client = Client() + client.force_login(self.user) + r = client.get(self.url) + self.assertEqual(r.status_code, 200) + + class TestBdaRevente: pass # TODO From db158ad312f66e877c7215a89107f75e1cf189c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 6 Oct 2019 11:52:32 +0200 Subject: [PATCH 3/3] Update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index a709d62c..6351fb06 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +- Fix erreur 500 sur /bda/revente//manage - Si on essaie d'accéder au compte que qqn d'autre on a une 404 (et plus une 403) - On ne peut plus modifier des comptes COF depuis l'interface K-Fêt - Le champ de paiement BdA se fait au niveau des attributions