Scheduler: fix delete_schedule validation(#7160) (#7168)

This commit is contained in:
cm-iwata 2023-12-30 23:21:31 +09:00 committed by GitHub
parent b3fa9bbb08
commit ba73f64e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 3 deletions

View File

@ -8,8 +8,10 @@ class ScheduleExists(JsonRESTError):
class ScheduleNotFound(JsonRESTError): class ScheduleNotFound(JsonRESTError):
def __init__(self) -> None: def __init__(self, name: str) -> None:
super().__init__("ResourceNotFoundException", "Schedule not found") super().__init__(
"ResourceNotFoundException", f"Schedule {name} does not exist."
)
class ScheduleGroupNotFound(JsonRESTError): class ScheduleGroupNotFound(JsonRESTError):

View File

@ -108,10 +108,12 @@ class ScheduleGroup(BaseModel):
def get_schedule(self, name: str) -> Schedule: def get_schedule(self, name: str) -> Schedule:
if name not in self.schedules: if name not in self.schedules:
raise ScheduleNotFound raise ScheduleNotFound(name)
return self.schedules[name] return self.schedules[name]
def delete_schedule(self, name: str) -> None: def delete_schedule(self, name: str) -> None:
if name not in self.schedules:
raise ScheduleNotFound(name)
self.schedules.pop(name) self.schedules.pop(name)
def to_dict(self) -> Dict[str, Any]: def to_dict(self) -> Dict[str, Any]:

View File

@ -175,6 +175,17 @@ def test_get_schedule_for_unknown_group():
assert err["Code"] == "ResourceNotFoundException" 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 @mock_scheduler
def test_list_schedules(): def test_list_schedules():
client = boto3.client("scheduler", region_name="eu-west-1") client = boto3.client("scheduler", region_name="eu-west-1")
@ -206,3 +217,14 @@ def test_list_schedules():
schedules = client.list_schedules(State="ENABLED")["Schedules"] schedules = client.list_schedules(State="ENABLED")["Schedules"]
assert len(schedules) == 4 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."