@@ -76,6 +76,103 @@ class TestChunkActions(TestCase):
76
76
def setup_method (self , _ ):
77
77
self .actions = [({"index" : {}}, {"some" : u"datá" , "i" : i }) for i in range (100 )]
78
78
79
+ def test_expand_action (self ):
80
+ self .assertEqual (helpers .expand_action ({}), ({"index" : {}}, {}))
81
+ self .assertEqual (
82
+ helpers .expand_action ({"key" : "val" }), ({"index" : {}}, {"key" : "val" })
83
+ )
84
+
85
+ def test_expand_action_actions (self ):
86
+ self .assertEqual (
87
+ helpers .expand_action (
88
+ {"_op_type" : "delete" , "_id" : "id" , "_index" : "index" }
89
+ ),
90
+ ({"delete" : {"_id" : "id" , "_index" : "index" }}, None ),
91
+ )
92
+ self .assertEqual (
93
+ helpers .expand_action (
94
+ {"_op_type" : "update" , "_id" : "id" , "_index" : "index" , "key" : "val" }
95
+ ),
96
+ ({"update" : {"_id" : "id" , "_index" : "index" }}, {"key" : "val" }),
97
+ )
98
+ self .assertEqual (
99
+ helpers .expand_action (
100
+ {"_op_type" : "create" , "_id" : "id" , "_index" : "index" , "key" : "val" }
101
+ ),
102
+ ({"create" : {"_id" : "id" , "_index" : "index" }}, {"key" : "val" }),
103
+ )
104
+ self .assertEqual (
105
+ helpers .expand_action (
106
+ {
107
+ "_op_type" : "create" ,
108
+ "_id" : "id" ,
109
+ "_index" : "index" ,
110
+ "_source" : {"key" : "val" },
111
+ }
112
+ ),
113
+ ({"create" : {"_id" : "id" , "_index" : "index" }}, {"key" : "val" }),
114
+ )
115
+
116
+ def test_expand_action_options (self ):
117
+ for option in (
118
+ "_id" ,
119
+ "_index" ,
120
+ "_percolate" ,
121
+ "_timestamp" ,
122
+ "_type" ,
123
+ "if_seq_no" ,
124
+ "if_primary_term" ,
125
+ "parent" ,
126
+ "pipeline" ,
127
+ "retry_on_conflict" ,
128
+ "routing" ,
129
+ "version" ,
130
+ "version_type" ,
131
+ ("_parent" , "parent" ),
132
+ ("_retry_on_conflict" , "retry_on_conflict" ),
133
+ ("_routing" , "routing" ),
134
+ ("_version" , "version" ),
135
+ ("_version_type" , "version_type" ),
136
+ ("_if_seq_no" , "if_seq_no" ),
137
+ ("_if_primary_term" , "if_primary_term" ),
138
+ ):
139
+ if isinstance (option , str ):
140
+ action_option = option
141
+ else :
142
+ option , action_option = option
143
+ self .assertEqual (
144
+ helpers .expand_action ({"key" : "val" , option : 0 }),
145
+ ({"index" : {action_option : 0 }}, {"key" : "val" }),
146
+ )
147
+
148
+ def test__source_metadata_or_source (self ):
149
+ self .assertEqual (
150
+ helpers .expand_action ({"_source" : {"key" : "val" }}),
151
+ ({"index" : {}}, {"key" : "val" }),
152
+ )
153
+
154
+ self .assertEqual (
155
+ helpers .expand_action (
156
+ {"_source" : ["key" ], "key" : "val" , "_op_type" : "update" }
157
+ ),
158
+ ({"update" : {"_source" : ["key" ]}}, {"key" : "val" }),
159
+ )
160
+
161
+ self .assertEqual (
162
+ helpers .expand_action (
163
+ {"_source" : True , "key" : "val" , "_op_type" : "update" }
164
+ ),
165
+ ({"update" : {"_source" : True }}, {"key" : "val" }),
166
+ )
167
+
168
+ # This case is only to ensure backwards compatibility with old functionality.
169
+ self .assertEqual (
170
+ helpers .expand_action (
171
+ {"_source" : {"key2" : "val2" }, "key" : "val" , "_op_type" : "update" }
172
+ ),
173
+ ({"update" : {}}, {"key2" : "val2" }),
174
+ )
175
+
79
176
def test_chunks_are_chopped_by_byte_size (self ):
80
177
self .assertEqual (
81
178
100 ,
0 commit comments