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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
from moto.ssm.utils import convert_to_params, convert_to_tree
SOURCE_PARAMS = [
{
"ARN": (
"arn:aws:ssm:us-west-1::parameter/aws/service"
"/global-infrastructure/regions/af-south-1"
),
"DataType": "text",
"Name": "/aws/service/global-infrastructure/regions/af-south-1",
"Type": "String",
"Value": "af-south-1",
"Version": 1,
},
{
"ARN": (
"arn:aws:ssm:us-west-1::parameter/aws/service"
"/global-infrastructure/regions/ap-northeast-2"
),
"DataType": "text",
"Name": "/aws/service/global-infrastructure/regions/ap-northeast-2",
"Type": "String",
"Value": "ap-northeast-2",
"Version": 1,
},
{
"ARN": (
"arn:aws:ssm:us-west-1::parameter/aws/service"
"/global-infrastructure/regions/cn-north-1"
),
"DataType": "text",
"Name": "/aws/service/global-infrastructure/regions/cn-north-1",
"Type": "String",
"Value": "cn-north-1",
"Version": 1,
},
{
"ARN": (
"arn:aws:ssm:us-west-1::parameter/aws/service"
"/global-infrastructure/regions/ap-northeast-2/services"
"/codestar-notifications"
),
"DataType": "text",
"Name": (
"/aws/service/global-infrastructure/regions"
"/ap-northeast-2/services/codestar-notifications"
),
"Type": "String",
"Value": "codestar-notifications",
"Version": 1,
},
]
EXPECTED_TREE = {
"aws": {
"service": {
"global-infrastructure": {
"regions": {
"af-south-1": {"Value": "af-south-1"},
"cn-north-1": {"Value": "cn-north-1"},
"ap-northeast-2": {
"Value": "ap-northeast-2",
"services": {
"codestar-notifications": {
"Value": "codestar-notifications"
}
},
},
}
}
}
}
}
CONVERTED_PARAMS = [
{
"Name": "/aws/service/global-infrastructure/regions/af-south-1",
"Value": "af-south-1",
},
{
"Name": "/aws/service/global-infrastructure/regions/cn-north-1",
"Value": "cn-north-1",
},
{
"Name": "/aws/service/global-infrastructure/regions/ap-northeast-2",
"Value": "ap-northeast-2",
},
{
"Name": (
"/aws/service/global-infrastructure/regions/ap-northeast-2"
"/services/codestar-notifications"
),
"Value": "codestar-notifications",
},
]
def test_convert_to_tree():
tree = convert_to_tree(SOURCE_PARAMS)
assert tree == EXPECTED_TREE
def test_convert_to_params():
actual = convert_to_params(EXPECTED_TREE)
assert len(actual) == len(CONVERTED_PARAMS)
for param in CONVERTED_PARAMS:
assert param in actual
def test_input_is_correct():
"""Test input should match."""
for src in SOURCE_PARAMS:
minimized_src = {"Name": src["Name"], "Value": src["Value"]}
assert minimized_src in CONVERTED_PARAMS
|