2019-11-03 23:25:29 +00:00
|
|
|
import datetime
|
2021-02-10 10:06:09 +00:00
|
|
|
|
|
|
|
from django.test import TestCase
|
2019-11-03 23:25:29 +00:00
|
|
|
from django.utils import timezone
|
|
|
|
|
2021-02-10 10:06:09 +00:00
|
|
|
from cotisations.models import Facture, Paiement, Vente
|
2019-11-03 23:25:29 +00:00
|
|
|
from users.models import User
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2019-11-03 23:25:29 +00:00
|
|
|
class UserModelTests(TestCase):
|
|
|
|
def setUp(self):
|
2019-11-04 16:55:03 +00:00
|
|
|
self.user = User.objects.create(pseudo="testUser")
|
2019-11-03 23:25:29 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.user.facture_set.all().delete()
|
|
|
|
self.user.delete()
|
|
|
|
|
|
|
|
def test_multiple_cotisations_are_taken_into_account(self):
|
2019-11-04 16:55:03 +00:00
|
|
|
paiement = Paiement.objects.create(moyen="test payment")
|
|
|
|
invoice = Facture.objects.create(user=self.user, paiement=paiement, valid=True)
|
2019-11-03 23:25:29 +00:00
|
|
|
date = timezone.now()
|
|
|
|
purchase1 = Vente.objects.create(
|
|
|
|
facture=invoice,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
2024-02-20 15:22:57 +00:00
|
|
|
duration_days_membership=1,
|
|
|
|
duration_membership=0,
|
|
|
|
duration_days_connection=1,
|
|
|
|
duration_connection=0,
|
2019-11-03 23:25:29 +00:00
|
|
|
prix=0,
|
|
|
|
)
|
|
|
|
purchase2 = Vente.objects.create(
|
|
|
|
facture=invoice,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
2024-02-20 15:22:57 +00:00
|
|
|
duration_days_membership=1,
|
|
|
|
duration_membership=0,
|
|
|
|
duration_days_connection=1,
|
|
|
|
duration_connection=0,
|
2019-11-03 23:25:29 +00:00
|
|
|
prix=0,
|
|
|
|
)
|
2024-02-20 15:22:57 +00:00
|
|
|
invoice.reorder_purchases()
|
2019-11-03 23:25:29 +00:00
|
|
|
self.assertAlmostEqual(
|
|
|
|
self.user.end_connexion() - date,
|
|
|
|
datetime.timedelta(days=2),
|
2019-11-04 16:55:03 +00:00
|
|
|
delta=datetime.timedelta(seconds=1),
|
2019-11-03 23:25:29 +00:00
|
|
|
)
|