Fix:update rule (#3734)
* Fix:SQS-message retention period consideration * Fix:SQS-message retention period consideration * Fix:SQS-message retention period consideration * Added comments &linting * Fixed tests * Fix:update rule * Linting and comments
This commit is contained in:
parent
457402fbe2
commit
5c04a4d8cc
@ -672,10 +672,22 @@ class EventsBackend(BaseBackend):
|
||||
|
||||
return return_obj
|
||||
|
||||
def update_rule(self, rule, **kwargs):
|
||||
rule.event_pattern = kwargs.get("EventPattern") or rule.event_pattern
|
||||
rule.schedule_exp = kwargs.get("ScheduleExpression") or rule.schedule_exp
|
||||
rule.state = kwargs.get("State") or rule.state
|
||||
rule.description = kwargs.get("Description") or rule.description
|
||||
rule.role_arn = kwargs.get("RoleArn") or rule.role_arn
|
||||
rule.event_bus_name = kwargs.get("EventBusName") or rule.event_bus_name
|
||||
|
||||
def put_rule(self, name, **kwargs):
|
||||
new_rule = Rule(name, self.region_name, **kwargs)
|
||||
self.rules[new_rule.name] = new_rule
|
||||
self.rules_order.append(new_rule.name)
|
||||
if name in self.rules:
|
||||
self.update_rule(self.rules[name], **kwargs)
|
||||
new_rule = self.rules[name]
|
||||
else:
|
||||
new_rule = Rule(name, self.region_name, **kwargs)
|
||||
self.rules[new_rule.name] = new_rule
|
||||
self.rules_order.append(new_rule.name)
|
||||
return new_rule
|
||||
|
||||
def put_targets(self, name, targets):
|
||||
|
@ -208,6 +208,37 @@ def test_remove_targets():
|
||||
assert targets_before - 1 == targets_after
|
||||
|
||||
|
||||
@mock_events
|
||||
def test_update_rule_with_targets():
|
||||
client = boto3.client("events", "us-west-2")
|
||||
client.put_rule(
|
||||
Name="test1", ScheduleExpression="rate(5 minutes)", EventPattern="",
|
||||
)
|
||||
|
||||
client.put_targets(
|
||||
Rule="test1",
|
||||
Targets=[
|
||||
{
|
||||
"Id": "test-target-1",
|
||||
"Arn": "arn:aws:lambda:us-west-2:111111111111:function:test-function-1",
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
targets = client.list_targets_by_rule(Rule="test1")["Targets"]
|
||||
targets_before = len(targets)
|
||||
assert targets_before == 1
|
||||
|
||||
client.put_rule(
|
||||
Name="test1", ScheduleExpression="rate(1 minute)", EventPattern="",
|
||||
)
|
||||
|
||||
targets = client.list_targets_by_rule(Rule="test1")["Targets"]
|
||||
|
||||
assert len(targets) == 1
|
||||
assert targets[0].get("Id") == "test-target-1"
|
||||
|
||||
|
||||
@mock_events
|
||||
def test_remove_targets_errors():
|
||||
client = boto3.client("events", "us-east-1")
|
||||
|
Loading…
Reference in New Issue
Block a user