Work on testing data
authorNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Wed, 23 Sep 2015 13:17:04 +0000 (15:17 +0200)
committerNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Wed, 23 Sep 2015 13:17:04 +0000 (15:17 +0200)
database/platal/factories.py [new file with mode: 0644]
database/platal/static_data.py [new file with mode: 0644]

diff --git a/database/platal/factories.py b/database/platal/factories.py
new file mode 100644 (file)
index 0000000..b955ad2
--- /dev/null
@@ -0,0 +1,104 @@
+# -*- 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)
+
diff --git a/database/platal/static_data.py b/database/platal/static_data.py
new file mode 100644 (file)
index 0000000..14a0ad5
--- /dev/null
@@ -0,0 +1,26 @@
+# -*- 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...