|
@@ -7,8 +7,10 @@ import ldapdb
|
|
|
from datetime import date
|
|
|
from cStringIO import StringIO
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
+import unittest
|
|
|
|
|
|
from django import db
|
|
|
+from django.conf import settings
|
|
|
from django.test import TestCase, Client, override_settings
|
|
|
from django.contrib.auth.models import User
|
|
|
from django.core import mail, management
|
|
@@ -16,8 +18,8 @@ from django.core import mail, management
|
|
|
from coin.members.models import Member, MembershipFee, LdapUser
|
|
|
|
|
|
|
|
|
-class MemberTests(TestCase):
|
|
|
-
|
|
|
+@unittest.skipIf(not settings.LDAP_ACTIVATE, "LDAP disabled")
|
|
|
+class LDAPMemberTests(TestCase):
|
|
|
def test_when_creating_member_a_ldapuser_is_also_created_with_same_data(self):
|
|
|
"""
|
|
|
Test que lors de la création d'un nouveau membre, une entrée
|
|
@@ -161,71 +163,6 @@ class MemberTests(TestCase):
|
|
|
|
|
|
member.delete()
|
|
|
|
|
|
- def test_when_creating_member_username_is_well_defined(self):
|
|
|
- """
|
|
|
- Lors de la création d'un membre, le champ "username", s'il n'est pas
|
|
|
- définit doit être généré avec les contraintes suivantes :
|
|
|
- premières lettres du prénom + nom le tout en minuscule,
|
|
|
- sans caractères accentués et sans espaces.
|
|
|
- """
|
|
|
- random = os.urandom(4).encode('hex')
|
|
|
- first_name = 'Gérard-Étienne'
|
|
|
- last_name = 'Majax de la Boétie!B' + random
|
|
|
-
|
|
|
- control = 'gemajaxdelaboetieb' + random
|
|
|
- control = control[:30]
|
|
|
-
|
|
|
- member = Member(first_name=first_name, last_name=last_name)
|
|
|
- member.save()
|
|
|
-
|
|
|
- self.assertEqual(member.username, control)
|
|
|
-
|
|
|
- member.delete()
|
|
|
-
|
|
|
- def test_when_creating_member_with_username_already_exists_username_is_incr(self):
|
|
|
- """
|
|
|
- Lors de la création d'un membre, test si le username existe déjà,
|
|
|
- renvoi avec un incrément à la fin
|
|
|
- """
|
|
|
- random = os.urandom(4).encode('hex')
|
|
|
-
|
|
|
- member1 = Member(first_name='Hervé', last_name='DUPOND' + random, email='hdupond@coin.org')
|
|
|
- member1.save()
|
|
|
- self.assertEqual(member1.username, 'hdupond' + random)
|
|
|
-
|
|
|
- member2 = Member(first_name='Henri', last_name='DUPOND' + random, email='hdupond2@coin.org')
|
|
|
- member2.save()
|
|
|
- self.assertEqual(member2.username, 'hdupond' + random + '2')
|
|
|
-
|
|
|
- member3 = Member(first_name='Hector', last_name='DUPOND' + random, email='hdupond3@coin.org')
|
|
|
- member3.save()
|
|
|
- self.assertEqual(member3.username, 'hdupond' + random + '3')
|
|
|
-
|
|
|
- member1.delete()
|
|
|
- member2.delete()
|
|
|
- member3.delete()
|
|
|
-
|
|
|
- def test_when_creating_legal_entity_organization_name_is_used_for_username(self):
|
|
|
- """
|
|
|
- Lors de la créatio d'une entreprise, son nom doit être utilisée lors de
|
|
|
- la détermination automatique du username
|
|
|
- """
|
|
|
- random = os.urandom(4).encode('hex')
|
|
|
- member = Member(type='legal_entity', organization_name='ILLYSE' + random, email='illyse@coin.org')
|
|
|
- member.save()
|
|
|
- self.assertEqual(member.username, 'illyse' + random)
|
|
|
- member.delete()
|
|
|
-
|
|
|
- def test_when_creating_member_with_nickname_it_is_used_for_username(self):
|
|
|
- """
|
|
|
- Lors de la création d'une personne, qui a un pseudo, celui-ci est utilisé en priorité
|
|
|
- """
|
|
|
- random = os.urandom(4).encode('hex')
|
|
|
- member = Member(first_name='Richard', last_name='Stallman', nickname='rms' + random, email='illyse@coin.org')
|
|
|
- member.save()
|
|
|
- self.assertEqual(member.username, 'rms' + random)
|
|
|
-
|
|
|
- member.delete()
|
|
|
|
|
|
def test_when_saving_member_and_ldap_fail_dont_save(self):
|
|
|
"""
|
|
@@ -291,6 +228,74 @@ class MemberTests(TestCase):
|
|
|
|
|
|
# LdapUser.objects.get(pk=member.username).delete()
|
|
|
|
|
|
+
|
|
|
+class MemberTests(TestCase):
|
|
|
+ def test_when_creating_member_username_is_well_defined(self):
|
|
|
+ """
|
|
|
+ Lors de la création d'un membre, le champ "username", s'il n'est pas
|
|
|
+ définit doit être généré avec les contraintes suivantes :
|
|
|
+ premières lettres du prénom + nom le tout en minuscule,
|
|
|
+ sans caractères accentués et sans espaces.
|
|
|
+ """
|
|
|
+ random = os.urandom(4).encode('hex')
|
|
|
+ first_name = 'Gérard-Étienne'
|
|
|
+ last_name = 'Majax de la Boétie!B' + random
|
|
|
+
|
|
|
+ control = 'gemajaxdelaboetieb' + random
|
|
|
+ control = control[:30]
|
|
|
+
|
|
|
+ member = Member(first_name=first_name, last_name=last_name)
|
|
|
+ member.save()
|
|
|
+
|
|
|
+ self.assertEqual(member.username, control)
|
|
|
+
|
|
|
+ member.delete()
|
|
|
+
|
|
|
+ def test_when_creating_member_with_username_already_exists_username_is_incr(self):
|
|
|
+ """
|
|
|
+ Lors de la création d'un membre, test si le username existe déjà,
|
|
|
+ renvoi avec un incrément à la fin
|
|
|
+ """
|
|
|
+ random = os.urandom(4).encode('hex')
|
|
|
+
|
|
|
+ member1 = Member(first_name='Hervé', last_name='DUPOND' + random, email='hdupond@coin.org')
|
|
|
+ member1.save()
|
|
|
+ self.assertEqual(member1.username, 'hdupond' + random)
|
|
|
+
|
|
|
+ member2 = Member(first_name='Henri', last_name='DUPOND' + random, email='hdupond2@coin.org')
|
|
|
+ member2.save()
|
|
|
+ self.assertEqual(member2.username, 'hdupond' + random + '2')
|
|
|
+
|
|
|
+ member3 = Member(first_name='Hector', last_name='DUPOND' + random, email='hdupond3@coin.org')
|
|
|
+ member3.save()
|
|
|
+ self.assertEqual(member3.username, 'hdupond' + random + '3')
|
|
|
+
|
|
|
+ member1.delete()
|
|
|
+ member2.delete()
|
|
|
+ member3.delete()
|
|
|
+
|
|
|
+ def test_when_creating_legal_entity_organization_name_is_used_for_username(self):
|
|
|
+ """
|
|
|
+ Lors de la créatio d'une entreprise, son nom doit être utilisée lors de
|
|
|
+ la détermination automatique du username
|
|
|
+ """
|
|
|
+ random = os.urandom(4).encode('hex')
|
|
|
+ member = Member(type='legal_entity', organization_name='ILLYSE' + random, email='illyse@coin.org')
|
|
|
+ member.save()
|
|
|
+ self.assertEqual(member.username, 'illyse' + random)
|
|
|
+ member.delete()
|
|
|
+
|
|
|
+ def test_when_creating_member_with_nickname_it_is_used_for_username(self):
|
|
|
+ """
|
|
|
+ Lors de la création d'une personne, qui a un pseudo, celui-ci est utilisé en priorité
|
|
|
+ """
|
|
|
+ random = os.urandom(4).encode('hex')
|
|
|
+ member = Member(first_name='Richard', last_name='Stallman', nickname='rms' + random, email='illyse@coin.org')
|
|
|
+ member.save()
|
|
|
+ self.assertEqual(member.username, 'rms' + random)
|
|
|
+
|
|
|
+ member.delete()
|
|
|
+
|
|
|
def test_member_end_date_of_memberhip(self):
|
|
|
"""
|
|
|
Test que end_date_of_membership d'un membre envoi bien la date de fin d'adhésion
|