20
20
from elasticsearch import Elasticsearch
21
21
from test_elasticsearch .test_cases import DummyTransportTestCase
22
22
23
+ EXPECTED_SERIALIZERS = {
24
+ "application/json" ,
25
+ "text/*" ,
26
+ "application/x-ndjson" ,
27
+ "application/vnd.mapbox-vector-tile" ,
28
+ "application/vnd.elasticsearch+json" ,
29
+ "application/vnd.elasticsearch+x-ndjson" ,
30
+ }
31
+
32
+
33
+ try :
34
+ import pyarrow as pa
35
+
36
+ EXPECTED_SERIALIZERS .add ("application/vnd.apache.arrow.stream" )
37
+ except ImportError :
38
+ pa = None
39
+
23
40
24
41
class TestSerializers (DummyTransportTestCase ):
25
42
def test_compat_mode_on_by_default (self ):
@@ -90,16 +107,8 @@ class CustomSerializer:
90
107
"https://localhost:9200" , serializers = {f"application/{ mime_subtype } " : ser }
91
108
)
92
109
serializers = client .transport .serializers .serializers
93
- assert set (serializers .keys ()) == {
94
- "application/json" ,
95
- "text/*" ,
96
- "application/x-ndjson" ,
97
- "application/vnd.apache.arrow.stream" ,
98
- "application/vnd.mapbox-vector-tile" ,
99
- "application/vnd.elasticsearch+json" ,
100
- "application/vnd.elasticsearch+x-ndjson" ,
101
- }
102
110
111
+ assert set (serializers .keys ()) == EXPECTED_SERIALIZERS
103
112
assert serializers [f"application/{ mime_subtype } " ] is ser
104
113
assert serializers [f"application/vnd.elasticsearch+{ mime_subtype } " ] is ser
105
114
@@ -118,16 +127,7 @@ class CustomSerializer:
118
127
},
119
128
)
120
129
serializers = client .transport .serializers .serializers
121
- assert set (serializers .keys ()) == {
122
- "application/json" ,
123
- "text/*" ,
124
- "application/x-ndjson" ,
125
- "application/vnd.apache.arrow.stream" ,
126
- "application/vnd.mapbox-vector-tile" ,
127
- "application/vnd.elasticsearch+json" ,
128
- "application/vnd.elasticsearch+x-ndjson" ,
129
- }
130
-
130
+ assert set (serializers .keys ()) == EXPECTED_SERIALIZERS
131
131
assert serializers [f"application/{ mime_subtype } " ] is ser1
132
132
assert serializers [f"application/vnd.elasticsearch+{ mime_subtype } " ] is ser2
133
133
@@ -138,15 +138,6 @@ class CustomSerializer:
138
138
ser = CustomSerializer ()
139
139
client = Elasticsearch ("https://localhost:9200" , serializer = ser )
140
140
serializers = client .transport .serializers .serializers
141
- assert set (serializers .keys ()) == {
142
- "application/json" ,
143
- "text/*" ,
144
- "application/x-ndjson" ,
145
- "application/vnd.apache.arrow.stream" ,
146
- "application/vnd.mapbox-vector-tile" ,
147
- "application/vnd.elasticsearch+json" ,
148
- "application/vnd.elasticsearch+x-ndjson" ,
149
- }
150
-
141
+ assert set (serializers .keys ()) == EXPECTED_SERIALIZERS
151
142
assert serializers ["application/json" ] is ser
152
143
assert serializers ["application/vnd.elasticsearch+json" ] is ser
0 commit comments