author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 16 Sep 2009 16:39:03 +0200 | |
branch | 3.5 |
changeset 3253 | 905e269ff853 |
parent 1977 | 606923dff11b |
child 3293 | 69c0ba095536 |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
""" |
3253
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
8 |
from cubicweb import Unauthorized |
0 | 9 |
from cubicweb.devtools.apptest import EnvBasedTC |
10 |
||
11 |
class EmailAddressHooksTC(EnvBasedTC): |
|
12 |
||
13 |
def test_use_email_set_primary_email(self): |
|
14 |
self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U use_email X WHERE U login "admin"') |
|
15 |
self.assertEquals(self.execute('Any A WHERE U primary_email X, U login "admin", X address A').rows, |
|
16 |
[]) |
|
17 |
self.commit() |
|
18 |
self.assertEquals(self.execute('Any A WHERE U primary_email X, U login "admin", X address A')[0][0], |
|
19 |
'admin@logilab.fr') |
|
20 |
# having another email should'nt change anything |
|
21 |
self.execute('INSERT EmailAddress X: X address "a@logilab.fr", U use_email X WHERE U login "admin"') |
|
22 |
self.commit() |
|
23 |
self.assertEquals(self.execute('Any A WHERE U primary_email X, U login "admin", X address A')[0][0], |
|
24 |
'admin@logilab.fr') |
|
25 |
||
26 |
def test_primary_email_set_use_email(self): |
|
27 |
self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U primary_email X WHERE U login "admin"') |
|
28 |
self.assertEquals(self.execute('Any A WHERE U use_email X, U login "admin", X address A').rows, |
|
29 |
[]) |
|
30 |
self.commit() |
|
31 |
self.assertEquals(self.execute('Any A WHERE U use_email X, U login "admin", X address A')[0][0], |
|
32 |
'admin@logilab.fr') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
33 |
|
3253
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
34 |
def test_cardinality_check(self): |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
35 |
email1 = self.execute('INSERT EmailAddress E: E address "client@client.com", U use_email E WHERE U login "admin"')[0][0] |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
36 |
self.commit() |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
37 |
self.execute('SET U primary_email E WHERE U login "anon", E address "client@client.com"') |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
38 |
self.commit() |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
39 |
rset = self.execute('Any X WHERE X use_email E, E eid %(e)s', {'e': email1}) |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
40 |
self.failIf(rset.rowcount != 1, rset) |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
41 |
|
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
42 |
def test_security_check(self): |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
43 |
self.create_user('toto') |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
44 |
email1 = self.execute('INSERT EmailAddress E: E address "client@client.com", U use_email E WHERE U login "admin"')[0][0] |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
45 |
self.commit() |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
46 |
cnx = self.login('toto') |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
47 |
cu = cnx.cursor() |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
48 |
cu.execute('SET U primary_email E WHERE E eid %(e)s, U login "toto"', |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
49 |
{'e': email1}) |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
50 |
self.assertRaises(Unauthorized, cnx.commit) |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
51 |
|
0 | 52 |
|
53 |
if __name__ == '__main__': |
|
54 |
from logilab.common.testlib import unittest_main |
|
55 |
unittest_main() |