示例#1
0
    def test__release_session(self, mock_database):
        from google.cloud.spanner_dbapi import Connection

        pool = self._make_pool()
        mock_database._pool = pool
        connection = Connection(INSTANCE, mock_database)
        connection._session = "session"

        connection._release_session()
        pool.put.assert_called_once_with("session")
        self.assertIsNone(connection._session)
示例#2
0
    def test__release_session(self):
        from google.cloud.spanner_dbapi import Connection

        with mock.patch("google.cloud.spanner_v1.database.Database") as mock_database:
            mock_database._pool = mock.MagicMock()
            mock_database._pool.put = mock.MagicMock()
            connection = Connection(self.INSTANCE, mock_database)
            connection._session = "session"

            connection._release_session()
            mock_database._pool.put.assert_called_once_with("session")
            self.assertIsNone(connection._session)
示例#3
0
    def test__session_checkout(self, mock_database):
        from google.cloud.spanner_dbapi import Connection

        pool = self._make_pool()
        mock_database._pool = pool
        connection = Connection(INSTANCE, mock_database)

        connection._session_checkout()
        pool.get.assert_called_once_with()
        self.assertEqual(connection._session, pool.get.return_value)

        connection._session = "db_session"
        connection._session_checkout()
        self.assertEqual(connection._session, "db_session")
示例#4
0
    def test__session_checkout(self):
        from google.cloud.spanner_dbapi import Connection

        with mock.patch("google.cloud.spanner_v1.database.Database") as mock_database:
            mock_database._pool = mock.MagicMock()
            mock_database._pool.get = mock.MagicMock(return_value="db_session_pool")
            connection = Connection(self.INSTANCE, mock_database)

            connection._session_checkout()
            mock_database._pool.get.assert_called_once_with()
            self.assertEqual(connection._session, "db_session_pool")

            connection._session = "db_session"
            connection._session_checkout()
            self.assertEqual(connection._session, "db_session")