sobjects/test/unittest_email.py
changeset 3293 69c0ba095536
parent 2773 b2530e3e0afb
parent 3253 905e269ff853
child 4252 6c4f109c2b03
equal deleted inserted replaced
3230:1d25e928c299 3293:69c0ba095536
     3 :organization: Logilab
     3 :organization: Logilab
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 """
     7 """
       
     8 
       
     9 from cubicweb import Unauthorized
     8 from cubicweb.devtools.testlib import CubicWebTC
    10 from cubicweb.devtools.testlib import CubicWebTC
     9 
    11 
    10 class EmailAddressHooksTC(CubicWebTC):
    12 class EmailAddressHooksTC(CubicWebTC):
    11 
    13 
    12     def test_use_email_set_primary_email(self):
    14     def test_use_email_set_primary_email(self):
    28                           [])
    30                           [])
    29         self.commit()
    31         self.commit()
    30         self.assertEquals(self.execute('Any A WHERE U use_email X, U login "admin", X address A')[0][0],
    32         self.assertEquals(self.execute('Any A WHERE U use_email X, U login "admin", X address A')[0][0],
    31                           'admin@logilab.fr')
    33                           'admin@logilab.fr')
    32 
    34 
       
    35     def test_cardinality_check(self):
       
    36         email1 = self.execute('INSERT EmailAddress E: E address "client@client.com", U use_email E WHERE U login "admin"')[0][0]
       
    37         self.commit()
       
    38         self.execute('SET U primary_email E WHERE U login "anon", E address "client@client.com"')
       
    39         self.commit()
       
    40         rset = self.execute('Any X WHERE X use_email E, E eid %(e)s', {'e': email1})
       
    41         self.failIf(rset.rowcount != 1, rset)
       
    42 
       
    43     def test_security_check(self):
       
    44         self.create_user('toto')
       
    45         email1 = self.execute('INSERT EmailAddress E: E address "client@client.com", U use_email E WHERE U login "admin"')[0][0]
       
    46         self.commit()
       
    47         cnx = self.login('toto')
       
    48         cu = cnx.cursor()
       
    49         cu.execute('SET U primary_email E WHERE E eid %(e)s, U login "toto"',
       
    50                    {'e': email1})
       
    51         self.assertRaises(Unauthorized, cnx.commit)
       
    52 
    33 
    53 
    34 if __name__ == '__main__':
    54 if __name__ == '__main__':
    35     from logilab.common.testlib import unittest_main
    55     from logilab.common.testlib import unittest_main
    36     unittest_main()
    56     unittest_main()