forked from cloud-custodian/cloud-custodian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pmtcrypt.py
67 lines (58 loc) · 2.33 KB
/
test_pmtcrypt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0
from .common import BaseTest
class PmtcryptTest(BaseTest):
def test_tag_action(self):
session_factory = self.replay_flight_data('test_pmtcrypt_tag_action')
p = self.load_policy(
{
"name": "tag-payment-cryptography",
"resource": "payment-cryptography-key",
"actions": [
{"type": "tag", "key": "Department", "value": "International"},
]
},
session_factory=session_factory,
)
resources = p.run()
self.assertEqual(len(resources), 1)
client = session_factory().client("payment-cryptography")
tags = client.list_tags_for_resource(ResourceArn=resources[0]["KeyArn"])["Tags"]
self.assertEqual(tags[0]["Value"], "International")
def test_remove_tag(self):
session_factory = self.replay_flight_data(
"test_payment-cryptography_remove_tag"
)
p = self.load_policy(
{
"name": "remove-tag-payment-cryptography",
"resource": "payment-cryptography-key",
"actions": [{"type": "remove-tag", "tags": ["ResourceOwner"]}],
},
session_factory=session_factory,
)
resources = p.run()
self.assertEqual(len(resources), 1)
client = session_factory().client("payment-cryptography")
tags = client.list_tags_for_resource(ResourceArn=resources[0]["KeyArn"])["Tags"]
self.assertEqual(len(tags), 0)
def test_delete_(self):
session_factory = self.replay_flight_data(
"test_payment-cryptography_delete"
)
p = self.load_policy(
{
"name": "delete-payment-cryptography",
"resource": "payment-cryptography-key",
"filters": [{"tag:Department": "International"}],
"actions": [{"type": "delete"}],
},
session_factory=session_factory,
)
resources = p.run()
self.assertEqual(len(resources), 1)
client = session_factory().client("payment-cryptography")
key = client.get_key(
KeyIdentifier=resources[0]["KeyArn"]
)["Key"]
self.assertTrue(key["KeyState"], "DELETE_PENDING")