sobjects/test/unittest_email.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 16 Sep 2009 16:39:03 +0200
branch3.5
changeset 3253 905e269ff853
parent 1977 606923dff11b
child 3293 69c0ba095536
child 4212 ab6573088b4a
permissions -rw-r--r--
email hooks tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
from cubicweb.devtools.apptest import EnvBasedTC
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
class EmailAddressHooksTC(EnvBasedTC):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
    def test_use_email_set_primary_email(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
        self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U use_email X WHERE U login "admin"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
        self.assertEquals(self.execute('Any A WHERE U primary_email X, U login "admin", X address A').rows,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
                          [])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
        self.assertEquals(self.execute('Any A WHERE U primary_email X, U login "admin", X address A')[0][0],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
                          'admin@logilab.fr')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
        # having another email should'nt change anything
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
        self.execute('INSERT EmailAddress X: X address "a@logilab.fr", U use_email X WHERE U login "admin"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
        self.assertEquals(self.execute('Any A WHERE U primary_email X, U login "admin", X address A')[0][0],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
                          'admin@logilab.fr')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
    def test_primary_email_set_use_email(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
        self.execute('INSERT EmailAddress X: X address "admin@logilab.fr", U primary_email X WHERE U login "admin"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
        self.assertEquals(self.execute('Any A WHERE U use_email X, U login "admin", X address A').rows,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
                          [])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
        self.assertEquals(self.execute('Any A WHERE U use_email X, U login "admin", X address A')[0][0],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
    from logilab.common.testlib import unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
    unittest_main()