Commit | Line | Data |
---|---|---|
e0a096ae NI |
1 | # -*- coding: utf-8 -*- |
2 | #*************************************************************************** | |
3 | #* Copyright (C) 2015 Polytechnique.org * | |
4 | #* http://opensource.polytechnique.org/ * | |
5 | #* * | |
6 | #* This program is free software; you can redistribute it and/or modify * | |
7 | #* it under the terms of the GNU General Public License as published by * | |
8 | #* the Free Software Foundation; either version 2 of the License, or * | |
9 | #* (at your option) any later version. * | |
10 | #* * | |
11 | #* This program is distributed in the hope that it will be useful, * | |
12 | #* but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 | #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 | #* GNU General Public License for more details. * | |
15 | #* * | |
16 | #* You should have received a copy of the GNU General Public License * | |
17 | #* along with this program; if not, write to the Free Software * | |
18 | #* Foundation, Inc., * | |
19 | #* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | #***************************************************************************/ | |
21 | """FactoryBoy classes aimed to ease populating the database | |
22 | """ | |
23 | from __future__ import unicode_literals | |
24 | ||
25 | import factory | |
26 | import factory.django | |
27 | import re | |
28 | import unicodedata | |
29 | ||
30 | from . import models | |
31 | ||
32 | ||
33 | def emailify(string): | |
34 | """Transform a UTF-8 string to an ASCII representation suitable for an | |
35 | email address | |
36 | ||
37 | >>> emailify('ABC def') | |
38 | 'abc-def' | |
39 | >>> emailify('gégé à l\'accent') | |
40 | 'gege-a-l-accent' | |
41 | """ | |
42 | normstr = unicodedata.normalize('NFKD', string) | |
43 | asciitext = normstr.encode('ascii', 'ignore').decode('ascii') | |
44 | return re.sub(r'\W', '-', asciitext) | |
45 | ||
46 | ||
47 | class AccountFactory(factory.django.DjangoModelFactory): | |
48 | class Meta: | |
49 | model = models.Account | |
50 | ||
51 | FIRSTNAMES_F = ( | |
52 | 'Elisabeth', | |
53 | 'Emmanuelle', | |
54 | 'Marie', | |
55 | 'Marie-Hélène', | |
56 | ) | |
57 | FIRSTNAMES_M = ( | |
58 | 'Jean', | |
59 | 'Jean-Baptiste', | |
60 | 'Jean-Pierre', | |
61 | 'Jacques', | |
62 | 'Joseph', | |
63 | 'Luc', | |
64 | 'Marc', | |
65 | 'Matthieu', | |
66 | 'Pierre', | |
67 | 'Simon', | |
68 | ) | |
69 | FIRSTNAMES = FIRSTNAMES_F + FIRSTNAMES_M | |
70 | LASTNAMES = ( | |
71 | 'Bibi', | |
72 | 'Exemple', | |
73 | 'De La Machine', | |
74 | 'Le Testeur', | |
75 | ) | |
76 | ||
77 | firstname = factory.Sequence(lambda n: FIRSTNAMES[n % len(FIRSTNAMES)]) | |
78 | lastname = factory.Sequence(lambda n: LASTNAMES[n % len(LASTNAMES)]) | |
79 | hruid = models.CharField(max_length=255, unique=True) | |
80 | type = models.ForeignKey(AccountType, null=True, db_column='type', blank=True) | |
81 | user_perms = models.CharField(max_length=288, blank=True) | |
82 | is_admin = models.BooleanField() | |
83 | state = models.CharField(max_length=24) | |
84 | password = models.CharField(max_length=120, blank=True) | |
85 | token = models.CharField(max_length=96, blank=True) | |
86 | weak_password = models.CharField(max_length=768, blank=True) | |
87 | registration_date = models.DateTimeField() | |
88 | flags = models.CharField(max_length=15) | |
89 | comment = models.CharField(max_length=765, blank=True) | |
90 | email = models.CharField(max_length=765, blank=True) | |
91 | firstname = models.CharField(max_length=765, blank=True) | |
92 | lastname = models.CharField(max_length=765, blank=True) | |
93 | full_name = models.CharField(max_length=765, blank=True) | |
94 | directory_name = models.CharField(max_length=765, blank=True) | |
95 | sort_name = models.CharField(max_length=765, blank=True) | |
96 | display_name = models.CharField(max_length=765, blank=True) | |
97 | sex = models.CharField(max_length=18) | |
98 | email_format = models.CharField(max_length=12) | |
99 | skin = models.ForeignKey(Skin, null=True, db_column='skin', blank=True) | |
100 | last_version = models.CharField(max_length=48) | |
101 | best_domain = models.ForeignKey(EmailVirtualDomain, null=True, db_column='best_domain', blank=True) | |
102 | from_email = models.CharField(max_length=765) | |
103 | from_format = models.CharField(max_length=12) | |
104 |