2019-11-03 20:46:18 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
from django.utils import timezone
|
2019-11-03 23:25:29 +00:00
|
|
|
from dateutil.relativedelta import relativedelta
|
2019-11-03 20:46:18 +00:00
|
|
|
|
|
|
|
from users.models import User
|
|
|
|
from .models import Vente, Facture, Cotisation, Paiement
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2019-11-03 20:46:18 +00:00
|
|
|
class VenteModelTests(TestCase):
|
|
|
|
def setUp(self):
|
2019-12-15 15:23:53 +00:00
|
|
|
self.user = User.objects.create(pseudo="testUserPlop", email="test@example.org")
|
2019-11-04 16:55:03 +00:00
|
|
|
self.paiement = Paiement.objects.create(moyen="test payment")
|
2019-11-03 20:46:18 +00:00
|
|
|
self.f = Facture.objects.create(
|
2019-11-04 16:55:03 +00:00
|
|
|
user=self.user, paiement=self.paiement, valid=True
|
2019-11-03 20:46:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_one_day_cotisation(self):
|
|
|
|
"""
|
|
|
|
It should be possible to have one day membership.
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
Add one day of membership and one day of connection.
|
2019-11-03 20:46:18 +00:00
|
|
|
"""
|
|
|
|
date = timezone.now()
|
|
|
|
purchase = Vente.objects.create(
|
|
|
|
facture=self.f,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
duration_connection=0,
|
|
|
|
duration_days_connection=1,
|
|
|
|
duration_membership=0,
|
|
|
|
duration_days_membership=1,
|
2019-11-03 20:46:18 +00:00
|
|
|
prix=0,
|
|
|
|
)
|
2019-12-15 15:23:53 +00:00
|
|
|
self.f.reorder_purchases()
|
2019-11-03 20:46:18 +00:00
|
|
|
self.assertAlmostEqual(
|
|
|
|
self.user.end_connexion() - date,
|
|
|
|
datetime.timedelta(days=1),
|
2019-11-04 16:55:03 +00:00
|
|
|
delta=datetime.timedelta(seconds=1),
|
2019-11-03 20:46:18 +00:00
|
|
|
)
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
self.assertAlmostEqual(
|
|
|
|
self.user.end_adhesion() - date,
|
|
|
|
datetime.timedelta(days=1),
|
|
|
|
delta=datetime.timedelta(seconds=1),
|
|
|
|
)
|
2019-11-03 20:46:18 +00:00
|
|
|
|
2019-11-03 23:25:29 +00:00
|
|
|
def test_one_month_cotisation(self):
|
|
|
|
"""
|
|
|
|
It should be possible to have one day membership.
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
Add one mounth of membership and one mounth of connection
|
2019-11-03 23:25:29 +00:00
|
|
|
"""
|
|
|
|
date = timezone.now()
|
2019-12-15 15:23:53 +00:00
|
|
|
Vente.objects.create(
|
2019-11-03 23:25:29 +00:00
|
|
|
facture=self.f,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
duration_connection=1,
|
|
|
|
duration_days_connection=0,
|
|
|
|
duration_membership=1,
|
|
|
|
duration_days_membership=0,
|
2019-11-03 23:25:29 +00:00
|
|
|
prix=0,
|
|
|
|
)
|
2019-12-15 15:23:53 +00:00
|
|
|
self.f.reorder_purchases()
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
end_con = self.user.end_connexion()
|
|
|
|
end_memb = self.user.end_adhesion()
|
2019-12-15 15:23:53 +00:00
|
|
|
expected_end = date + relativedelta(months=1)
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
self.assertEqual(end_con.day, expected_end.day)
|
|
|
|
self.assertEqual(end_con.month, expected_end.month)
|
|
|
|
self.assertEqual(end_con.year, expected_end.year)
|
|
|
|
self.assertEqual(end_memb.day, expected_end.day)
|
|
|
|
self.assertEqual(end_memb.month, expected_end.month)
|
|
|
|
self.assertEqual(end_memb.year, expected_end.year)
|
2019-11-03 23:25:29 +00:00
|
|
|
|
|
|
|
def test_one_month_and_one_week_cotisation(self):
|
|
|
|
"""
|
|
|
|
It should be possible to have one day membership.
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
Add one mounth and one week of membership and one mounth
|
|
|
|
and one week of connection
|
2019-11-03 23:25:29 +00:00
|
|
|
"""
|
|
|
|
date = timezone.now()
|
2019-12-15 15:23:53 +00:00
|
|
|
Vente.objects.create(
|
2019-11-03 23:25:29 +00:00
|
|
|
facture=self.f,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
duration_connection=1,
|
|
|
|
duration_days_connection=7,
|
|
|
|
duration_membership=1,
|
|
|
|
duration_days_membership=7,
|
2019-11-03 23:25:29 +00:00
|
|
|
prix=0,
|
|
|
|
)
|
2019-12-15 15:23:53 +00:00
|
|
|
self.f.reorder_purchases()
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
end_con = self.user.end_connexion()
|
|
|
|
end_memb = self.user.end_adhesion()
|
2019-12-15 15:23:53 +00:00
|
|
|
expected_end = date + relativedelta(months=1, days=7)
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
self.assertEqual(end_con.day, expected_end.day)
|
|
|
|
self.assertEqual(end_con.month, expected_end.month)
|
|
|
|
self.assertEqual(end_con.year, expected_end.year)
|
|
|
|
self.assertEqual(end_memb.day, expected_end.day)
|
|
|
|
self.assertEqual(end_memb.month, expected_end.month)
|
|
|
|
self.assertEqual(end_memb.year, expected_end.year)
|
2019-11-03 23:25:29 +00:00
|
|
|
|
2019-12-20 07:43:35 +00:00
|
|
|
def test_date_start_cotisation(self):
|
|
|
|
"""
|
|
|
|
It should be possible to add a cotisation with a specific start date
|
|
|
|
"""
|
|
|
|
v = Vente(
|
|
|
|
facture=self.f,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
duration_connection=0,
|
|
|
|
duration_days_connection=1,
|
|
|
|
duration_membership=0,
|
|
|
|
duration_deys_membership=1,
|
2019-12-20 07:43:35 +00:00
|
|
|
prix=0
|
|
|
|
)
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
v.create_cotis(date_start_con=timezone.make_aware(datetime.datetime(1998, 10, 16)), date_start_memb=timezone.make_aware(datetime.datetime(1998, 10, 16)))
|
2019-12-20 07:43:35 +00:00
|
|
|
v.save()
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
self.assertEqual(v.cotisation.date_end_con, timezone.make_aware(datetime.datetime(1998, 10, 17)))
|
|
|
|
self.assertEqual(v.cotisation.date_end_memb, timezone.make_aware(datetime.datetime(1998, 10, 17)))
|
2019-12-20 07:43:35 +00:00
|
|
|
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
def test_one_day_cotisation_membership_only(self):
|
|
|
|
"""
|
|
|
|
It should be possible to have one day membership without connection.
|
|
|
|
Add one day of membership and no connection.
|
|
|
|
"""
|
|
|
|
date = timezone.now()
|
|
|
|
purchase = Vente.objects.create(
|
|
|
|
facture=self.f,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
|
|
|
duration_connection=0,
|
|
|
|
duration_days_connection=0,
|
|
|
|
duration_membership=0,
|
|
|
|
duration_days_membership=1,
|
|
|
|
prix=0,
|
|
|
|
)
|
|
|
|
self.f.reorder_purchases()
|
|
|
|
self.assertEqual(
|
|
|
|
self.user.end_connexion(),
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
self.assertAlmostEqual(
|
|
|
|
self.user.end_adhesion() - date,
|
|
|
|
datetime.timedelta(days=1),
|
|
|
|
delta=datetime.timedelta(seconds=1),
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_one_month_cotisation_membership_only(self):
|
|
|
|
"""
|
|
|
|
It should be possible to have one month membership.
|
|
|
|
Add one mounth of membership and no connection
|
|
|
|
"""
|
|
|
|
date = timezone.now()
|
|
|
|
Vente.objects.create(
|
|
|
|
facture=self.f,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
|
|
|
duration_connection=0,
|
|
|
|
duration_days_connection=0,
|
|
|
|
duration_membership=1,
|
|
|
|
duration_days_membership=0,
|
|
|
|
prix=0,
|
|
|
|
)
|
|
|
|
self.f.reorder_purchases()
|
|
|
|
end_con = self.user.end_connexion()
|
|
|
|
end_memb = self.user.end_adhesion()
|
|
|
|
expected_end = date + relativedelta(months=1)
|
|
|
|
self.assertEqual(end_con, None)
|
|
|
|
self.assertEqual(end_memb.day, expected_end.day)
|
|
|
|
self.assertEqual(end_memb.month, expected_end.month)
|
|
|
|
self.assertEqual(end_memb.year, expected_end.year)
|
|
|
|
|
|
|
|
def test_one_month_and_one_week_cotisation_membership_only(self):
|
|
|
|
"""
|
|
|
|
It should be possible to have one mounth and one week membership.
|
|
|
|
Add one mounth and one week of membership and no connection.
|
|
|
|
"""
|
|
|
|
date = timezone.now()
|
|
|
|
Vente.objects.create(
|
|
|
|
facture=self.f,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
|
|
|
duration_connection=0,
|
|
|
|
duration_days_connection=0,
|
|
|
|
duration_membership=1,
|
|
|
|
duration_days_membership=7,
|
|
|
|
prix=0,
|
|
|
|
)
|
|
|
|
self.f.reorder_purchases()
|
|
|
|
end_con = self.user.end_connexion()
|
|
|
|
end_memb = self.user.end_adhesion()
|
|
|
|
expected_end = date + relativedelta(months=1, days=7)
|
|
|
|
self.assertEqual(end_con, None)
|
|
|
|
self.assertEqual(end_memb.day, expected_end.day)
|
|
|
|
self.assertEqual(end_memb.month, expected_end.month)
|
|
|
|
self.assertEqual(end_memb.year, expected_end.year)
|
|
|
|
|
|
|
|
def test_date_start_cotisation_membership_only(self):
|
|
|
|
"""
|
|
|
|
It should be possible to add a cotisation with a specific start date
|
|
|
|
"""
|
|
|
|
v = Vente(
|
|
|
|
facture=self.f,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
|
|
|
duration_connection=0,
|
|
|
|
duration_days_connection=0,
|
|
|
|
duration_membership=0,
|
|
|
|
duration_days_membership=1,
|
|
|
|
prix=0
|
|
|
|
)
|
|
|
|
v.create_cotis(date_start_con=timezone.make_aware(datetime.datetime(1998, 10, 16)), date_start_memb=timezone.make_aware(datetime.datetime(1998, 10, 16)))
|
|
|
|
v.save()
|
|
|
|
self.assertEqual(v.cotisation.date_end_con, timezone.make_aware(datetime.datetime(1998, 10, 17)))
|
|
|
|
self.assertEqual(v.cotisation.date_end_memb, timezone.make_aware(datetime.datetime(1998, 10, 16)))
|
|
|
|
|
|
|
|
def test_cotisation_membership_diff_connection(self):
|
|
|
|
"""
|
|
|
|
It should be possible to have purchase a membership longer
|
|
|
|
than the connection.
|
|
|
|
"""
|
|
|
|
date = timezone.now()
|
|
|
|
Vente.objects.create(
|
|
|
|
facture=self.f,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
|
|
|
duration_connection=1,
|
|
|
|
duration_days_connection=0,
|
|
|
|
duration_membership=2,
|
|
|
|
duration_days_membership=0,
|
|
|
|
prix=0,
|
|
|
|
)
|
|
|
|
self.f.reorder_purchases()
|
|
|
|
end_con = self.user.end_connexion()
|
|
|
|
end_memb = self.user.end_adhesion()
|
|
|
|
expected_end_con = date + relativedelta(months=1)
|
|
|
|
expected_end_memb = date + relativedelta(months=2)
|
|
|
|
self.assertEqual(end_con.day, expected_end_con.day)
|
|
|
|
self.assertEqual(end_con.month, expected_end_con.month)
|
|
|
|
self.assertEqual(end_con.year, expected_end_con.year)
|
|
|
|
self.assertEqual(end_memb.day, expected_end_memb.day)
|
|
|
|
self.assertEqual(end_memb.month, expected_end_memb.month)
|
|
|
|
self.assertEqual(end_memb.year, expected_end_memb.year)
|
2019-12-20 07:43:35 +00:00
|
|
|
|
2019-11-03 20:46:18 +00:00
|
|
|
def tearDown(self):
|
|
|
|
self.f.delete()
|
|
|
|
self.user.delete()
|
|
|
|
self.paiement.delete()
|
2019-12-15 15:23:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FactureModelTests(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.user = User.objects.create(pseudo="testUserPlop", email="test@example.org")
|
|
|
|
self.paiement = Paiement.objects.create(moyen="test payment")
|
|
|
|
def tearDown(self):
|
|
|
|
self.user.delete()
|
|
|
|
self.paiement.delete()
|
|
|
|
def test_cotisations_prolongation(self):
|
|
|
|
"""When user already have one valid cotisation, the new one should be
|
|
|
|
added at the end of the existing one."""
|
|
|
|
date = timezone.now()
|
|
|
|
invoice1 = Facture.objects.create(
|
|
|
|
user=self.user, paiement=self.paiement, valid=True
|
|
|
|
)
|
|
|
|
Vente.objects.create(
|
|
|
|
facture=invoice1,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
duration_connection=1,
|
|
|
|
duration_days_connection=0,
|
|
|
|
duration_membership=1,
|
|
|
|
duration_days_membership=0,
|
2019-12-15 15:23:53 +00:00
|
|
|
prix=0,
|
|
|
|
)
|
|
|
|
invoice1.reorder_purchases()
|
|
|
|
invoice2 = Facture.objects.create(
|
|
|
|
user=self.user, paiement=self.paiement, valid=True
|
|
|
|
)
|
|
|
|
Vente.objects.create(
|
|
|
|
facture=invoice2,
|
|
|
|
number=1,
|
|
|
|
name="Test purchase",
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
duration_connection=1,
|
|
|
|
duration_days_connection=0,
|
|
|
|
duration_membership=1,
|
|
|
|
duration_days_membership=0,
|
2019-12-15 15:23:53 +00:00
|
|
|
prix=0,
|
|
|
|
)
|
|
|
|
invoice1.reorder_purchases()
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
delta_con = relativedelta(self.user.end_connexion(), date)
|
|
|
|
delta_memb = relativedelta(self.user.end_adhesion(), date)
|
|
|
|
delta_con.microseconds = 0
|
|
|
|
delta_memb.microseconds = 0
|
2019-12-15 15:23:53 +00:00
|
|
|
try:
|
Split the membership duration from the connection duration
changes:
Article:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
Vente:
remove COTISATION_TYPE, duration(_days), type_cotisation
add duration(_days)_connection, duration(_days)_membership
add method `test_membership_or_connection()` to replace
`bool(type_cotisation)`
Cotisation:
remove COTISATION_TYPE, date_start, date_end, type_cotisation
add date_start_con, date_end_con, date_start_memb, date_end_memb
create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False)
+ migration
+ changes to use the new models in the remaining of the code
2020-09-20 23:21:46 +00:00
|
|
|
self.assertEqual(delta_con, relativedelta(months=2))
|
|
|
|
self.assertEqual(delta_memb, relativedelta(months=2))
|
2019-12-15 15:23:53 +00:00
|
|
|
except Exception as e:
|
|
|
|
invoice1.delete()
|
|
|
|
invoice2.delete()
|
|
|
|
raise e
|
|
|
|
invoice1.delete()
|
|
|
|
invoice2.delete()
|
|
|
|
|