@@ -273,3 +273,76 @@ def test_warns_when_wrong_format_provided(self, mocker, task_list):
273273 assert mock_tabulate .call_count == 0
274274 assert wrong_format not in tabulate_formats
275275 assert "Table format has to be one of" in result .stdout
276+
277+
278+ @pytest .mark .clischeduleupdate
279+ class TestUpdate :
280+ def test_enables_task_and_sets_porcelain (self , mocker ):
281+ mock_task_from_id = mocker .patch ("cli.schedule.get_task_from_id" )
282+
283+ runner .invoke (app , ["update" , "42" , "--enable" , "--porcelain" ])
284+
285+ assert mock_task_from_id .call_args == call (42 )
286+ assert mock_task_from_id .return_value .method_calls == [
287+ call .update_schedule ({"enabled" : True }, porcelain = True )
288+ ]
289+
290+ def test_turns_off_snakesay (self , mocker ):
291+ mock_logger = mocker .patch ("cli.schedule.get_logger" )
292+
293+ runner .invoke (app , ["update" , "42" , "--quiet" ])
294+
295+ assert mock_logger .return_value .setLevel .call_count == 0
296+
297+ def test_warns_when_task_update_schedule_raises (self , mocker ):
298+ mock_logger = mocker .patch ("cli.schedule.get_logger" )
299+ mock_task_from_id = mocker .patch ("cli.schedule.get_task_from_id" )
300+ mock_task_from_id .return_value .update_schedule .side_effect = Exception ("error" )
301+ mock_snake = mocker .patch ("cli.schedule.snakesay" )
302+
303+ runner .invoke (app , ["update" , "42" , "--disable" ])
304+
305+ assert mock_snake .call_args == call ("error" )
306+ assert mock_logger .return_value .warning .call_args == call (mock_snake .return_value )
307+
308+ def test_ensures_proper_daily_params (self , mocker ):
309+ mock_task_from_id = mocker .patch ("cli.schedule.get_task_from_id" )
310+
311+ result = runner .invoke (app , ["update" , "42" , "--hourly" ])
312+
313+ assert mock_task_from_id .return_value .update_schedule .call_args == call (
314+ {"interval" : "hourly" }, porcelain = False
315+ )
316+
317+ def test_ensures_proper_hourly_params (self , mocker ):
318+ mock_task_from_id = mocker .patch ("cli.schedule.get_task_from_id" )
319+ mock_datetime = mocker .patch ("cli.schedule.datetime" )
320+
321+ runner .invoke (app , ["update" , "42" , "--daily" ])
322+
323+ assert mock_task_from_id .return_value .update_schedule .call_args == call (
324+ {"interval" : "daily" , "hour" : mock_datetime .now .return_value .hour },
325+ porcelain = False
326+ )
327+
328+ def test_validates_minute (self ):
329+ result = runner .invoke (app , ["update" , "42" , "--minute" , "88" ])
330+ assert "88 is not in the valid range of 0 to 59" in result .stdout
331+
332+ def test_validates_hour (self ):
333+ result = runner .invoke (app , ["update" , "42" , "--daily" , "--hour" , "33" ])
334+ assert "33 is not in the valid range of 0 to 23" in result .stdout
335+
336+ def test_complains_when_no_id_provided (self ):
337+ result = runner .invoke (app , ["update" ])
338+ assert "Missing argument 'id'" in result .stdout
339+
340+ def test_exits_early_when_nothing_to_update (self , mocker ):
341+ mock_logger = mocker .patch ("cli.schedule.get_logger" ).return_value
342+ mock_snakesay = mocker .patch ("cli.schedule.snakesay" )
343+
344+ result = runner .invoke (app , ["update" , "42" ])
345+
346+ assert mock_snakesay .call_args == call ("Nothing to update!" )
347+ assert mock_logger .warning .call_args == call (mock_snakesay .return_value )
348+ assert result .exit_code == 1
0 commit comments