def test_properties(self):
        """positive tests"""
        defer = False
        timeout = timedelta(seconds=10)

        crp = ClientRequestProperties()
        crp.set_option(
            ClientRequestProperties.
            results_defer_partial_query_failures_option_name, defer)
        crp.set_option(ClientRequestProperties.request_timeout_option_name,
                       timeout)

        result = crp.to_json()

        assert '"{0}": false'.format(
            crp.results_defer_partial_query_failures_option_name) in result
        assert '"{0}": "0:00:10"'.format(
            ClientRequestProperties.request_timeout_option_name) in result

        assert crp.client_request_id is None
        assert crp.application is None
        assert crp.user is None

        crp.client_request_id = "CRID"
        assert crp.client_request_id == "CRID"

        crp.application = "myApp"
        assert crp.application == "myApp"

        crp.user = "******"
        assert crp.user == "myUser"
Example #2
0
 def test_custom_request_id(self, mock_post, method):
     """Test query V2."""
     client = KustoClient(self.HOST)
     properties = ClientRequestProperties()
     request_id = "test_request_id"
     properties.client_request_id = request_id
     response = method.__call__(client,
                                "PythonTest",
                                "Deft",
                                properties=properties)
     self._assert_sanity_query_response(response)
     self._assert_client_request_id(mock_post.call_args.kwargs,
                                    value=request_id)
Example #3
0
    def _ingest_from_stream_with_client_request_id(
        self, stream_descriptor: Union[StreamDescriptor, IO[AnyStr]], ingestion_properties: IngestionProperties, client_request_id: Optional[str]
    ) -> IngestionResult:
        stream_descriptor = BaseIngestClient._prepare_stream(stream_descriptor, ingestion_properties)
        additional_properties = None
        if client_request_id:
            additional_properties = ClientRequestProperties()
            additional_properties.client_request_id = client_request_id

        self._kusto_client.execute_streaming_ingest(
            ingestion_properties.database,
            ingestion_properties.table,
            stream_descriptor.stream,
            ingestion_properties.format.name,
            additional_properties,
            mapping_name=ingestion_properties.ingestion_mapping_reference,
        )

        return IngestionResult(IngestionStatus.SUCCESS, ingestion_properties.database, ingestion_properties.table, stream_descriptor.source_id)
Example #4
0
        def create_client_request_properties(
                cls,
                scope: str,
                timeout: str = None) -> ClientRequestProperties:
            """
            Creates a fitting ClientRequestProperties object, to be used when executing control commands or queries.
            :param scope: Working scope
            :param timeout: Requests default timeout
            :return: ClientRequestProperties object
            """
            client_request_properties = ClientRequestProperties()
            client_request_properties.client_request_id = f"{scope};{str(uuid.uuid4())}"
            client_request_properties.application = "sample_app.py"

            # Tip: Though uncommon, you can alter the request default command timeout using the below command, e.g. to set the timeout to 10 minutes, use "10m"
            if timeout:
                client_request_properties.set_option(
                    ClientRequestProperties.request_timeout_option_name,
                    timeout)

            return client_request_properties