Scheduler: create_scheduler() now errors on duplicate names (#6641)
This commit is contained in:
parent
d47f984175
commit
b41e2579c6
@ -2,6 +2,11 @@
|
|||||||
from moto.core.exceptions import JsonRESTError
|
from moto.core.exceptions import JsonRESTError
|
||||||
|
|
||||||
|
|
||||||
|
class ScheduleExists(JsonRESTError):
|
||||||
|
def __init__(self, name: str) -> None:
|
||||||
|
super().__init__("ConflictException", f"Schedule {name} already exists.")
|
||||||
|
|
||||||
|
|
||||||
class ScheduleNotFound(JsonRESTError):
|
class ScheduleNotFound(JsonRESTError):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__("ResourceNotFoundException", "Schedule not found")
|
super().__init__("ResourceNotFoundException", "Schedule not found")
|
||||||
|
@ -5,6 +5,7 @@ from moto.core import BaseBackend, BackendDict, BaseModel
|
|||||||
from moto.core.utils import unix_time
|
from moto.core.utils import unix_time
|
||||||
from moto.utilities.tagging_service import TaggingService
|
from moto.utilities.tagging_service import TaggingService
|
||||||
|
|
||||||
|
from .exceptions import ScheduleExists
|
||||||
from .exceptions import ScheduleNotFound, ScheduleGroupNotFound
|
from .exceptions import ScheduleNotFound, ScheduleGroupNotFound
|
||||||
|
|
||||||
|
|
||||||
@ -155,6 +156,8 @@ class EventBridgeSchedulerBackend(BaseBackend):
|
|||||||
The ClientToken parameter is not yet implemented
|
The ClientToken parameter is not yet implemented
|
||||||
"""
|
"""
|
||||||
group = self.schedule_groups[group_name or "default"]
|
group = self.schedule_groups[group_name or "default"]
|
||||||
|
if name in group.schedules:
|
||||||
|
raise ScheduleExists(name)
|
||||||
schedule = Schedule(
|
schedule = Schedule(
|
||||||
region=self.region_name,
|
region=self.region_name,
|
||||||
account_id=self.account_id,
|
account_id=self.account_id,
|
||||||
|
@ -144,6 +144,26 @@ def test_update_schedule(extra_kwargs):
|
|||||||
assert schedule["CreationDate"] != schedule["LastModificationDate"]
|
assert schedule["CreationDate"] != schedule["LastModificationDate"]
|
||||||
|
|
||||||
|
|
||||||
|
@mock_scheduler
|
||||||
|
def test_create_duplicate_schedule():
|
||||||
|
client = boto3.client("scheduler", region_name="us-east-1")
|
||||||
|
params = {
|
||||||
|
"ScheduleExpression": "at(2022-12-12T00:00:00)",
|
||||||
|
"FlexibleTimeWindow": {
|
||||||
|
"MaximumWindowInMinutes": 4,
|
||||||
|
"Mode": "FLEXIBLE",
|
||||||
|
},
|
||||||
|
"Target": {"Arn": "arn1", "RoleArn": "arn2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
client.create_schedule(Name="schedule1", **params)
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
client.create_schedule(Name="schedule1", **params)
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
assert err["Code"] == "ConflictException"
|
||||||
|
assert err["Message"] == "Schedule schedule1 already exists."
|
||||||
|
|
||||||
|
|
||||||
@mock_scheduler
|
@mock_scheduler
|
||||||
def test_get_schedule_for_unknown_group():
|
def test_get_schedule_for_unknown_group():
|
||||||
client = boto3.client("scheduler", region_name="eu-west-1")
|
client = boto3.client("scheduler", region_name="eu-west-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user