3333from elastic_transport ._node import NodeApiResponse
3434from elastic_transport .client_utils import DEFAULT
3535
36- from elasticsearch import AsyncElasticsearch
36+ from elasticsearch import AsyncElasticsearch , __versionstr__
37+ from elasticsearch ._version import _SERVERLESS_API_VERSION
3738from elasticsearch .exceptions import (
3839 ApiError ,
3940 ConnectionError ,
@@ -781,13 +782,14 @@ async def test_default_stack_mode_sends_compat_headers(self):
781782 calls = client .transport .node_pool .get ().calls
782783 assert 1 == len (calls )
783784 headers = calls [0 ][1 ]["headers" ]
785+ compat_version = __versionstr__ .partition ("." )[0 ]
784786 assert headers ["accept" ] == (
785- "application/vnd.elasticsearch+json; compatible-with=9 "
787+ f "application/vnd.elasticsearch+json; compatible-with={ compat_version } "
786788 )
787789 assert "elastic-api-version" not in headers
788790
789791 @pytest .mark .anyio
790- async def test_serverless_mode_sends_api_version_header (self ):
792+ async def test_serverless_mode_sends_api_version_header_on_get (self ):
791793 client = AsyncElasticsearch (
792794 "http://localhost:9200" ,
793795 meta_header = False ,
@@ -799,11 +801,11 @@ async def test_serverless_mode_sends_api_version_header(self):
799801 calls = client .transport .node_pool .get ().calls
800802 assert 1 == len (calls )
801803 headers = calls [0 ][1 ]["headers" ]
802- assert headers ["elastic-api-version" ] == "2023-10-31"
804+ assert headers ["elastic-api-version" ] == _SERVERLESS_API_VERSION
803805 assert headers ["accept" ] == "application/json"
804806
805807 @pytest .mark .anyio
806- async def test_serverless_mode_does_not_send_compat_headers (self ):
808+ async def test_serverless_mode_sends_plain_headers_on_post (self ):
807809 client = AsyncElasticsearch (
808810 "http://localhost:9200" ,
809811 meta_header = False ,
@@ -815,7 +817,7 @@ async def test_serverless_mode_does_not_send_compat_headers(self):
815817 calls = client .transport .node_pool .get ().calls
816818 assert 1 == len (calls )
817819 headers = calls [0 ][1 ]["headers" ]
818- assert headers ["elastic-api-version" ] == "2023-10-31"
820+ assert headers ["elastic-api-version" ] == _SERVERLESS_API_VERSION
819821 assert headers ["accept" ] == "application/json"
820822 assert headers ["content-type" ] == "application/json"
821823 assert "compatible-with" not in headers .get ("accept" , "" )
@@ -855,5 +857,16 @@ async def test_serverless_mode_preserved_in_options(self):
855857 calls = client2 .transport .node_pool .get ().calls
856858 assert 1 == len (calls )
857859 headers = calls [0 ][1 ]["headers" ]
858- assert headers ["elastic-api-version" ] == "2023-10-31"
860+ assert headers ["elastic-api-version" ] == _SERVERLESS_API_VERSION
859861 assert "compatible-with" not in headers .get ("accept" , "" )
862+
863+ @pytest .mark .anyio
864+ async def test_serverless_mode_inherited_by_namespaces (self ):
865+ client = AsyncElasticsearch (
866+ "http://localhost:9200" ,
867+ meta_header = False ,
868+ node_class = DummyNode ,
869+ server_mode = "serverless" ,
870+ )
871+ assert client ._is_serverless is True
872+ assert client .indices ._is_serverless is True
0 commit comments