mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Fix some tests
This commit is contained in:
parent
e3f77f16c3
commit
c95e4b7a4b
4 changed files with 58 additions and 33 deletions
49
api/tests.py
49
api/tests.py
|
@ -227,8 +227,6 @@ class APIEndpointsTestCase(APITestCase):
|
|||
# For more details, see
|
||||
# https://docs.djangoproject.com/en/1.10/topics/testing/tools/#testcase
|
||||
|
||||
super(APIEndpointsTestCase, cls).setUpClass()
|
||||
|
||||
# A user with no rights
|
||||
cls.stduser = users.User.objects.create_user(
|
||||
"apistduser", "apistduser", "apistduser@example.net", "apistduser"
|
||||
|
@ -261,22 +259,22 @@ class APIEndpointsTestCase(APITestCase):
|
|||
registered=datetime.datetime.now(datetime.timezone.utc),
|
||||
telephone="0123456789",
|
||||
uid_number=21102,
|
||||
rezo_rez_uid=21102,
|
||||
)
|
||||
cls.users_user_1 = cls.users_adherent_1
|
||||
cls.cotisations_article_1 = cotisations.Article.objects.create(
|
||||
name="cotisations_article_1",
|
||||
prix=10,
|
||||
duration=1,
|
||||
duration_days_membership=0,
|
||||
duration_membership=1,
|
||||
duration_days_connection=0,
|
||||
duration_connection=1,
|
||||
type_user=cotisations.Article.USER_TYPES[0][0],
|
||||
type_cotisation=cotisations.Article.COTISATION_TYPE[0][0],
|
||||
)
|
||||
cls.cotisations_banque_1 = cotisations.Banque.objects.create(
|
||||
name="cotisations_banque_1"
|
||||
)
|
||||
cls.cotisations_paiement_1 = cotisations.Paiement.objects.create(
|
||||
moyen="cotisations_paiement_1",
|
||||
type_paiement=cotisations.Paiement.PAYMENT_TYPES[0][0],
|
||||
)
|
||||
cls.cotisations_facture_1 = cotisations.Facture.objects.create(
|
||||
user=cls.users_user_1, # Dep users.User
|
||||
|
@ -292,8 +290,10 @@ class APIEndpointsTestCase(APITestCase):
|
|||
number=2,
|
||||
name="cotisations_vente_1",
|
||||
prix=10,
|
||||
duration=1,
|
||||
type_cotisation=cotisations.Vente.COTISATION_TYPE[0][0],
|
||||
duration_days_membership=0,
|
||||
duration_membership=1,
|
||||
duration_days_connection=0,
|
||||
duration_connection=1,
|
||||
)
|
||||
# A cotisation is automatically created by the Vente object and
|
||||
# trying to create another cotisation associated with this vente
|
||||
|
@ -328,7 +328,7 @@ class APIEndpointsTestCase(APITestCase):
|
|||
vlan_id=0, name="machines_vlan_1", comment="machines Vlan 1"
|
||||
)
|
||||
cls.machines_iptype_1 = machines.IpType.objects.create(
|
||||
type="machines_iptype_1",
|
||||
name="machines_iptype_1",
|
||||
extension=cls.machines_extension_1, # Dep machines.Extension
|
||||
need_infra=False,
|
||||
domaine_ip_start="10.0.0.1",
|
||||
|
@ -343,14 +343,14 @@ class APIEndpointsTestCase(APITestCase):
|
|||
ipv4="10.0.0.1", ip_type=cls.machines_iptype_1 # Dep machines.IpType
|
||||
)
|
||||
cls.machines_machinetype_1 = machines.MachineType.objects.create(
|
||||
type="machines_machinetype_1",
|
||||
name="machines_machinetype_1",
|
||||
ip_type=cls.machines_iptype_1, # Dep machines.IpType
|
||||
)
|
||||
cls.machines_interface_1 = machines.Interface.objects.create(
|
||||
ipv4=cls.machines_iplist_1, # Dep machines.IpList
|
||||
mac_address="00:00:00:00:00:00",
|
||||
machine=cls.machines_machine_1, # Dep machines.Machine
|
||||
type=cls.machines_machinetype_1, # Dep machines.MachineType
|
||||
machine_type=cls.machines_machinetype_1, # Dep machines.MachineType
|
||||
details="machines Interface 1",
|
||||
# port_lists=[cls.machines_ouvertureportlist_1] # Dep machines.OuverturePortList
|
||||
)
|
||||
|
@ -438,8 +438,12 @@ class APIEndpointsTestCase(APITestCase):
|
|||
name="machines_machine_1",
|
||||
active=True,
|
||||
)
|
||||
cls.topologie_dormitory_1 = topologie.Dormitory.objects.create(
|
||||
name="topologie_dormitory_1"
|
||||
)
|
||||
cls.topologie_building_1 = topologie.Building.objects.create(
|
||||
name="topologie_building_1"
|
||||
name="topologie_building_1",
|
||||
dormitory=cls.topologie_dormitory_1, # Dep topologie.Dormitory
|
||||
)
|
||||
cls.topologie_switchbay_1 = topologie.SwitchBay.objects.create(
|
||||
name="topologie_switchbay_1",
|
||||
|
@ -464,29 +468,35 @@ class APIEndpointsTestCase(APITestCase):
|
|||
switchbay=cls.topologie_switchbay_1, # Dep topologie.SwitchBay
|
||||
)
|
||||
cls.topologie_room_1 = topologie.Room.objects.create(
|
||||
name="topologie_romm_1", details="topologie Room 1"
|
||||
name="topologie_romm_1", details="topologie Room 1",
|
||||
building=cls.topologie_building_1, # Dep topologie.Building
|
||||
)
|
||||
cls.topologie_port_profile_1 = topologie.PortProfile.objects.create(
|
||||
name="topologie_port_profile_1",
|
||||
profil_default=topologie.PortProfile.PROFIL_DEFAULT[0][0],
|
||||
on_dormitory=cls.topologie_dormitory_1,
|
||||
radius_type="inactive",
|
||||
radius_mode="COMMON",
|
||||
)
|
||||
cls.topologie_port_1 = topologie.Port.objects.create(
|
||||
switch=cls.topologie_switch_1, # Dep topologie.Switch
|
||||
port=1,
|
||||
room=cls.topologie_room_1, # Dep topologie.Room
|
||||
radius=topologie.Port.STATES[0][0],
|
||||
vlan_force=cls.machines_vlan_1, # Dep machines.Vlan
|
||||
custom_profile=cls.topologie_port_profile_1,
|
||||
details="topologie_switch_1",
|
||||
)
|
||||
cls.topologie_port_2 = topologie.Port.objects.create(
|
||||
switch=cls.topologie_switch_1, # Dep topologie.Switch
|
||||
port=2,
|
||||
machine_interface=cls.machines_interface_1, # Dep machines.Interface
|
||||
radius=topologie.Port.STATES[0][0],
|
||||
vlan_force=cls.machines_vlan_1, # Dep machines.Vlan
|
||||
custom_profile=cls.topologie_port_profile_1,
|
||||
details="topologie_switch_1",
|
||||
)
|
||||
cls.topologie_port_3 = topologie.Port.objects.create(
|
||||
switch=cls.topologie_switch_1, # Dep topologie.Switch
|
||||
port=3,
|
||||
room=cls.topologie_room_1, # Dep topologie.Room
|
||||
radius=topologie.Port.STATES[0][0],
|
||||
custom_profile=cls.topologie_port_profile_1,
|
||||
# Do not defines related because circular dependency # Dep machines.Vlan
|
||||
details="topologie_switch_1",
|
||||
)
|
||||
|
@ -512,7 +522,6 @@ class APIEndpointsTestCase(APITestCase):
|
|||
registered=datetime.datetime.now(datetime.timezone.utc),
|
||||
telephone="0123456789",
|
||||
uid_number=21103,
|
||||
rezo_rez_uid=21103,
|
||||
)
|
||||
# Need merge of MR145 to work
|
||||
# TODO: Merge !145
|
||||
|
@ -749,7 +758,7 @@ class APIPaginationTestCase(APITestCase):
|
|||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.superuser.delete()
|
||||
super(APIPaginationTestCase, self).tearDownClass()
|
||||
super().tearDownClass()
|
||||
|
||||
def test_pagination(self):
|
||||
"""Tests that every endpoint is using the pagination correctly.
|
||||
|
|
|
@ -111,9 +111,10 @@ class VenteModelTests(TestCase):
|
|||
duration_connection=0,
|
||||
duration_days_connection=1,
|
||||
duration_membership=0,
|
||||
duration_deys_membership=1,
|
||||
duration_days_membership=1,
|
||||
prix=0,
|
||||
)
|
||||
v.save()
|
||||
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)),
|
||||
|
@ -145,9 +146,10 @@ class VenteModelTests(TestCase):
|
|||
prix=0,
|
||||
)
|
||||
self.f.reorder_purchases()
|
||||
self.assertEqual(
|
||||
self.assertAlmostEqual(
|
||||
self.user.end_connexion(),
|
||||
None,
|
||||
date,
|
||||
delta=datetime.timedelta(seconds=1),
|
||||
)
|
||||
self.assertAlmostEqual(
|
||||
self.user.end_adhesion() - date,
|
||||
|
@ -175,7 +177,11 @@ class VenteModelTests(TestCase):
|
|||
end_con = self.user.end_connexion()
|
||||
end_memb = self.user.end_adhesion()
|
||||
expected_end = date + relativedelta(months=1)
|
||||
self.assertEqual(end_con, None)
|
||||
self.assertAlmostEqual(
|
||||
end_con,
|
||||
date,
|
||||
delta=datetime.timedelta(seconds=1),
|
||||
)
|
||||
self.assertEqual(end_memb.day, expected_end.day)
|
||||
self.assertEqual(end_memb.month, expected_end.month)
|
||||
self.assertEqual(end_memb.year, expected_end.year)
|
||||
|
@ -200,7 +206,11 @@ class VenteModelTests(TestCase):
|
|||
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.assertAlmostEqual(
|
||||
end_con,
|
||||
date,
|
||||
delta=datetime.timedelta(seconds=1),
|
||||
)
|
||||
self.assertEqual(end_memb.day, expected_end.day)
|
||||
self.assertEqual(end_memb.month, expected_end.month)
|
||||
self.assertEqual(end_memb.year, expected_end.year)
|
||||
|
@ -219,6 +229,7 @@ class VenteModelTests(TestCase):
|
|||
duration_days_membership=1,
|
||||
prix=0,
|
||||
)
|
||||
v.save()
|
||||
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)),
|
||||
|
|
|
@ -26,10 +26,10 @@ class NewFactureTests(TestCase):
|
|||
self.user.user_permissions.set(
|
||||
[
|
||||
Permission.objects.get_by_natural_key(
|
||||
"add_facture", "cotisations", "Facture"
|
||||
"add_facture", "cotisations", "facture"
|
||||
),
|
||||
Permission.objects.get_by_natural_key(
|
||||
"use_every_payment", "cotisations", "Paiement"
|
||||
"use_every_payment", "cotisations", "paiement"
|
||||
),
|
||||
]
|
||||
)
|
||||
|
@ -145,5 +145,7 @@ class NewFactureTests(TestCase):
|
|||
response = self.client.post(
|
||||
reverse("cotisations:new-facture", kwargs={"userid": self.user.pk}), data
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(response.url, "/users/profil/%d" % self.user.pk)
|
||||
f = self.user.facture_set.first()
|
||||
self.assertEqual(f.vente_set.count(), 2)
|
||||
|
|
|
@ -23,20 +23,23 @@ class UserModelTests(TestCase):
|
|||
facture=invoice,
|
||||
number=1,
|
||||
name="Test purchase",
|
||||
duration=0,
|
||||
duration_days=1,
|
||||
type_cotisation="All",
|
||||
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=0,
|
||||
duration_days=1,
|
||||
type_cotisation="All",
|
||||
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),
|
||||
|
|
Loading…
Reference in a new issue