Beispiel #1
0
    def test_contextmanager(self):
        mock_dbapi2 = mock.MagicMock()
        pool = ConnectionPool(mock_dbapi2, {}, maxsize=10)

        with pool.connection() as connection:
            mock_dbapi2.assert_has_calls([mock.call.connect()])
            self.assertEqual(id(connection),
                             id(mock_dbapi2.connect.return_value))

        mock_dbapi2.assert_has_calls([
            mock.call.connect(),
            mock.call.connect().rollback(),
        ])
Beispiel #2
0
    def test_contextmanager_error(self):  # pylint: disable=no-self-use
        class MockDBAPI2Error(Exception):
            pass

        mock_dbapi2 = mock.MagicMock()
        pool = ConnectionPool(mock_dbapi2, {}, maxsize=10)

        try:
            with pool.connection():
                raise MockDBAPI2Error
        except MockDBAPI2Error:
            pass

        mock_dbapi2.assert_has_calls([
            mock.call.connect(),
            mock.call.connect().rollback(),
        ])
Beispiel #3
0
    def test_contextmanager(self):
        mock_dbapi2 = mock.MagicMock()
        pool = ConnectionPool(mock_dbapi2, {}, maxsize=10)

        with pool.connection() as connection:
            mock_dbapi2.assert_has_calls(
                [
                    mock.call.connect()
                ]
            )
            self.assertEqual(
                id(connection),
                id(mock_dbapi2.connect.return_value)
            )

        mock_dbapi2.assert_has_calls(
            [
                mock.call.connect(),
                mock.call.connect().rollback(),
            ]
        )