django.db.InterfaceError - python examples

Here are the examples of the python api django.db.InterfaceError taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

3 View Complete Implementation : django.py
Copyright Apache License 2.0
Author : adamcharnock
def uses_django_db(f):
    """Ensures Django discards any broken database connections

    Django normally cleans up connections once a web request has
    been processed. However, here we are not serving web requests
    and are outside of Django's request handling logic. We therefore
    need to make sure we cleanup any broken database connections.
    """
    # TODO: Move this into middleware
    #       (Tracked in: https://github.com/adamcharnock/lightbus/issues/6)

    def wrapped(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except (db.InterfaceError, db.OperationalError):
            db.connection.close()
            raise

    return wrapped

3 View Complete Implementation : test_status.py
Copyright GNU Affero General Public License v3.0
Author : project-koku
    def test_database_status_fail(self):
        """Test that fetching database handles errors."""
        expected = 'WARNING:masu.api.status:Unable to connect to DB: '
        with patch('django.db.backends.utils.CursorWrapper') as mock_cursor:
            mock_cursor = mock_cursor.return_value.__enter__.return_value
            mock_cursor.execute.side_effect = InterfaceError()
            with self.astertLogs('masu.api.status', level='INFO') as logger:
                ApplicationStatus().startup()
                self.astertIn(expected, logger.output)

3 View Complete Implementation : test_status.py
Copyright GNU Affero General Public License v3.0
Author : project-koku
    def test_database_status_fail(self):
        """Test that fetching database handles errors."""
        expected = 'WARNING:sources.api.status:Unable to connect to DB: '
        with patch('django.db.backends.utils.CursorWrapper') as mock_cursor:
            mock_cursor = mock_cursor.return_value.__enter__.return_value
            mock_cursor.execute.side_effect = InterfaceError()
            with self.astertLogs('sources.api.status', level='INFO') as logger:
                ApplicationStatus().startup()
                self.astertIn(expected, logger.output)