@@ -137,24 +137,23 @@ def test_missing_var(self):
137137 """Check for a missing fact"""
138138 self ._plugin ._task .args = {"updates" : [{"path" : "a.b.c" , "value" : 5 }]}
139139 with self .assertRaises (Exception ) as error :
140- self ._plugin .run (task_vars = {"vars" : {} })
140+ self ._plugin .run (task_vars = {})
141141 self .assertIn ("'a' was not found in the current facts." , str (error .exception ))
142142
143143 def test_run_simple (self ):
144144 """Confirm a valid argspec passes"""
145- task_vars = {"vars" : { " a" : {"b" : [1 , 2 , 3 ]} }}
146- expected = copy .deepcopy (task_vars [ "vars" ] )
145+ task_vars = {"a" : {"b" : [1 , 2 , 3 ]}}
146+ expected = copy .deepcopy (task_vars )
147147 expected ["a" ]["b" ] = 5
148- expected . update ({ "changed" : True })
148+ expected [ "changed" ] = True
149149 self ._plugin ._task .args = {"updates" : [{"path" : "a.b" , "value" : 5 }]}
150150 result = self ._plugin .run (task_vars = task_vars )
151151 self .assertEqual (result , expected )
152152
153153 def test_run_multiple (self ):
154154 """Confirm multiple paths passes"""
155- task_vars = {"vars" : {"a" : {"b1" : [1 , 2 , 3 ], "b2" : {"c" : "123" , "d" : False }}}}
156- expected = {"a" : {"b1" : [1 , 2 , 3 , 4 ], "b2" : {"c" : 456 , "d" : True }}}
157- expected .update ({"changed" : True })
155+ task_vars = {"a" : {"b1" : [1 , 2 , 3 ], "b2" : {"c" : "123" , "d" : False }}}
156+ expected = {"a" : {"b1" : [1 , 2 , 3 , 4 ], "b2" : {"c" : 456 , "d" : True }}, "changed" : True }
158157 self ._plugin ._task .args = {
159158 "updates" : [
160159 {"path" : "a.b1.3" , "value" : 4 },
@@ -167,60 +166,60 @@ def test_run_multiple(self):
167166
168167 def test_run_replace_in_list (self ):
169168 """Replace in list"""
170- task_vars = {"vars" : { " a" : {"b" : [1 , 2 , 3 ]} }}
171- expected = copy .deepcopy (task_vars [ "vars" ] )
169+ task_vars = {"a" : {"b" : [1 , 2 , 3 ]}}
170+ expected = copy .deepcopy (task_vars )
172171 expected ["a" ]["b" ][1 ] = 5
173- expected . update ({ "changed" : True })
172+ expected [ "changed" ] = True
174173 self ._plugin ._task .args = {"updates" : [{"path" : "a.b.1" , "value" : 5 }]}
175174 result = self ._plugin .run (task_vars = task_vars )
176175 self .assertEqual (result , expected )
177176
178177 def test_run_append_to_list (self ):
179178 """Append to list"""
180- task_vars = {"vars" : { " a" : {"b" : [1 , 2 , 3 ]} }}
181- expected = copy .deepcopy (task_vars [ "vars" ] )
179+ task_vars = {"a" : {"b" : [1 , 2 , 3 ]}}
180+ expected = copy .deepcopy (task_vars )
182181 expected ["a" ]["b" ].append (4 )
183- expected . update ({ "changed" : True })
182+ expected [ "changed" ] = True
184183 self ._plugin ._task .args = {"updates" : [{"path" : "a.b.3" , "value" : 4 }]}
185184 result = self ._plugin .run (task_vars = task_vars )
186185 self .assertEqual (result , expected )
187186
188187 def test_run_bracket_single_quote (self ):
189188 """Bracket notation sigle quote"""
190- task_vars = {"vars" : { " a" : {"b" : [1 , 2 , 3 ]} }}
191- expected = copy .deepcopy (task_vars [ "vars" ] )
189+ task_vars = {"a" : {"b" : [1 , 2 , 3 ]}}
190+ expected = copy .deepcopy (task_vars )
192191 expected ["a" ]["b" ].append (4 )
193- expected . update ({ "changed" : True })
192+ expected [ "changed" ] = True
194193 self ._plugin ._task .args = {"updates" : [{"path" : "a['b'][3]" , "value" : 4 }]}
195194 result = self ._plugin .run (task_vars = task_vars )
196195 self .assertEqual (result , expected )
197196
198197 def test_run_bracket_double_quote (self ):
199198 """Bracket notation double quote"""
200- task_vars = {"vars" : { " a" : {"b" : [1 , 2 , 3 ]} }}
201- expected = copy .deepcopy (task_vars [ "vars" ] )
199+ task_vars = {"a" : {"b" : [1 , 2 , 3 ]}}
200+ expected = copy .deepcopy (task_vars )
202201 expected ["a" ]["b" ].append (4 )
203- expected . update ({ "changed" : True })
202+ expected [ "changed" ] = True
204203 self ._plugin ._task .args = {"updates" : [{"path" : 'a["b"][3]' , "value" : 4 }]}
205204 result = self ._plugin .run (task_vars = task_vars )
206205 self .assertEqual (result , expected )
207206
208207 def test_run_int_dict_keys (self ):
209208 """Integer dict keys"""
210- task_vars = {"vars" : { " a" : {0 : [1 , 2 , 3 ]} }}
211- expected = copy .deepcopy (task_vars [ "vars" ] )
209+ task_vars = {"a" : {0 : [1 , 2 , 3 ]}}
210+ expected = copy .deepcopy (task_vars )
212211 expected ["a" ][0 ][0 ] = 0
213- expected . update ({ "changed" : True })
212+ expected [ "changed" ] = True
214213 self ._plugin ._task .args = {"updates" : [{"path" : "a.0.0" , "value" : 0 }]}
215214 result = self ._plugin .run (task_vars = task_vars )
216215 self .assertEqual (result , expected )
217216
218217 def test_run_int_as_string (self ):
219218 """Integer dict keys as string"""
220- task_vars = {"vars" : { " a" : {"0" : [1 , 2 , 3 ]} }}
221- expected = copy .deepcopy (task_vars [ "vars" ] )
219+ task_vars = {"a" : {"0" : [1 , 2 , 3 ]}}
220+ expected = copy .deepcopy (task_vars )
222221 expected ["a" ]["0" ][0 ] = 0
223- expected . update ({ "changed" : True })
222+ expected [ "changed" ] = True
224223 self ._plugin ._task .args = {"updates" : [{"path" : 'a["0"].0' , "value" : 0 }]}
225224 result = self ._plugin .run (task_vars = task_vars )
226225 self .assertEqual (result , expected )
@@ -229,62 +228,60 @@ def test_run_invalid_path_quote_after_dot(self):
229228 """Invalid path format"""
230229 self ._plugin ._task .args = {"updates" : [{"path" : "a.'b'" , "value" : 0 }]}
231230 with self .assertRaises (Exception ) as error :
232- self ._plugin .run (task_vars = {"vars" : {} })
231+ self ._plugin .run (task_vars = {})
233232 self .assertIn ("malformed" , str (error .exception ))
234233
235234 def test_run_invalid_path_bracket_after_dot (self ):
236235 """Invalid path format"""
237236 self ._plugin ._task .args = {"updates" : [{"path" : "a.['b']" , "value" : 0 }]}
238237 with self .assertRaises (Exception ) as error :
239- self ._plugin .run (task_vars = {"vars" : {} })
238+ self ._plugin .run (task_vars = {})
240239 self .assertIn ("malformed" , str (error .exception ))
241240
242241 def test_run_invalid_key_start_with_dot (self ):
243242 """Invalid key format"""
244243 self ._plugin ._task .args = {"updates" : [{"path" : ".abc" , "value" : 0 }]}
245244 with self .assertRaises (Exception ) as error :
246- self ._plugin .run (task_vars = {"vars" : {} })
245+ self ._plugin .run (task_vars = {})
247246 self .assertIn ("malformed" , str (error .exception ))
248247
249248 def test_run_no_update_list (self ):
250249 """Confirm no change when same"""
251- task_vars = {"vars" : {"a" : {"b" : [1 , 2 , 3 ]}}}
252- expected = copy .deepcopy (task_vars ["vars" ])
253- expected ["a" ]["b" ] = [1 , 2 , 3 ]
254- expected .update ({"changed" : False })
250+ task_vars = {"a" : {"b" : [1 , 2 , 3 ]}}
251+ expected = copy .deepcopy (task_vars )
252+ expected ["changed" ] = False
255253 self ._plugin ._task .args = {"updates" : [{"path" : "a.b.0" , "value" : 1 }]}
256254 result = self ._plugin .run (task_vars = task_vars )
257255 self .assertEqual (result , expected )
258256
259257 def test_run_no_update_dict (self ):
260258 """Confirm no change when same"""
261- task_vars = {"vars" : {"a" : {"b" : [1 , 2 , 3 ]}}}
262- expected = copy .deepcopy (task_vars ["vars" ])
263- expected ["a" ]["b" ] = [1 , 2 , 3 ]
264- expected .update ({"changed" : False })
259+ task_vars = {"a" : {"b" : [1 , 2 , 3 ]}}
260+ expected = copy .deepcopy (task_vars )
261+ expected ["changed" ] = False
265262 self ._plugin ._task .args = {"updates" : [{"path" : "a.b" , "value" : [1 , 2 , 3 ]}]}
266263 result = self ._plugin .run (task_vars = task_vars )
267264 self .assertEqual (result , expected )
268265
269266 def test_run_missing_key (self ):
270267 """Confirm error when key not found"""
271- task_vars = {"vars" : { " a" : {"b" : 1 } }}
268+ task_vars = {"a" : {"b" : 1 }}
272269 self ._plugin ._task .args = {"updates" : [{"path" : "a.c.d" , "value" : 1 }]}
273270 with self .assertRaises (Exception ) as error :
274271 self ._plugin .run (task_vars = task_vars )
275272 self .assertIn ("the key 'c' was not found" , str (error .exception ))
276273
277274 def test_run_list_not_int (self ):
278275 """Confirm error when key not found"""
279- task_vars = {"vars" : { " a" : {"b" : [1 ]} }}
276+ task_vars = {"a" : {"b" : [1 ]}}
280277 self ._plugin ._task .args = {"updates" : [{"path" : "a.b['0']" , "value" : 2 }]}
281278 with self .assertRaises (Exception ) as error :
282279 self ._plugin .run (task_vars = task_vars )
283280 self .assertIn ("index provided was not an integer" , str (error .exception ))
284281
285282 def test_run_list_not_long (self ):
286283 """List not long enough"""
287- task_vars = {"vars" : { " a" : {"b" : [0 ]} }}
284+ task_vars = {"a" : {"b" : [0 ]}}
288285 self ._plugin ._task .args = {"updates" : [{"path" : "a.b.2" , "value" : 2 }]}
289286 with self .assertRaises (Exception ) as error :
290287 self ._plugin .run (task_vars = task_vars )
@@ -303,47 +300,43 @@ def test_not_mutable_sequence_or_mapping(self):
303300
304301 def test_run_not_dotted_success_one (self ):
305302 """Test with a not dotted key"""
306- task_vars = {"vars" : {"a" : 0 }}
307- expected = copy .deepcopy (task_vars ["vars" ])
308- expected ["a" ] = 1
309- expected .update ({"changed" : True })
303+ task_vars = {"a" : 0 }
304+ expected = {"a" : 1 , "ansible_facts" : {"a" : 1 }, "changed" : True }
310305 self ._plugin ._task .args = {"updates" : [{"path" : "a" , "value" : 1 }]}
311306 result = self ._plugin .run (task_vars = task_vars )
312307 self .assertEqual (result , expected )
313308
314309 def test_run_not_dotted_success_three (self ):
315310 """Test with a not dotted key longer"""
316- task_vars = {"vars" : {"abc" : 0 }}
317- expected = copy .deepcopy (task_vars ["vars" ])
318- expected ["abc" ] = 1
319- expected .update ({"changed" : True })
311+ task_vars = {"abc" : 0 }
312+ expected = {"abc" : 1 , "ansible_facts" : {"abc" : 1 }, "changed" : True }
320313 self ._plugin ._task .args = {"updates" : [{"path" : "abc" , "value" : 1 }]}
321314 result = self ._plugin .run (task_vars = task_vars )
322315 self .assertEqual (result , expected )
323316
324317 def test_run_not_dotted_fail_missing (self ):
325318 """Test with a not dotted key, missing"""
326- task_vars = {"vars" : { " abc" : 0 } }
319+ task_vars = {"abc" : 0 }
327320 self ._plugin ._task .args = {"updates" : [{"path" : "123" , "value" : 1 }]}
328321 with self .assertRaises (Exception ) as error :
329322 self ._plugin .run (task_vars = task_vars )
330323 self .assertIn ("'123' was not found in the current facts" , str (error .exception ))
331324
332325 def test_run_not_dotted_success_same (self ):
333326 """Test with a not dotted key, no change"""
334- task_vars = {"vars" : { " a" : 0 } }
335- expected = copy .deepcopy (task_vars [ "vars" ] )
336- expected . update ({ "changed" : False })
327+ task_vars = {"a" : 0 }
328+ expected = copy .deepcopy (task_vars )
329+ expected [ "changed" ] = False
337330 self ._plugin ._task .args = {"updates" : [{"path" : "a" , "value" : 0 }]}
338331 result = self ._plugin .run (task_vars = task_vars )
339332 self .assertEqual (result , expected )
340333
341334 def test_run_looks_like_a_bool (self ):
342335 """Test with a key that looks like a bool"""
343- task_vars = {"vars" : { " a" : {"True" : 0 } }}
344- expected = copy .deepcopy (task_vars [ "vars" ] )
336+ task_vars = {"a" : {"True" : 0 }}
337+ expected = copy .deepcopy (task_vars )
345338 expected ["a" ]["True" ] = 1
346- expected . update ({ "changed" : True })
339+ expected [ "changed" ] = True
347340 self ._plugin ._task .args = {"updates" : [{"path" : "a['True']" , "value" : 1 }]}
348341 result = self ._plugin .run (task_vars = task_vars )
349342 self .assertEqual (result , expected )
0 commit comments