Skip to content

Commit

Permalink
Scheduler: Fix Exception code/format and default timezone (#8478)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhoheiser authored Jan 11, 2025
1 parent c60f261 commit d8d4e28
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
10 changes: 8 additions & 2 deletions moto/scheduler/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ def __init__(self, name: str) -> None:


class ScheduleNotFound(JsonRESTError):
code = 404

def __init__(self, name: str) -> None:
super().__init__(
"ResourceNotFoundException", f"Schedule {name} does not exist."
)


class ScheduleGroupNotFound(JsonRESTError):
def __init__(self) -> None:
super().__init__("ResourceNotFoundException", "ScheduleGroup not found")
code = 404

def __init__(self, name: str) -> None:
super().__init__(
"ResourceNotFoundException", f"Schedule group {name} does not exist."
)


class ValidationException(JsonRESTError):
Expand Down
6 changes: 3 additions & 3 deletions moto/scheduler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
self.description = description
self.arn = f"arn:{get_partition(region)}:scheduler:{region}:{account_id}:schedule/{group_name}/{name}"
self.schedule_expression = schedule_expression
self.schedule_expression_timezone = schedule_expression_timezone
self.schedule_expression_timezone = schedule_expression_timezone or "UTC"
self.flexible_time_window = flexible_time_window
self.target = Schedule.validate_target(target)
self.state = state or "ENABLED"
Expand Down Expand Up @@ -110,7 +110,7 @@ def update(
target: Dict[str, Any],
) -> None:
self.schedule_expression = schedule_expression
self.schedule_expression_timezone = schedule_expression_timezone
self.schedule_expression_timezone = schedule_expression_timezone or "UTC"
self.flexible_time_window = flexible_time_window
self.target = Schedule.validate_target(target)
self.description = description
Expand Down Expand Up @@ -273,7 +273,7 @@ def create_schedule_group(

def get_schedule_group(self, group_name: Optional[str]) -> ScheduleGroup:
if (group_name or "default") not in self.schedule_groups:
raise ScheduleGroupNotFound
raise ScheduleGroupNotFound(group_name or "default")
return self.schedule_groups[group_name or "default"]

def list_schedule_groups(self) -> Iterable[ScheduleGroup]:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_scheduler/test_schedule_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ def test_list_schedule_groups():
groups = client.list_schedule_groups()["ScheduleGroups"]
assert len(groups) == 2
assert groups[1]["Arn"] == arn1


@mock_aws
def test_get_schedule_groupe_not_found():
client = boto3.client("scheduler", region_name="eu-west-1")

with pytest.raises(ClientError) as exc:
client.get_schedule_group(Name="sg")
err = exc.value.response["Error"]
assert err["Message"] == "Schedule group sg does not exist."
assert err["Code"] == "ResourceNotFoundException"
assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 404
1 change: 1 addition & 0 deletions tests/test_scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def test_get_schedule_for_none_existing_schedule():
err = exc.value.response["Error"]
assert err["Code"] == "ResourceNotFoundException"
assert err["Message"] == "Schedule my-schedule does not exist."
assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 404


@mock_aws
Expand Down

0 comments on commit d8d4e28

Please sign in to comment.