From e0a65e4d044199d414ae2606813fe08fedf4420a Mon Sep 17 00:00:00 2001 From: Hugo Levy-Falk Date: Sun, 3 Nov 2019 21:46:18 +0100 Subject: [PATCH] Setup tests for Vente model. --- .../migrations/0041_auto_20191103_2131.py | 41 ++++++++++++++++ cotisations/payment_methods/balance/models.py | 2 +- cotisations/payment_methods/cheque/models.py | 2 +- cotisations/payment_methods/comnpay/models.py | 2 +- cotisations/payment_methods/free/models.py | 2 +- .../payment_methods/note_kfet/models.py | 2 +- cotisations/test_models.py | 49 +++++++++++++++++++ cotisations/tests.py | 28 ----------- 8 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 cotisations/migrations/0041_auto_20191103_2131.py create mode 100644 cotisations/test_models.py delete mode 100644 cotisations/tests.py diff --git a/cotisations/migrations/0041_auto_20191103_2131.py b/cotisations/migrations/0041_auto_20191103_2131.py new file mode 100644 index 00000000..09f763ed --- /dev/null +++ b/cotisations/migrations/0041_auto_20191103_2131.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.23 on 2019-11-03 20:31 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('cotisations', '0040_auto_20191002_2335'), + ] + + operations = [ + migrations.AlterField( + model_name='balancepayment', + name='payment', + field=models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method_balance', to='cotisations.Paiement'), + ), + migrations.AlterField( + model_name='chequepayment', + name='payment', + field=models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method_cheque', to='cotisations.Paiement'), + ), + migrations.AlterField( + model_name='comnpaypayment', + name='payment', + field=models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method_comnpay', to='cotisations.Paiement'), + ), + migrations.AlterField( + model_name='freepayment', + name='payment', + field=models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method_free', to='cotisations.Paiement'), + ), + migrations.AlterField( + model_name='notepayment', + name='payment', + field=models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='payment_method_note', to='cotisations.Paiement'), + ), + ] diff --git a/cotisations/payment_methods/balance/models.py b/cotisations/payment_methods/balance/models.py index 221cca3e..e3e05ea4 100644 --- a/cotisations/payment_methods/balance/models.py +++ b/cotisations/payment_methods/balance/models.py @@ -40,7 +40,7 @@ class BalancePayment(PaymentMethodMixin, models.Model): payment = models.OneToOneField( Paiement, on_delete=models.CASCADE, - related_name='payment_method', + related_name='payment_method_balance', editable=False ) minimum_balance = models.DecimalField( diff --git a/cotisations/payment_methods/cheque/models.py b/cotisations/payment_methods/cheque/models.py index 8f00ff46..a834bb93 100644 --- a/cotisations/payment_methods/cheque/models.py +++ b/cotisations/payment_methods/cheque/models.py @@ -38,7 +38,7 @@ class ChequePayment(PaymentMethodMixin, models.Model): payment = models.OneToOneField( Paiement, on_delete=models.CASCADE, - related_name='payment_method', + related_name='payment_method_cheque', editable=False ) diff --git a/cotisations/payment_methods/comnpay/models.py b/cotisations/payment_methods/comnpay/models.py index 7fac089a..a5568f22 100644 --- a/cotisations/payment_methods/comnpay/models.py +++ b/cotisations/payment_methods/comnpay/models.py @@ -41,7 +41,7 @@ class ComnpayPayment(PaymentMethodMixin, models.Model): payment = models.OneToOneField( Paiement, on_delete=models.CASCADE, - related_name='payment_method', + related_name='payment_method_comnpay', editable=False ) payment_credential = models.CharField( diff --git a/cotisations/payment_methods/free/models.py b/cotisations/payment_methods/free/models.py index 46ecca87..2931faad 100644 --- a/cotisations/payment_methods/free/models.py +++ b/cotisations/payment_methods/free/models.py @@ -38,7 +38,7 @@ class FreePayment(PaymentMethodMixin, models.Model): payment = models.OneToOneField( Paiement, on_delete=models.CASCADE, - related_name='payment_method', + related_name='payment_method_free', editable=False ) diff --git a/cotisations/payment_methods/note_kfet/models.py b/cotisations/payment_methods/note_kfet/models.py index be54bd54..0e2ebea1 100644 --- a/cotisations/payment_methods/note_kfet/models.py +++ b/cotisations/payment_methods/note_kfet/models.py @@ -42,7 +42,7 @@ class NotePayment(PaymentMethodMixin, models.Model): payment = models.OneToOneField( Paiement, on_delete = models.CASCADE, - related_name = 'payment_method', + related_name = 'payment_method_note', editable = False ) server = models.CharField( diff --git a/cotisations/test_models.py b/cotisations/test_models.py new file mode 100644 index 00000000..33f32a18 --- /dev/null +++ b/cotisations/test_models.py @@ -0,0 +1,49 @@ +from django.test import TestCase + +import datetime +from django.utils import timezone + +from users.models import User +from .models import Vente, Facture, Cotisation, Paiement + +class VenteModelTests(TestCase): + def setUp(self): + self.user = User.objects.create( + pseudo="testUser", + email="test@example.org" + ) + self.paiement = Paiement.objects.create( + moyen="test payment" + ) + self.f = Facture.objects.create( + user=self.user, + paiement=self.paiement, + valid=True + ) + + def test_one_day_cotisation(self): + """ + It should be possible to have one day membership. + """ + date = timezone.now() + purchase = Vente.objects.create( + facture=self.f, + number=1, + name="Test purchase", + duration=0, + duration_days=1, + type_cotisation="All", + prix=0, + ) + self.assertAlmostEqual( + self.user.end_connexion() - date, + datetime.timedelta(days=1), + delta=datetime.timedelta(seconds=1) + ) + + def tearDown(self): + self.f.delete() + self.user.delete() + self.paiement.delete() + + diff --git a/cotisations/tests.py b/cotisations/tests.py deleted file mode 100644 index b2ecee78..00000000 --- a/cotisations/tests.py +++ /dev/null @@ -1,28 +0,0 @@ -# Re2o est un logiciel d'administration développé initiallement au rezometz. Il -# se veut agnostique au réseau considéré, de manière à être installable en -# quelques clics. -# -# Copyright © 2017 Gabriel Détraz -# Copyright © 2017 Lara Kermarec -# Copyright © 2017 Augustin Lemesle -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -"""cotisations.tests -The tests for the Cotisations module. -""" - -# from django.test import TestCase - -# Create your tests here.