diff --git a/moto/scheduler/exceptions.py b/moto/scheduler/exceptions.py index 0e180c2c1..fcf49f736 100644 --- a/moto/scheduler/exceptions.py +++ b/moto/scheduler/exceptions.py @@ -8,8 +8,10 @@ class ScheduleExists(JsonRESTError): class ScheduleNotFound(JsonRESTError): - def __init__(self) -> None: - super().__init__("ResourceNotFoundException", "Schedule not found") + def __init__(self, name: str) -> None: + super().__init__( + "ResourceNotFoundException", f"Schedule {name} does not exist." + ) class ScheduleGroupNotFound(JsonRESTError): diff --git a/moto/scheduler/models.py b/moto/scheduler/models.py index bd440a9f8..fbbd57f7c 100644 --- a/moto/scheduler/models.py +++ b/moto/scheduler/models.py @@ -108,10 +108,12 @@ class ScheduleGroup(BaseModel): def get_schedule(self, name: str) -> Schedule: if name not in self.schedules: - raise ScheduleNotFound + raise ScheduleNotFound(name) return self.schedules[name] def delete_schedule(self, name: str) -> None: + if name not in self.schedules: + raise ScheduleNotFound(name) self.schedules.pop(name) def to_dict(self) -> Dict[str, Any]: diff --git a/tests/test_scheduler/test_scheduler.py b/tests/test_scheduler/test_scheduler.py index 7abab8173..c613cb5f6 100644 --- a/tests/test_scheduler/test_scheduler.py +++ b/tests/test_scheduler/test_scheduler.py @@ -175,6 +175,17 @@ def test_get_schedule_for_unknown_group(): assert err["Code"] == "ResourceNotFoundException" +@mock_scheduler +def test_get_schedule_for_none_existing_schedule(): + client = boto3.client("scheduler", region_name="eu-west-1") + + with pytest.raises(ClientError) as exc: + client.get_schedule(Name="my-schedule") + err = exc.value.response["Error"] + assert err["Code"] == "ResourceNotFoundException" + assert err["Message"] == "Schedule my-schedule does not exist." + + @mock_scheduler def test_list_schedules(): client = boto3.client("scheduler", region_name="eu-west-1") @@ -206,3 +217,14 @@ def test_list_schedules(): schedules = client.list_schedules(State="ENABLED")["Schedules"] assert len(schedules) == 4 + + +@mock_scheduler +def test_delete_schedule_for_none_existing_schedule(): + client = boto3.client("scheduler", region_name="eu-west-1") + + with pytest.raises(ClientError) as exc: + client.delete_schedule(Name="my-schedule") + err = exc.value.response["Error"] + assert err["Code"] == "ResourceNotFoundException" + assert err["Message"] == "Schedule my-schedule does not exist."