cubicweb/sobjects/test/unittest_register_user.py
changeset 11368 a32209aba682
parent 11057 0b59724cb3f2
child 11369 3c8d345d0f3a
equal deleted inserted replaced
11367:5379c5dbc2c5 11368:a32209aba682
    22 from cubicweb.devtools.testlib import CubicWebTC
    22 from cubicweb.devtools.testlib import CubicWebTC
    23 
    23 
    24 
    24 
    25 class RegisterUserTC(CubicWebTC):
    25 class RegisterUserTC(CubicWebTC):
    26 
    26 
    27     def test_register_user_service(self):
    27     def test_register_user_service_anon(self):
    28         acc = self.admin_access
    28         with self.new_access('anon').client_cnx() as cnx:
    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',
    29             self.assertRaises(Unauthorized, cnx.call_service, 'register_user',
    37                               login=u'foo2', password=u'bar2',
    30                               login=u'foo2', password=u'bar2',
    38                               email=u'foo2@bar2.com', firstname=u'Foo2', surname=u'Bar2')
    31                               email=u'foo2@bar2.com', firstname=u'Foo2', surname=u'Bar2')
    39 
    32 
    40         with self.repo.internal_cnx() as cnx:
    33     def test_register_user_service_unique(self):
       
    34         with self.admin_access.cnx() as cnx:
    41             cnx.call_service('register_user', login=u'foo3',
    35             cnx.call_service('register_user', login=u'foo3',
    42                              password=u'bar3', email=u'foo3@bar3.com',
    36                              password=u'bar3', email=u'foo3@bar3.com',
    43                              firstname=u'Foo3', surname=u'Bar3')
    37                              firstname=u'Foo3', surname=u'Bar3')
    44             # same login
    38             # same login
    45             with self.assertRaises(ValidationError):
    39             with self.assertRaises(ValidationError):
    46                 cnx.call_service('register_user', login=u'foo3',
    40                 cnx.call_service('register_user', login=u'foo3',
    47                                  password=u'bar3')
    41                                  password=u'bar3')
    48 
    42 
    49     def test_register_user_attributes(self):
    43     def test_register_user_attributes(self):
    50         with self.repo.internal_cnx() as cnx:
    44         with self.admin_access.cnx() as cnx:
    51             cnx.call_service('register_user', login=u'foo3',
    45             cnx.call_service('register_user', login=u'foo3',
    52                              password=u'bar3', email=u'foo3@bar3.com',
    46                              password=u'bar3', email=u'foo3@bar3.com',
    53                              firstname=u'Foo3', surname=u'Bar3')
    47                              firstname=u'Foo3', surname=u'Bar3')
    54             cnx.commit()
    48             cnx.commit()
    55 
    49 
    57             user = cnx.find('CWUser', login=u'foo3').one()
    51             user = cnx.find('CWUser', login=u'foo3').one()
    58             self.assertEqual(user.firstname, u'Foo3')
    52             self.assertEqual(user.firstname, u'Foo3')
    59             self.assertEqual(user.use_email[0].address, u'foo3@bar3.com')
    53             self.assertEqual(user.use_email[0].address, u'foo3@bar3.com')
    60 
    54 
    61     def test_register_user_groups(self):
    55     def test_register_user_groups(self):
    62         with self.repo.internal_cnx() as cnx:
    56         with self.admin_access.cnx() as cnx:
    63             # default
    57             # default
    64             cnx.call_service('register_user', login=u'foo_user',
    58             cnx.call_service('register_user', login=u'foo_user',
    65                              password=u'bar_user', email=u'foo_user@bar_user.com',
    59                              password=u'bar_user', email=u'foo_user@bar_user.com',
    66                              firstname=u'Foo_user', surname=u'Bar_user')
    60                              firstname=u'Foo_user', surname=u'Bar_user')
    67 
    61