From 471fd52bdb17ca1735eb46d48a022c631c708903 Mon Sep 17 00:00:00 2001 From: chapeau Date: Tue, 20 Feb 2024 16:20:02 +0100 Subject: [PATCH 1/6] Unit tests of disabled optionnal apps are no longer run --- api/__init__.py | 29 +++++++++++++++++++++++++++++ deposits/__init__.py | 29 +++++++++++++++++++++++++++++ ldap_sync/__init__.py | 29 +++++++++++++++++++++++++++++ radius/__init__.py | 29 +++++++++++++++++++++++++++++ tickets/__init__.py | 29 +++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+) diff --git a/api/__init__.py b/api/__init__.py index e69de29b..745e9089 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -0,0 +1,29 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2024 Caroline Canebier +# +# 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. +from os.path import dirname, abspath +from django.conf import settings as django_settings + +def load_tests(loader, tests, pattern): + """ + As this is an optionnal app, loads its tests only if it is installed. + """ + if "api" in django_settings.INSTALLED_APPS: + return loader.discover(start_dir=dirname(abspath(__file__)), pattern=pattern) \ No newline at end of file diff --git a/deposits/__init__.py b/deposits/__init__.py index e69de29b..745e9089 100644 --- a/deposits/__init__.py +++ b/deposits/__init__.py @@ -0,0 +1,29 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2024 Caroline Canebier +# +# 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. +from os.path import dirname, abspath +from django.conf import settings as django_settings + +def load_tests(loader, tests, pattern): + """ + As this is an optionnal app, loads its tests only if it is installed. + """ + if "api" in django_settings.INSTALLED_APPS: + return loader.discover(start_dir=dirname(abspath(__file__)), pattern=pattern) \ No newline at end of file diff --git a/ldap_sync/__init__.py b/ldap_sync/__init__.py index e69de29b..83cad363 100644 --- a/ldap_sync/__init__.py +++ b/ldap_sync/__init__.py @@ -0,0 +1,29 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2024 Caroline Canebier +# +# 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. +from os.path import dirname, abspath +from django.conf import settings as django_settings + +def load_tests(loader, tests, pattern): + """ + As this is an optionnal app, loads its tests only if it is installed. + """ + if "ldap_sync" in django_settings.INSTALLED_APPS: + return loader.discover(start_dir=dirname(abspath(__file__)), pattern=pattern) \ No newline at end of file diff --git a/radius/__init__.py b/radius/__init__.py index e69de29b..745e9089 100644 --- a/radius/__init__.py +++ b/radius/__init__.py @@ -0,0 +1,29 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2024 Caroline Canebier +# +# 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. +from os.path import dirname, abspath +from django.conf import settings as django_settings + +def load_tests(loader, tests, pattern): + """ + As this is an optionnal app, loads its tests only if it is installed. + """ + if "api" in django_settings.INSTALLED_APPS: + return loader.discover(start_dir=dirname(abspath(__file__)), pattern=pattern) \ No newline at end of file diff --git a/tickets/__init__.py b/tickets/__init__.py index e69de29b..745e9089 100644 --- a/tickets/__init__.py +++ b/tickets/__init__.py @@ -0,0 +1,29 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2024 Caroline Canebier +# +# 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. +from os.path import dirname, abspath +from django.conf import settings as django_settings + +def load_tests(loader, tests, pattern): + """ + As this is an optionnal app, loads its tests only if it is installed. + """ + if "api" in django_settings.INSTALLED_APPS: + return loader.discover(start_dir=dirname(abspath(__file__)), pattern=pattern) \ No newline at end of file From e3f77f16c371fb4c5e73fd5b1524d71f2fbf3be3 Mon Sep 17 00:00:00 2001 From: chapeau Date: Tue, 20 Feb 2024 16:20:49 +0100 Subject: [PATCH 2/6] Move ldap tests under the correct app --- ldap_sync/tests.py | 100 ++++++++++++++++++++++++++++++++++++++++++++- users/tests.py | 40 ------------------ 2 files changed, 99 insertions(+), 41 deletions(-) diff --git a/ldap_sync/tests.py b/ldap_sync/tests.py index 7ce503c2..27c6d3f5 100644 --- a/ldap_sync/tests.py +++ b/ldap_sync/tests.py @@ -1,3 +1,101 @@ +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. 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. +"""users.tests +The tests for the Users module. +""" + +import os.path + +import volatildap +from django.conf import settings from django.test import TestCase -# Create your tests here. +from . import models + +class LdapEnabledTestCase(TestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.ldap = volatildap.LdapServer( + # Load some initial data + initial={'ou=people': { + 'ou': ['people'], + 'objectClass': ['organizationalUnit'], + }}, + # Enable more LDAP schemas + schemas=['core.schema', 'cosine.schema', 'inetorgperson.schema', 'nis.schema'], + ) + # The volatildap server uses specific defaults, and listens on an arbitrary port. + # Copy the server-side values to Django settings + settings.DATABASES['ldap']['USER'] = cls.ldap.rootdn + settings.DATABASES['ldap']['PASSWORD'] = cls.ldap.rootpw + settings.DATABASES['ldap']['NAME'] = cls.ldap.uri + + def setUp(self): + super().setUp() + # Starting an already-started volatildap server performs a data reset + self.ldap.start() + + @classmethod + def tearDownClass(cls): + # Free up resources on teardown. + cls.ldap.stop() + super().tearDownClass() + +class LdapUserTestCase(TestCase): + def test_create_ldap_user(self): + g = models.LdapUser.objects.create( + gid="500", + name="users_test_ldapuser", + uid="users_test_ldapuser", + uidNumber="21001", + sn="users_test_ldapuser", + login_shell="/bin/false", + mail="user@example.net", + given_name="users_test_ldapuser", + home_directory="/home/moamoak", + display_name="users_test_ldapuser", + dialupAccess="False", + sambaSID="21001", + user_password="{SSHA}aBcDeFgHiJkLmNoPqRsTuVwXyZ012345", + sambat_nt_password="0123456789ABCDEF0123456789ABCDEF", + macs=[], + shadowexpire="0", + ) + self.assertEqual(g.name, "users_test_ldapuser") + + +class LdapUserGroupTestCase(TestCase): + def test_create_ldap_user_group(self): + g = models.LdapUserGroup.objects.create( + gid="501", members=[], name="users_test_ldapusergroup" + ) + self.assertEqual(g.name, "users_test_ldapusergroup") + + +class LdapServiceUserTestCase(TestCase): + def test_create_ldap_service_user(self): + g = models.LdapServiceUser.objects.create( + name="users_test_ldapserviceuser", + user_password="{SSHA}AbCdEfGhIjKlMnOpQrStUvWxYz987654", + ) + self.assertEqual(g.name, "users_test_ldapserviceuser") diff --git a/users/tests.py b/users/tests.py index 805fbaa8..954d4fc5 100644 --- a/users/tests.py +++ b/users/tests.py @@ -42,43 +42,3 @@ class ListShellTestCase(TestCase): def test_shell_are_created(self): s = models.ListShell.objects.create(shell="/bin/zsh") self.assertEqual(s.shell, "/bin/zsh") - - -class LdapUserTestCase(TestCase): - def test_create_ldap_user(self): - g = models.LdapUser.objects.create( - gid="500", - name="users_test_ldapuser", - uid="users_test_ldapuser", - uidNumber="21001", - sn="users_test_ldapuser", - login_shell="/bin/false", - mail="user@example.net", - given_name="users_test_ldapuser", - home_directory="/home/moamoak", - display_name="users_test_ldapuser", - dialupAccess="False", - sambaSID="21001", - user_password="{SSHA}aBcDeFgHiJkLmNoPqRsTuVwXyZ012345", - sambat_nt_password="0123456789ABCDEF0123456789ABCDEF", - macs=[], - shadowexpire="0", - ) - self.assertEqual(g.name, "users_test_ldapuser") - - -class LdapUserGroupTestCase(TestCase): - def test_create_ldap_user_group(self): - g = models.LdapUserGroup.objects.create( - gid="501", members=[], name="users_test_ldapusergroup" - ) - self.assertEqual(g.name, "users_test_ldapusergroup") - - -class LdapServiceUserTestCase(TestCase): - def test_create_ldap_service_user(self): - g = models.LdapServiceUser.objects.create( - name="users_test_ldapserviceuser", - user_password="{SSHA}AbCdEfGhIjKlMnOpQrStUvWxYz987654", - ) - self.assertEqual(g.name, "users_test_ldapserviceuser") From c95e4b7a4b0d6d6b0c1ca379a314f21159e63f0f Mon Sep 17 00:00:00 2001 From: chapeau Date: Tue, 20 Feb 2024 16:22:57 +0100 Subject: [PATCH 3/6] Fix some tests --- api/tests.py | 49 ++++++++++++++++++++++---------------- cotisations/test_models.py | 21 ++++++++++++---- cotisations/test_views.py | 6 +++-- users/test_models.py | 15 +++++++----- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/api/tests.py b/api/tests.py index 32c1e264..04455114 100644 --- a/api/tests.py +++ b/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. diff --git a/cotisations/test_models.py b/cotisations/test_models.py index ea19725b..c0f8c463 100644 --- a/cotisations/test_models.py +++ b/cotisations/test_models.py @@ -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)), diff --git a/cotisations/test_views.py b/cotisations/test_views.py index 9f9b80c7..1d6cbe3d 100644 --- a/cotisations/test_views.py +++ b/cotisations/test_views.py @@ -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) diff --git a/users/test_models.py b/users/test_models.py index 665ff6c4..1a4072b8 100644 --- a/users/test_models.py +++ b/users/test_models.py @@ -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), From c12cc07d724e9ff8cb9f75390179bc9226f9e59b Mon Sep 17 00:00:00 2001 From: chapeau Date: Thu, 29 Feb 2024 11:07:26 +0100 Subject: [PATCH 4/6] Fix cotisations/test_views tests --- api/tests.py | 2 +- cotisations/test_views.py | 77 +++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/api/tests.py b/api/tests.py index 04455114..3350a3fe 100644 --- a/api/tests.py +++ b/api/tests.py @@ -670,7 +670,7 @@ class APIEndpointsTestCase(APITestCase): def assert_more(response, url, format): """Assert the response is valid json when format is json""" - if format is "json": + if format == "json": json.loads(response.content.decode()) self.check_responses_code( diff --git a/cotisations/test_views.py b/cotisations/test_views.py index 1d6cbe3d..bf3a3229 100644 --- a/cotisations/test_views.py +++ b/cotisations/test_views.py @@ -12,13 +12,41 @@ from .models import Article, Cotisation, Facture, Paiement, Vente class NewFactureTests(TestCase): + @classmethod + def setUpTestData(cls): + cls.paiement = Paiement.objects.create(moyen="test payment") + cls.article_one_day = Article.objects.create( + name="One day", + prix=0, + duration_connection=0, + duration_days_connection=1, + duration_membership=0, + duration_days_membership=1, + available_for_everyone=True, + ) + cls.article_one_month = Article.objects.create( + name="One mounth", + prix=0, + duration_connection=1, + duration_days_connection=0, + duration_membership=1, + duration_days_membership=0, + available_for_everyone=True, + ) + cls.article_one_month_and_one_week = Article.objects.create( + name="One mounth and one week", + prix=0, + duration_connection=1, + duration_days_connection=7, + duration_membership=1, + duration_days_membership=7, + available_for_everyone=True, + ) + + def tearDown(self): self.user.facture_set.all().delete() self.user.delete() - self.paiement.delete() - self.article_one_day.delete() - self.article_one_month.delete() - self.article_one_month_and_one_week.delete() def setUp(self): self.user = Adherent.objects.create(pseudo="testUser", email="test@example.org") @@ -34,35 +62,6 @@ class NewFactureTests(TestCase): ] ) self.user.save() - - self.paiement = Paiement.objects.create(moyen="test payment") - self.article_one_day = Article.objects.create( - name="One day", - prix=0, - duration_connection=0, - duration_days_connection=1, - duration_membership=0, - duration_days_membership=1, - available_for_everyone=True, - ) - self.article_one_month = Article.objects.create( - name="One mounth", - prix=0, - duration_connection=1, - duration_days_connection=0, - duration_membership=1, - duration_days_membership=0, - available_for_everyone=True, - ) - self.article_one_month_and_one_week = Article.objects.create( - name="One mounth and one week", - prix=0, - duration_connection=1, - duration_days_connection=7, - duration_membership=1, - duration_days_membership=7, - available_for_everyone=True, - ) self.client.login(username="testUser", password="plopiplop") def test_invoice_with_one_day(self): @@ -72,7 +71,7 @@ class NewFactureTests(TestCase): "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, - "form-0-article": 1, + "form-0-article": self.article_one_day.pk, "form-0-quantity": 1, } date = timezone.now() @@ -94,7 +93,7 @@ class NewFactureTests(TestCase): "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, - "form-0-article": 2, + "form-0-article": self.article_one_month.pk, "form-0-quantity": 1, } date = timezone.now() @@ -114,9 +113,9 @@ class NewFactureTests(TestCase): "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, - "form-0-article": 1, + "form-0-article": self.article_one_day.pk, "form-0-quantity": 7, - "form-1-article": 2, + "form-1-article": self.article_one_month.pk, "form-1-quantity": 1, } date = timezone.now() @@ -137,9 +136,9 @@ class NewFactureTests(TestCase): "form-INITIAL_FORMS": 0, "form-MIN_NUM_FORMS": 0, "form-MAX_NUM_FORMS": 1000, - "form-0-article": 2, + "form-0-article": self.article_one_month.pk, "form-0-quantity": 1, - "form-1-article": 2, + "form-1-article": self.article_one_month.pk, "form-1-quantity": 1, } response = self.client.post( From 55b0d7bc629efb0e1329708189076c880a51a291 Mon Sep 17 00:00:00 2001 From: chapeau Date: Thu, 29 Feb 2024 14:01:25 +0100 Subject: [PATCH 5/6] remove tests for cotisation starting at a specified date, as the feature is broken an unused --- cotisations/test_models.py | 58 -------------------------------------- 1 file changed, 58 deletions(-) diff --git a/cotisations/test_models.py b/cotisations/test_models.py index c0f8c463..8c582ceb 100644 --- a/cotisations/test_models.py +++ b/cotisations/test_models.py @@ -100,35 +100,6 @@ class VenteModelTests(TestCase): self.assertEqual(end_memb.month, expected_end.month) self.assertEqual(end_memb.year, expected_end.year) - 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", - duration_connection=0, - duration_days_connection=1, - duration_membership=0, - 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)), - ) - 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, 17)), - ) - def test_one_day_cotisation_membership_only(self): """ It should be possible to have one day membership without connection. @@ -215,35 +186,6 @@ class VenteModelTests(TestCase): 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.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)), - ) - 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 From 1bf6b36e99c6272bde1a743c0d8c680db30e85cb Mon Sep 17 00:00:00 2001 From: chapeau Date: Sat, 2 Mar 2024 15:22:00 +0100 Subject: [PATCH 6/6] Fix typos --- api/__init__.py | 2 +- ldap_sync/__init__.py | 2 +- radius/__init__.py | 2 +- tickets/__init__.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/__init__.py b/api/__init__.py index 745e9089..2a28c95a 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -23,7 +23,7 @@ from django.conf import settings as django_settings def load_tests(loader, tests, pattern): """ - As this is an optionnal app, loads its tests only if it is installed. + As this is an optional app, load its tests only if it is installed. """ if "api" in django_settings.INSTALLED_APPS: return loader.discover(start_dir=dirname(abspath(__file__)), pattern=pattern) \ No newline at end of file diff --git a/ldap_sync/__init__.py b/ldap_sync/__init__.py index 83cad363..d0503716 100644 --- a/ldap_sync/__init__.py +++ b/ldap_sync/__init__.py @@ -23,7 +23,7 @@ from django.conf import settings as django_settings def load_tests(loader, tests, pattern): """ - As this is an optionnal app, loads its tests only if it is installed. + As this is an optional app, load its tests only if it is installed. """ if "ldap_sync" in django_settings.INSTALLED_APPS: return loader.discover(start_dir=dirname(abspath(__file__)), pattern=pattern) \ No newline at end of file diff --git a/radius/__init__.py b/radius/__init__.py index 745e9089..2a28c95a 100644 --- a/radius/__init__.py +++ b/radius/__init__.py @@ -23,7 +23,7 @@ from django.conf import settings as django_settings def load_tests(loader, tests, pattern): """ - As this is an optionnal app, loads its tests only if it is installed. + As this is an optional app, load its tests only if it is installed. """ if "api" in django_settings.INSTALLED_APPS: return loader.discover(start_dir=dirname(abspath(__file__)), pattern=pattern) \ No newline at end of file diff --git a/tickets/__init__.py b/tickets/__init__.py index 745e9089..2a28c95a 100644 --- a/tickets/__init__.py +++ b/tickets/__init__.py @@ -23,7 +23,7 @@ from django.conf import settings as django_settings def load_tests(loader, tests, pattern): """ - As this is an optionnal app, loads its tests only if it is installed. + As this is an optional app, load its tests only if it is installed. """ if "api" in django_settings.INSTALLED_APPS: return loader.discover(start_dir=dirname(abspath(__file__)), pattern=pattern) \ No newline at end of file