Commit | Line | Data |
---|---|---|
7751bc47 OL |
1 | #encoding UTF-8 |
2 | # -*- encoding: utf-8 -*- | |
3 | ||
4 | """ | |
5 | Configuration du site pour faire fonctionner les tests unitaires avec | |
6 | MySQL en RAM. | |
7 | """ | |
8 | ||
9 | from production import * | |
10 | ||
11 | DATABASES['default']['HOST'] = '/var/run/mysqld/mysqld-ram.sock' | |
12 | ||
13 | host = "mysql --socket=%s -uroot -e" % DATABASES['default']['HOST'] | |
14 | db = "unittests_%s" % DATABASES['default']['NAME'] | |
15 | DATABASES['default']['NAME'] = db | |
16 | DATABASES['default']['TEST_NAME'] = db | |
17 | user = DATABASES['default']['USER'] | |
18 | pwd = DATABASES['default']['PASSWORD'] | |
19 | ||
20 | cmd_creer_bd = "%(host)s \ | |
21 | 'CREATE DATABASE %(db)s;'" % { | |
22 | 'host': host, | |
23 | 'db': db, | |
24 | } | |
25 | ||
26 | cmd_creer_user = """%(host)s \ | |
27 | "GRANT USAGE ON *.* TO %(user)s@localhost \ | |
28 | IDENTIFIED BY '%(pwd)s';" """ % { | |
29 | 'host': host, | |
30 | 'user': user, | |
31 | 'pwd': pwd, | |
32 | } | |
33 | ||
34 | cmd_creer_privileges = "%(host)s \ | |
35 | 'GRANT ALL PRIVILEGES ON *.* TO %(user)s@localhost ;'" % { | |
36 | 'host': host, | |
37 | 'user': user, | |
38 | } | |
39 | ||
40 | ||
41 | # La bd non préfixée par "test_" a besoin d'exister pour lancer les tests. | |
42 | # Cette commande ne modifie rien, si la table existe déjà. | |
43 | os.system(cmd_creer_bd) | |
44 | ||
45 | # Création de l'accès à la base "test_xxx" en fonction de conf.py | |
46 | os.system(cmd_creer_user) | |
47 | os.system(cmd_creer_privileges) |