1
- from elasticsearch_dsl import Document , Index , Text , Date , analyzer , Mapping , \
2
- exceptions
3
-
4
- from random import choice
5
1
import string
2
+ from random import choice
6
3
7
4
from pytest import raises
8
5
6
+ from elasticsearch_dsl import Date , Document , Index , IndexTemplate , Text , analyzer
7
+
8
+
9
9
class Post (Document ):
10
10
title = Text ()
11
11
published_from = Date ()
12
12
13
+
13
14
def test_multiple_doc_types_will_combine_mappings ():
14
15
class User (Document ):
15
16
username = Text ()
@@ -27,12 +28,14 @@ class User(Document):
27
28
}
28
29
} == i .to_dict ()
29
30
31
+
30
32
def test_search_is_limited_to_index_name ():
31
33
i = Index ('my-index' )
32
34
s = i .search ()
33
35
34
36
assert s ._index == ['my-index' ]
35
37
38
+
36
39
def test_cloned_index_has_copied_settings_and_using ():
37
40
client = object ()
38
41
i = Index ('my-index' , using = client )
@@ -45,6 +48,7 @@ def test_cloned_index_has_copied_settings_and_using():
45
48
assert i ._settings == i2 ._settings
46
49
assert i ._settings is not i2 ._settings
47
50
51
+
48
52
def test_cloned_index_has_analysis_attribute ():
49
53
"""
50
54
Regression test for Issue #582 in which `Index.clone()` was not copying
@@ -75,6 +79,7 @@ def test_settings_are_saved():
75
79
}
76
80
} == i .to_dict ()
77
81
82
+
78
83
def test_registered_doc_type_included_in_to_dict ():
79
84
i = Index ('i' , using = 'alias' )
80
85
i .document (Post )
@@ -88,6 +93,7 @@ def test_registered_doc_type_included_in_to_dict():
88
93
}
89
94
} == i .to_dict ()
90
95
96
+
91
97
def test_registered_doc_type_included_in_search ():
92
98
i = Index ('i' , using = 'alias' )
93
99
i .document (Post )
@@ -135,13 +141,15 @@ def test_analyzers_returned_from_to_dict():
135
141
136
142
assert index .to_dict ()["settings" ]["analysis" ]["analyzer" ][random_analyzer_name ] == {"filter" : ["standard" ], "type" : "custom" , "tokenizer" : "standard" }
137
143
144
+
138
145
def test_conflicting_analyzer_raises_error ():
139
146
i = Index ('i' )
140
147
i .analyzer ('my_analyzer' , tokenizer = 'whitespace' , filter = ['lowercase' , 'stop' ])
141
148
142
149
with raises (ValueError ):
143
150
i .analyzer ('my_analyzer' , tokenizer = 'keyword' , filter = ['lowercase' , 'stop' ])
144
151
152
+
145
153
def test_index_template_can_have_order ():
146
154
i = Index ('i-*' )
147
155
it = i .as_template ('i' , order = 2 )
@@ -150,3 +158,9 @@ def test_index_template_can_have_order():
150
158
"index_patterns" : ["i-*" ],
151
159
"order" : 2
152
160
} == it .to_dict ()
161
+
162
+
163
+ def test_index_template_save_result (mock_client ):
164
+ it = IndexTemplate ('test-template' , 'test-*' )
165
+
166
+ assert it .save (using = 'mock' ) == mock_client .indices .put_template ()
0 commit comments