add tagging support to events
This commit is contained in:
parent
d596560971
commit
eaa8c8db6e
6 changed files with 228 additions and 12 deletions
|
|
@ -1,12 +1,15 @@
|
|||
import random
|
||||
import boto3
|
||||
import json
|
||||
import sure # noqa
|
||||
import random
|
||||
import unittest
|
||||
|
||||
from moto.events import mock_events
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
from nose.tools import assert_raises
|
||||
|
||||
from moto.core import ACCOUNT_ID
|
||||
from moto.core.exceptions import JsonRESTError
|
||||
from moto.events import mock_events
|
||||
from moto.events.models import EventsBackend
|
||||
|
||||
RULES = [
|
||||
{"Name": "test1", "ScheduleExpression": "rate(5 minutes)"},
|
||||
|
|
@ -136,14 +139,6 @@ def test_list_rule_names_by_target():
|
|||
assert rule in test_2_target["Rules"]
|
||||
|
||||
|
||||
@mock_events
|
||||
def test_list_rules():
|
||||
client = generate_environment()
|
||||
|
||||
rules = client.list_rules()
|
||||
assert len(rules["Rules"]) == len(RULES)
|
||||
|
||||
|
||||
@mock_events
|
||||
def test_delete_rule():
|
||||
client = generate_environment()
|
||||
|
|
@ -461,3 +456,58 @@ def test_delete_event_bus_errors():
|
|||
client.delete_event_bus.when.called_with(Name="default").should.throw(
|
||||
ClientError, "Cannot delete event bus default."
|
||||
)
|
||||
|
||||
|
||||
@mock_events
|
||||
def test_rule_tagging_happy():
|
||||
client = generate_environment()
|
||||
rule_name = get_random_rule()["Name"]
|
||||
rule_arn = client.describe_rule(Name=rule_name).get("Arn")
|
||||
|
||||
tags = [{"Key": "key1", "Value": "value1"}, {"Key": "key2", "Value": "value2"}]
|
||||
client.tag_resource(ResourceARN=rule_arn, Tags=tags)
|
||||
|
||||
actual = client.list_tags_for_resource(ResourceARN=rule_arn).get("Tags")
|
||||
tc = unittest.TestCase("__init__")
|
||||
expected = [{"Value": "value1", "Key": "key1"}, {"Value": "value2", "Key": "key2"}]
|
||||
tc.assertTrue(
|
||||
(expected[0] == actual[0] and expected[1] == actual[1])
|
||||
or (expected[1] == actual[0] and expected[0] == actual[1])
|
||||
)
|
||||
|
||||
client.untag_resource(ResourceARN=rule_arn, TagKeys=["key1"])
|
||||
|
||||
actual = client.list_tags_for_resource(ResourceARN=rule_arn).get("Tags")
|
||||
expected = [{"Key": "key2", "Value": "value2"}]
|
||||
assert expected == actual
|
||||
|
||||
|
||||
def freeze_dict(obj):
|
||||
if isinstance(obj, dict):
|
||||
dict_items = list(obj.items())
|
||||
dict_items.append(("__frozen__", True))
|
||||
return tuple([(k, freeze_dict(v)) for k, v in dict_items])
|
||||
return obj
|
||||
|
||||
|
||||
@mock_events
|
||||
def test_rule_tagging_sad():
|
||||
b = EventsBackend("us-west-2")
|
||||
|
||||
try:
|
||||
b.tag_resource("unknown", [])
|
||||
raise "tag_resource should fail if ResourceARN is not known"
|
||||
except JsonRESTError:
|
||||
pass
|
||||
|
||||
try:
|
||||
b.untag_resource("unknown", [])
|
||||
raise "untag_resource should fail if ResourceARN is not known"
|
||||
except JsonRESTError:
|
||||
pass
|
||||
|
||||
try:
|
||||
b.list_tags_for_resource("unknown")
|
||||
raise "list_tags_for_resource should fail if ResourceARN is not known"
|
||||
except JsonRESTError:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue