@@ -42,17 +42,19 @@ def wrapped_func_default(self, *args, **kwargs):
42
42
def wrapped_func_body_name (self , * args , ** kwargs ):
43
43
self .calls .append ((args , kwargs ))
44
44
45
- @_rewrite_parameters (body_fields = True )
45
+ @_rewrite_parameters (body_fields = ( "query" , "source" ) )
46
46
def wrapped_func_body_fields (self , * args , ** kwargs ):
47
47
self .calls .append ((args , kwargs ))
48
48
49
49
@_rewrite_parameters (
50
- body_fields = True , ignore_deprecated_options = {"api_key" , "body" , "params" }
50
+ body_fields = ( "query" ,) , ignore_deprecated_options = {"api_key" , "body" , "params" }
51
51
)
52
52
def wrapped_func_ignore (self , * args , ** kwargs ):
53
53
self .calls .append ((args , kwargs ))
54
54
55
- @_rewrite_parameters (body_fields = True , parameter_aliases = {"_source" : "source" })
55
+ @_rewrite_parameters (
56
+ body_fields = ("source" ,), parameter_aliases = {"_source" : "source" }
57
+ )
56
58
def wrapped_func_aliases (self , * args , ** kwargs ):
57
59
self .calls .append ((args , kwargs ))
58
60
@@ -81,6 +83,16 @@ def test_default(self):
81
83
((), {"query" : {"match_all" : {}}, "key" : "value" }),
82
84
]
83
85
86
+ def test_default_params_conflict (self ):
87
+ with pytest .raises (ValueError ) as e :
88
+ self .wrapped_func_default (
89
+ query = {"match_all" : {}},
90
+ params = {"query" : {"match_all" : {}}},
91
+ )
92
+ assert str (e .value ) == (
93
+ "Received multiple values for 'query', specify parameters directly instead of using 'params'"
94
+ )
95
+
84
96
def test_body_name_using_body (self ):
85
97
with warnings .catch_warnings (record = True ) as w :
86
98
self .wrapped_func_body_name (
@@ -167,6 +179,25 @@ def test_error_on_params_merge(self, params):
167
179
"using 'params' use individual API parameters"
168
180
)
169
181
182
+ def test_body_fields_merge (self ):
183
+ with warnings .catch_warnings (record = True ) as w :
184
+ self .wrapped_func_body_fields (source = False , body = {"query" : {}})
185
+
186
+ assert len (w ) == 1
187
+ assert w [0 ].category == DeprecationWarning
188
+ assert str (w [0 ].message ) == (
189
+ f"Received 'source' via a specific parameter in the presence of a "
190
+ "'body' parameter, which is deprecated and will be removed in a future "
191
+ "version. Instead, use only 'body' or only specific paremeters."
192
+ )
193
+
194
+ def test_body_fields_conflict (self ):
195
+ with pytest .raises (ValueError ) as e :
196
+ self .wrapped_func_body_fields (query = {"match_all" : {}}, body = {"query" : {}})
197
+ assert str (e .value ) == (
198
+ "Received multiple values for 'query', specify parameters using either body or parameters, not both."
199
+ )
200
+
170
201
def test_ignore_deprecated_options (self ):
171
202
with warnings .catch_warnings (record = True ) as w :
172
203
self .wrapped_func_ignore (
0 commit comments