コード例 #1
0
    def test_valid_asynchronous_args(self):
        mock_execute = MagicMock(return_value={})
        mock_execute_async = MagicMock(return_value={})
        mock_context = {
            "cassandra_cql_returner_cluster": MagicMock(return_value={}),
            "cassandra_cql_returner_session": MagicMock(
                execute=mock_execute,
                execute_async=mock_execute_async,
                prepare=lambda _: MagicMock(
                    bind=lambda _: None
                ),  # mock prepared_statement
                row_factory=None,
            ),
            "cassandra_cql_prepared": {},
        }

        with patch.dict(cassandra_cql.__context__, mock_context):
            cassandra_cql.cql_query_with_prepare(
                "SELECT now() from system.local;", "select_now", [], asynchronous=True
            )
            self.assert_called_once(mock_execute_async)
コード例 #2
0
    def test_valid_async_args(self):
        mock_execute = MagicMock(return_value={})
        mock_execute_async = MagicMock(return_value={})
        mock_context = {
            "cassandra_cql_returner_cluster":
            MagicMock(return_value={}),
            "cassandra_cql_returner_session":
            MagicMock(
                execute=mock_execute,
                execute_async=mock_execute_async,
                prepare=lambda _: MagicMock(bind=lambda _: None),
                # mock prepared_statement
                row_factory=None,
            ),
            "cassandra_cql_prepared": {},
        }

        kwargs = {"async": True}  # to avoid syntax error in python 3.7
        with patch.dict(cassandra_cql.__context__, mock_context):
            cassandra_cql.cql_query_with_prepare(
                "SELECT now() from system.local;", "select_now", [], **kwargs)
            mock_execute_async.assert_called_once()