sobjects/test/unittest_email.py
author Sandrine Ribeau <sandrine.ribeau@logilab.fr>
Wed, 09 Dec 2009 12:23:31 +0100
changeset 4073 03681ba6da0b
parent 3293 69c0ba095536
child 4252 6c4f109c2b03
permissions -rw-r--r--
cw 3.6 api update
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
"""
3293
69c0ba095536 backport 3.5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2773 3253
diff changeset
     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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
    def test_use_email_set_primary_email(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
        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
    16
        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
    17
                          [])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
        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
    20
                          'admin@logilab.fr')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
        # having another email should'nt change anything
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
        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
    23
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
        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
    25
                          'admin@logilab.fr')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
    def test_primary_email_set_use_email(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
        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
    29
        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
    30
                          [])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
        self.commit()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
        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
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
    from logilab.common.testlib import unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
    unittest_main()