author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 26 Jan 2010 13:38:02 +0100 | |
changeset 4367 | fa02f7dccfe4 |
parent 4252 | 6c4f109c2b03 |
child 4673 | 6f8b925a29f4 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3253
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
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 |
""" |
3293 | 8 |
|
3253
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
9 |
from cubicweb import Unauthorized |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
10 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 11 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
12 |
class EmailAddressHooksTC(CubicWebTC): |
0 | 13 |
|
14 |
def test_use_email_set_primary_email(self): |
|
15 |
self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U use_email X WHERE U login "admin"') |
|
16 |
self.assertEquals(self.execute('Any A WHERE U primary_email X, U login "admin", X address A').rows, |
|
17 |
[]) |
|
18 |
self.commit() |
|
19 |
self.assertEquals(self.execute('Any A WHERE U primary_email X, U login "admin", X address A')[0][0], |
|
20 |
'admin@logilab.fr') |
|
21 |
# having another email should'nt change anything |
|
22 |
self.execute('INSERT EmailAddress X: X address "a@logilab.fr", U use_email X WHERE U login "admin"') |
|
23 |
self.commit() |
|
24 |
self.assertEquals(self.execute('Any A WHERE U primary_email X, U login "admin", X address A')[0][0], |
|
25 |
'admin@logilab.fr') |
|
26 |
||
27 |
def test_primary_email_set_use_email(self): |
|
28 |
self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U primary_email X WHERE U login "admin"') |
|
29 |
self.assertEquals(self.execute('Any A WHERE U use_email X, U login "admin", X address A').rows, |
|
30 |
[]) |
|
31 |
self.commit() |
|
32 |
self.assertEquals(self.execute('Any A WHERE U use_email X, U login "admin", X address A')[0][0], |
|
33 |
'admin@logilab.fr') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
34 |
|
3253
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
35 |
def test_cardinality_check(self): |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
36 |
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
|
37 |
self.commit() |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
38 |
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
|
39 |
self.commit() |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
40 |
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
|
41 |
self.failIf(rset.rowcount != 1, rset) |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
42 |
|
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
43 |
def test_security_check(self): |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
44 |
self.create_user('toto') |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
45 |
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
|
46 |
self.commit() |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
47 |
cnx = self.login('toto') |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
48 |
cu = cnx.cursor() |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
49 |
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
|
50 |
{'e': email1}) |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
51 |
self.assertRaises(Unauthorized, cnx.commit) |
905e269ff853
email hooks tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
52 |
|
0 | 53 |
|
54 |
if __name__ == '__main__': |
|
55 |
from logilab.common.testlib import unittest_main |
|
56 |
unittest_main() |