@@ -211,7 +211,7 @@ def test_inspecting_by_name_not_found(
211
211
)
212
212
213
213
214
- def test_inspecting_in_json (
214
+ def test_inspecting_by_name_in_json (
215
215
various_automations : List [Automation ], read_automations_by_name : mock .AsyncMock
216
216
):
217
217
read_automations_by_name .return_value = [various_automations [0 ]]
@@ -223,7 +223,26 @@ def test_inspecting_in_json(
223
223
assert loaded [0 ]["id" ] == "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
224
224
225
225
226
- def test_inspecting_in_yaml (
226
+ def test_inspecting_by_id_in_json (
227
+ various_automations : List [Automation ], read_automation : mock .AsyncMock
228
+ ):
229
+ read_automation .return_value = various_automations [1 ]
230
+ result = invoke_and_assert (
231
+ [
232
+ "automations" ,
233
+ "inspect" ,
234
+ "--id" ,
235
+ "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" ,
236
+ "--json" ,
237
+ ],
238
+ expected_code = 0 ,
239
+ )
240
+ loaded = orjson .loads (result .output )
241
+ assert loaded ["name" ] == "My Other Reactive Automation"
242
+ assert loaded ["id" ] == "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
243
+
244
+
245
+ def test_inspecting_by_name_in_yaml (
227
246
various_automations : List [Automation ], read_automations_by_name : mock .AsyncMock
228
247
):
229
248
read_automations_by_name .return_value = [various_automations [0 ]]
@@ -235,6 +254,25 @@ def test_inspecting_in_yaml(
235
254
assert loaded [0 ]["id" ] == "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
236
255
237
256
257
+ def test_inspecting_by_id_in_yaml (
258
+ various_automations : List [Automation ], read_automation : mock .AsyncMock
259
+ ):
260
+ read_automation .return_value = various_automations [1 ]
261
+ result = invoke_and_assert (
262
+ [
263
+ "automations" ,
264
+ "inspect" ,
265
+ "--id" ,
266
+ "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" ,
267
+ "--yaml" ,
268
+ ],
269
+ expected_code = 0 ,
270
+ )
271
+ loaded = yaml .safe_load (result .output )
272
+ assert loaded ["name" ] == "My Other Reactive Automation"
273
+ assert loaded ["id" ] == "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
274
+
275
+
238
276
@pytest .fixture
239
277
def pause_automation () -> Generator [mock .AsyncMock , None , None ]:
240
278
with mock .patch (
@@ -244,26 +282,69 @@ def pause_automation() -> Generator[mock.AsyncMock, None, None]:
244
282
245
283
246
284
def test_pausing_by_name (
247
- pause_automation : mock .AsyncMock , various_automations : List [Automation ]
285
+ pause_automation : mock .AsyncMock ,
286
+ various_automations : List [Automation ],
287
+ read_automations_by_name : mock .AsyncMock ,
248
288
):
289
+ read_automations_by_name .return_value = [various_automations [0 ]]
249
290
invoke_and_assert (
250
291
["automations" , "pause" , "My First Reactive" ],
251
292
expected_code = 0 ,
252
- expected_output_contains = ["Paused automation 'My First Reactive'" ],
293
+ expected_output_contains = [
294
+ "Paused automation(s) with name 'My First Reactive' and id(s) 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'"
295
+ ],
253
296
)
254
297
255
298
pause_automation .assert_awaited_once_with (
256
299
mock .ANY , UUID ("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" )
257
300
)
258
301
259
302
260
- def test_pausing_not_found (
261
- pause_automation : mock .AsyncMock , various_automations : List [Automation ]
303
+ def test_pausing_by_name_not_found (
304
+ pause_automation : mock .AsyncMock ,
305
+ various_automations : List [Automation ],
306
+ read_automations_by_name : mock .AsyncMock ,
262
307
):
308
+ read_automations_by_name .return_value = None
263
309
invoke_and_assert (
264
310
["automations" , "pause" , "Wha?" ],
265
311
expected_code = 1 ,
266
- expected_output_contains = ["Automation 'Wha?' not found" ],
312
+ expected_output_contains = ["Automation with name 'Wha?' not found" ],
313
+ )
314
+
315
+ pause_automation .assert_not_awaited ()
316
+
317
+
318
+ def test_pausing_by_id (
319
+ pause_automation : mock .AsyncMock ,
320
+ various_automations : List [Automation ],
321
+ read_automation : mock .AsyncMock ,
322
+ ):
323
+ read_automation .return_value = various_automations [0 ]
324
+ invoke_and_assert (
325
+ ["automations" , "pause" , "--id" , "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" ],
326
+ expected_code = 0 ,
327
+ expected_output_contains = [
328
+ "Paused automation with id 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'"
329
+ ],
330
+ )
331
+
332
+ pause_automation .assert_awaited_once_with (
333
+ mock .ANY , UUID ("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" )
334
+ )
335
+
336
+
337
+ def test_pausing_by_id_not_found (
338
+ pause_automation : mock .AsyncMock ,
339
+ read_automation : mock .AsyncMock ,
340
+ ):
341
+ read_automation .return_value = None
342
+ invoke_and_assert (
343
+ ["automations" , "pause" , "--id" , "zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz" ],
344
+ expected_code = 1 ,
345
+ expected_output_contains = [
346
+ "Automation with id 'zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz' not found"
347
+ ],
267
348
)
268
349
269
350
pause_automation .assert_not_awaited ()
@@ -278,26 +359,68 @@ def resume_automation() -> Generator[mock.AsyncMock, None, None]:
278
359
279
360
280
361
def test_resuming_by_name (
281
- resume_automation : mock .AsyncMock , various_automations : List [Automation ]
362
+ resume_automation : mock .AsyncMock ,
363
+ various_automations : List [Automation ],
364
+ read_automations_by_name : mock .AsyncMock ,
282
365
):
366
+ read_automations_by_name .return_value = [various_automations [0 ]]
283
367
invoke_and_assert (
284
368
["automations" , "resume" , "My First Reactive" ],
285
369
expected_code = 0 ,
286
- expected_output_contains = ["Resumed automation 'My First Reactive'" ],
370
+ expected_output_contains = [
371
+ "Resumed automation(s) with name 'My First Reactive' and id(s) 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'"
372
+ ],
287
373
)
288
374
289
375
resume_automation .assert_awaited_once_with (
290
376
mock .ANY , UUID ("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" )
291
377
)
292
378
293
379
294
- def test_resuming_not_found (
295
- resume_automation : mock .AsyncMock , various_automations : List [Automation ]
380
+ def test_resuming_by_name_not_found (
381
+ resume_automation : mock .AsyncMock ,
382
+ various_automations : List [Automation ],
383
+ read_automations_by_name : mock .AsyncMock ,
296
384
):
385
+ read_automations_by_name .return_value = None
297
386
invoke_and_assert (
298
387
["automations" , "resume" , "Wha?" ],
299
388
expected_code = 1 ,
300
- expected_output_contains = ["Automation 'Wha?' not found" ],
389
+ expected_output_contains = ["Automation with name 'Wha?' not found" ],
390
+ )
391
+
392
+ resume_automation .assert_not_awaited ()
393
+
394
+
395
+ def test_resuming_by_id (
396
+ resume_automation : mock .AsyncMock ,
397
+ various_automations : List [Automation ],
398
+ read_automation : mock .AsyncMock ,
399
+ ):
400
+ read_automation .return_value = various_automations [0 ]
401
+ invoke_and_assert (
402
+ ["automations" , "resume" , "--id" , "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" ],
403
+ expected_code = 0 ,
404
+ expected_output_contains = [
405
+ "Resumed automation with id 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'"
406
+ ],
407
+ )
408
+
409
+ resume_automation .assert_awaited_once_with (
410
+ mock .ANY , UUID ("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" )
411
+ )
412
+
413
+
414
+ def test_resuming_by_id_not_found (
415
+ resume_automation : mock .AsyncMock , read_automation : mock .AsyncMock
416
+ ):
417
+ read_automation .return_value = None
418
+ invoke_and_assert (
419
+ ["automations" , "resume" , "--id" , "zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz" ],
420
+ expected_code = 1 ,
421
+ expected_output_contains = [
422
+ "Automation with id 'zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz' not found"
423
+ ],
301
424
)
302
425
303
426
resume_automation .assert_not_awaited ()
0 commit comments