Пример #1
0
 def test_create_system_user_created(self, mock_crypt, mock_trans):
     from ramses import auth
     encoder = mock_crypt.bcrypt.BCRYPTPasswordManager()
     encoder.encode.return_value = '654321'
     config = Mock()
     config.registry.settings = {
         'system.user': '******',
         'system.password': '******',
         'system.email': '*****@*****.**',
     }
     config.registry.auth_model.get_or_create.return_value = (Mock(), True)
     auth.create_system_user(config)
     mock_trans.commit.assert_called_once_with()
     encoder.encode.assert_called_once_with('123456')
     config.registry.auth_model.get_or_create.assert_called_once_with(
         username='******',
         defaults={
             'password': '******',
             'email': '*****@*****.**',
             'groups': ['admin'],
             '_acl': [(Allow, 'g:admin', ALL_PERMISSIONS)],
         })
Пример #2
0
 def test_create_system_user_exists(self, mock_crypt, mock_trans):
     from ramses import auth
     encoder = mock_crypt.bcrypt.BCRYPTPasswordManager()
     encoder.encode.return_value = '654321'
     config = Mock()
     config.registry.settings = {
         'system.user': '******',
         'system.password': '******',
         'system.email': '*****@*****.**',
     }
     config.registry.auth_model.get_or_create.return_value = (1, False)
     auth.create_system_user(config)
     assert not mock_trans.commit.called
     encoder.encode.assert_called_once_with('123456')
     config.registry.auth_model.get_or_create.assert_called_once_with(
         username='******',
         defaults={
             'password': '******',
             'email': '*****@*****.**',
             'groups': ['admin'],
             '_acl': [(Allow, 'g:admin', ALL_PERMISSIONS)],
         }
     )
Пример #3
0
 def test_create_system_user_key_error(self):
     from ramses import auth
     config = Mock()
     config.registry.settings = {}
     auth.create_system_user(config)
     assert not config.registry.auth_model.get_or_create.called
Пример #4
0
 def test_create_system_user_key_error(self):
     from ramses import auth
     config = Mock()
     config.registry.settings = {}
     auth.create_system_user(config)
     assert not config.registry.auth_model.get_or_create.called