--- /dev/null
+# -*- coding: utf-8 -*-
+#***************************************************************************
+#* Copyright (C) 2015 Polytechnique.org *
+#* http://opensource.polytechnique.org/ *
+#* *
+#* 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., *
+#* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+#***************************************************************************/
+"""FactoryBoy classes aimed to ease populating the database
+"""
+from __future__ import unicode_literals
+
+import factory
+import factory.django
+import re
+import unicodedata
+
+from . import models
+
+
+def emailify(string):
+ """Transform a UTF-8 string to an ASCII representation suitable for an
+ email address
+
+ >>> emailify('ABC def')
+ 'abc-def'
+ >>> emailify('gégé à l\'accent')
+ 'gege-a-l-accent'
+ """
+ normstr = unicodedata.normalize('NFKD', string)
+ asciitext = normstr.encode('ascii', 'ignore').decode('ascii')
+ return re.sub(r'\W', '-', asciitext)
+
+
+class AccountFactory(factory.django.DjangoModelFactory):
+ class Meta:
+ model = models.Account
+
+ FIRSTNAMES_F = (
+ 'Elisabeth',
+ 'Emmanuelle',
+ 'Marie',
+ 'Marie-Hélène',
+ )
+ FIRSTNAMES_M = (
+ 'Jean',
+ 'Jean-Baptiste',
+ 'Jean-Pierre',
+ 'Jacques',
+ 'Joseph',
+ 'Luc',
+ 'Marc',
+ 'Matthieu',
+ 'Pierre',
+ 'Simon',
+ )
+ FIRSTNAMES = FIRSTNAMES_F + FIRSTNAMES_M
+ LASTNAMES = (
+ 'Bibi',
+ 'Exemple',
+ 'De La Machine',
+ 'Le Testeur',
+ )
+
+ firstname = factory.Sequence(lambda n: FIRSTNAMES[n % len(FIRSTNAMES)])
+ lastname = factory.Sequence(lambda n: LASTNAMES[n % len(LASTNAMES)])
+ hruid = models.CharField(max_length=255, unique=True)
+ type = models.ForeignKey(AccountType, null=True, db_column='type', blank=True)
+ user_perms = models.CharField(max_length=288, blank=True)
+ is_admin = models.BooleanField()
+ state = models.CharField(max_length=24)
+ password = models.CharField(max_length=120, blank=True)
+ token = models.CharField(max_length=96, blank=True)
+ weak_password = models.CharField(max_length=768, blank=True)
+ registration_date = models.DateTimeField()
+ flags = models.CharField(max_length=15)
+ comment = models.CharField(max_length=765, blank=True)
+ email = models.CharField(max_length=765, blank=True)
+ firstname = models.CharField(max_length=765, blank=True)
+ lastname = models.CharField(max_length=765, blank=True)
+ full_name = models.CharField(max_length=765, blank=True)
+ directory_name = models.CharField(max_length=765, blank=True)
+ sort_name = models.CharField(max_length=765, blank=True)
+ display_name = models.CharField(max_length=765, blank=True)
+ sex = models.CharField(max_length=18)
+ email_format = models.CharField(max_length=12)
+ skin = models.ForeignKey(Skin, null=True, db_column='skin', blank=True)
+ last_version = models.CharField(max_length=48)
+ best_domain = models.ForeignKey(EmailVirtualDomain, null=True, db_column='best_domain', blank=True)
+ from_email = models.CharField(max_length=765)
+ from_format = models.CharField(max_length=12)
+
--- /dev/null
+# -*- coding: utf-8 -*-
+#***************************************************************************
+#* Copyright (C) 2015 Polytechnique.org *
+#* http://opensource.polytechnique.org/ *
+#* *
+#* 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., *
+#* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+#***************************************************************************/
+"""Define the data which must be initially in the database"""
+from __future__ import unicode_literals
+
+
+# XXX TODO Find a Django-way to do this
+AccountType...