sobjects/test/unittest_register_user.py
changeset 9687 00c2356faba7
child 9688 1f6ecd90df4f
equal deleted inserted replaced
9686:9a04e48e780b 9687:00c2356faba7
       
     1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 """unittest for cubicweb.dbapi"""
       
    19 
       
    20 from cubicweb import ValidationError
       
    21 from cubicweb.web import Unauthorized
       
    22 from cubicweb.devtools.testlib import CubicWebTC
       
    23 
       
    24 
       
    25 class RegisterUserTC(CubicWebTC):
       
    26 
       
    27     def test_register_user_service(self):
       
    28         acc = self.new_access('admin')
       
    29         with acc.client_cnx() as cnx:
       
    30             cnx.call_service('register_user', login=u'foo1', password=u'bar1',
       
    31                              email=u'foo1@bar1.com', firstname=u'Foo1',
       
    32                              surname=u'Bar1')
       
    33 
       
    34         acc = self.new_access('anon')
       
    35         with acc.client_cnx() as cnx:
       
    36             self.assertRaises(Unauthorized, cnx.call_service, 'register_user',
       
    37                               login=u'foo2', password=u'bar2',
       
    38                               email=u'foo2@bar2.com', firstname=u'Foo2', surname=u'Bar2')
       
    39 
       
    40         with self.repo.internal_cnx() as cnx:
       
    41             cnx.call_service('register_user', login=u'foo3',
       
    42                              password=u'bar3', email=u'foo3@bar3.com',
       
    43                              firstname=u'Foo3', surname=u'Bar3')
       
    44             # same login
       
    45             with self.assertRaises(ValidationError):
       
    46                 cnx.call_service('register_user', login=u'foo3',
       
    47                                  password=u'bar3')
       
    48 
       
    49 
       
    50 if __name__ == '__main__':
       
    51     from logilab.common.testlib import unittest_main
       
    52     unittest_main()