Пример #1
0
 def test_ping_returns_false_if_unavailable_in_readonly_mode(self):
     self.request.registry.settings['readonly'] = 'true'
     ping = heartbeat(self.permission)
     with mock.patch.object(self.permission,
                            'user_principals',
                            side_effect=exceptions.BackendError("Boom!")):
         self.assertFalse(ping(self.request))
Пример #2
0
 def setUp(self):
     super(BackendErrorTest, self).setUp()
     self.patcher = mock.patch.object(
         self.storage,
         'create',
         side_effect=storage_exceptions.BackendError())
     self.addCleanup(self.patcher.stop)
Пример #3
0
    def connect(self, readonly=False, force_commit=False):
        """
        Pulls a connection from the pool when context is entered and
        returns it when context is exited.

        A COMMIT is performed on the current transaction if everything went
        well. Otherwise transaction is ROLLBACK, and everything cleaned up.
        """
        with_transaction = not readonly and self.commit_manually
        session = None
        try:
            # Pull connection from pool.
            session = self.session_factory()
            # Start context
            yield session
            if not readonly and not self.commit_manually:
                # Mark session as dirty.
                self.invalidate(session)
            # Success
            if with_transaction:
                session.commit()
            elif force_commit:
                # Commit like would do a succesful request.
                zope_transaction.commit()

        except sqlalchemy.exc.SQLAlchemyError as e:
            logger.error(e)
            if session and with_transaction:
                session.rollback()
            raise exceptions.BackendError(original=e)

        finally:
            if session and self.commit_manually:
                # Give back to pool if commit done manually.
                session.close()
Пример #4
0
 def wrapped(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except redis.RedisError as e:
         logger.exception(e)
         raise exceptions.BackendError(original=e)
Пример #5
0
 def __init__(self, *args, **kwargs):
     super(StorageErrorTest, self).__init__(*args, **kwargs)
     self.error = storage_exceptions.BackendError(ValueError())
     self.storage_error_patcher = mock.patch(
         'cliquet.storage.redis.Storage.create', side_effect=self.error)