mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-16 08:23:12 +00:00
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import datetime
|
|
|
|
from django.test import TestCase
|
|
from django.utils import timezone
|
|
|
|
from cotisations.models import Facture, Paiement, Vente
|
|
from users.models import User
|
|
|
|
|
|
class UserModelTests(TestCase):
|
|
def setUp(self):
|
|
self.user = User.objects.create(pseudo="testUser")
|
|
|
|
def tearDown(self):
|
|
self.user.facture_set.all().delete()
|
|
self.user.delete()
|
|
|
|
def test_multiple_cotisations_are_taken_into_account(self):
|
|
paiement = Paiement.objects.create(moyen="test payment")
|
|
invoice = Facture.objects.create(user=self.user, paiement=paiement, valid=True)
|
|
date = timezone.now()
|
|
purchase1 = Vente.objects.create(
|
|
facture=invoice,
|
|
number=1,
|
|
name="Test purchase",
|
|
duration_days_membership=1,
|
|
duration_membership=0,
|
|
duration_days_connection=1,
|
|
duration_connection=0,
|
|
prix=0,
|
|
)
|
|
purchase2 = Vente.objects.create(
|
|
facture=invoice,
|
|
number=1,
|
|
name="Test purchase",
|
|
duration_days_membership=1,
|
|
duration_membership=0,
|
|
duration_days_connection=1,
|
|
duration_connection=0,
|
|
prix=0,
|
|
)
|
|
invoice.reorder_purchases()
|
|
self.assertAlmostEqual(
|
|
self.user.end_connexion() - date,
|
|
datetime.timedelta(days=2),
|
|
delta=datetime.timedelta(seconds=1),
|
|
)
|