Skip to content

Commit 97019ce

Browse files
committed
[python] move integration tests to REST tests
We can keep only unit tests in plugins instead of starting each time a local node and running tests against it. Also follow up of elastic#12091
1 parent c99bc81 commit 97019ce

File tree

3 files changed

+399
-313
lines changed

3 files changed

+399
-313
lines changed
Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
# Integration tests for Lang Python components
2+
#
3+
"Python Query":
4+
- do:
5+
index:
6+
index: test
7+
type: test
8+
id: 1
9+
body: { "test": "value beck", "num1": 1.0 }
10+
- do:
11+
index:
12+
index: test
13+
type: test
14+
id: 2
15+
body: { "test": "value beck", "num1": 2.0 }
16+
- do:
17+
index:
18+
index: test
19+
type: test
20+
id: 3
21+
body: { "test": "value beck", "num1": 3.0 }
22+
- do:
23+
indices.refresh: {}
24+
25+
- do:
26+
index: test
27+
search:
28+
body:
29+
query:
30+
script:
31+
script:
32+
inline: "doc['num1'].value > 1"
33+
lang: python
34+
script_fields:
35+
sNum1:
36+
lang: python
37+
script: "doc['num1'].value"
38+
sort:
39+
num1:
40+
order: asc
41+
42+
- match: { hits.total: 2 }
43+
- match: { hits.hits.0.fields.sNum1.0: 2.0 }
44+
- match: { hits.hits.1.fields.sNum1.0: 3.0 }
45+
46+
- do:
47+
index: test
48+
search:
49+
body:
50+
query:
51+
script:
52+
script:
53+
inline: "doc['num1'].value > param1"
54+
lang: python
55+
params:
56+
param1: 1
57+
58+
script_fields:
59+
sNum1:
60+
lang: python
61+
script: "doc['num1'].value"
62+
sort:
63+
num1:
64+
order: asc
65+
66+
- match: { hits.total: 2 }
67+
- match: { hits.hits.0.fields.sNum1.0: 2.0 }
68+
- match: { hits.hits.1.fields.sNum1.0: 3.0 }
69+
70+
- do:
71+
index: test
72+
search:
73+
body:
74+
query:
75+
script:
76+
script:
77+
inline: "doc['num1'].value > param1"
78+
lang: python
79+
params:
80+
param1: -1
81+
82+
script_fields:
83+
sNum1:
84+
lang: python
85+
script: "doc['num1'].value"
86+
sort:
87+
num1:
88+
order: asc
89+
90+
- match: { hits.total: 3 }
91+
- match: { hits.hits.0.fields.sNum1.0: 1.0 }
92+
- match: { hits.hits.1.fields.sNum1.0: 2.0 }
93+
- match: { hits.hits.2.fields.sNum1.0: 3.0 }
94+
95+
96+
---
97+
98+
"Python Script Field Using Source":
99+
- do:
100+
index:
101+
index: test
102+
type: test
103+
id: 1
104+
body: {
105+
"obj1": {
106+
"test": "something"
107+
},
108+
"obj2": {
109+
"arr2": [ "arr_value1", "arr_value2" ]
110+
}
111+
}
112+
- do:
113+
indices.refresh: {}
114+
115+
- do:
116+
index: test
117+
search:
118+
body:
119+
script_fields:
120+
s_obj1:
121+
lang: python
122+
script: "_source['obj1']"
123+
s_obj1_test:
124+
lang: python
125+
script: "_source['obj1']['test']"
126+
s_obj2:
127+
lang: python
128+
script: "_source['obj2']"
129+
s_obj2_arr2:
130+
lang: python
131+
script: "_source['obj2']['arr2']"
132+
133+
- match: { hits.total: 1 }
134+
- match: { hits.hits.0.fields.s_obj1.0.test: something }
135+
- match: { hits.hits.0.fields.s_obj1_test.0: something }
136+
- match: { hits.hits.0.fields.s_obj2.0.arr2.0: arr_value1 }
137+
- match: { hits.hits.0.fields.s_obj2.0.arr2.1: arr_value2 }
138+
- match: { hits.hits.0.fields.s_obj2_arr2.0: arr_value1 }
139+
- match: { hits.hits.0.fields.s_obj2_arr2.1: arr_value2 }
140+
141+
---
142+
143+
"Python Custom Script Boost":
144+
- do:
145+
index:
146+
index: test
147+
type: test
148+
id: 1
149+
body: { "test": "value beck", "num1": 1.0 }
150+
- do:
151+
index:
152+
index: test
153+
type: test
154+
id: 2
155+
body: { "test": "value beck", "num1": 2.0 }
156+
- do:
157+
indices.refresh: {}
158+
159+
- do:
160+
index: test
161+
search:
162+
body:
163+
query:
164+
function_score:
165+
query:
166+
term:
167+
test: value
168+
"functions": [{
169+
"script_score": {
170+
"script": {
171+
"lang": "python",
172+
"inline": "doc['num1'].value"
173+
}
174+
}
175+
}]
176+
177+
- match: { hits.total: 2 }
178+
- match: { hits.hits.0._id: "2" }
179+
- match: { hits.hits.1._id: "1" }
180+
181+
- do:
182+
index: test
183+
search:
184+
body:
185+
query:
186+
function_score:
187+
query:
188+
term:
189+
test: value
190+
"functions": [{
191+
"script_score": {
192+
"script": {
193+
"lang": "python",
194+
"inline": "-doc['num1'].value"
195+
}
196+
}
197+
}]
198+
199+
- match: { hits.total: 2 }
200+
- match: { hits.hits.0._id: "1" }
201+
- match: { hits.hits.1._id: "2" }
202+
203+
- do:
204+
index: test
205+
search:
206+
body:
207+
query:
208+
function_score:
209+
query:
210+
term:
211+
test: value
212+
"functions": [{
213+
"script_score": {
214+
"script": {
215+
"lang": "python",
216+
"inline": "doc['num1'].value * _score.doubleValue()"
217+
}
218+
}
219+
}]
220+
221+
- match: { hits.total: 2 }
222+
- match: { hits.hits.0._id: "2" }
223+
- match: { hits.hits.1._id: "1" }
224+
225+
- do:
226+
index: test
227+
search:
228+
body:
229+
query:
230+
function_score:
231+
query:
232+
term:
233+
test: value
234+
"functions": [{
235+
"script_score": {
236+
"script": {
237+
"lang": "python",
238+
"inline": "param1 * param2 * _score.doubleValue()",
239+
"params": {
240+
"param1": 2,
241+
"param2": 2
242+
243+
}
244+
}
245+
}
246+
}]
247+
248+
- match: { hits.total: 2 }
249+
250+
---
251+
252+
"Python Scores Nested":
253+
- do:
254+
index:
255+
index: test
256+
type: test
257+
id: 1
258+
body: { "dummy_field": 1 }
259+
- do:
260+
indices.refresh: {}
261+
262+
- do:
263+
index: test
264+
search:
265+
body:
266+
query:
267+
function_score:
268+
query:
269+
function_score:
270+
"functions": [
271+
{
272+
"script_score": {
273+
"script": {
274+
"lang": "python",
275+
"inline": "1"
276+
}
277+
}
278+
}, {
279+
"script_score": {
280+
"script": {
281+
"lang": "python",
282+
"inline": "_score.doubleValue()"
283+
}
284+
}
285+
}
286+
]
287+
"functions": [{
288+
"script_score": {
289+
"script": {
290+
"lang": "python",
291+
"inline": "_score.doubleValue()"
292+
}
293+
}
294+
}]
295+
296+
- match: { hits.total: 1 }
297+
- match: { hits.hits.0._score: 1.0 }
298+
299+
300+
---
301+
302+
"Python Scores With Agg":
303+
- do:
304+
index:
305+
index: test
306+
type: test
307+
id: 1
308+
body: { "dummy_field": 1 }
309+
- do:
310+
indices.refresh: {}
311+
312+
313+
- do:
314+
index: test
315+
search:
316+
body:
317+
query:
318+
function_score:
319+
"functions": [{
320+
"script_score": {
321+
"script": {
322+
"lang": "python",
323+
"inline": "_score.doubleValue()"
324+
}
325+
}
326+
}]
327+
aggs:
328+
score_agg:
329+
terms:
330+
script:
331+
lang: python
332+
inline: "_score.doubleValue()"
333+
334+
- match: { hits.total: 1 }
335+
- match: { hits.hits.0._score: 1.0 }
336+
- match: { aggregations.score_agg.buckets.0.key: "1.0" }
337+
- match: { aggregations.score_agg.buckets.0.doc_count: 1 }
338+

0 commit comments

Comments
 (0)