moto/tests/test_ssm/test_ssm_parameterstore.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
2.7 KiB
Python
Raw Normal View History

2022-02-12 13:59:15 +00:00
import sure # noqa # pylint: disable=unused-import
from moto.ssm.models import ParameterDict
def test_simple_setget():
2022-08-13 09:49:43 +00:00
store = ParameterDict("accnt", "region")
2022-02-12 13:59:15 +00:00
store["/a/b/c"] = "some object"
store.get("/a/b/c").should.equal("some object")
def test_get_none():
2022-08-13 09:49:43 +00:00
store = ParameterDict("accnt", "region")
2022-02-12 13:59:15 +00:00
store.get(None).should.equal(None)
def test_get_aws_param():
2022-08-13 09:49:43 +00:00
store = ParameterDict("accnt", "region")
2022-02-12 13:59:15 +00:00
p = store["/aws/service/global-infrastructure/regions/us-west-1/longName"]
p.should.have.length_of(1)
p[0].value.should.equal("US West (N. California)")
def test_iter():
2022-08-13 09:49:43 +00:00
store = ParameterDict("accnt", "region")
2022-02-12 13:59:15 +00:00
store["/a/b/c"] = "some object"
"/a/b/c".should.be.within(store)
"/a/b/d".shouldnt.be.within(store)
def test_iter_none():
2022-08-13 09:49:43 +00:00
store = ParameterDict("accnt", "region")
2022-02-12 13:59:15 +00:00
None.shouldnt.be.within(store)
def test_iter_aws():
2022-08-13 09:49:43 +00:00
store = ParameterDict("accnt", "region")
2022-02-12 13:59:15 +00:00
"/aws/service/global-infrastructure/regions/us-west-1/longName".should.be.within(
store
)
def test_get_key_beginning_with():
2022-08-13 09:49:43 +00:00
store = ParameterDict("accnt", "region")
2022-02-12 13:59:15 +00:00
store["/a/b/c"] = "some object"
store["/b/c/d"] = "some other object"
store["/a/c/d"] = "some third object"
begins_with_ab = list(store.get_keys_beginning_with("/a/b", recursive=False))
begins_with_ab.should.equal(["/a/b/c"])
2022-02-12 13:59:15 +00:00
begins_with_a = list(store.get_keys_beginning_with("/a", recursive=False))
begins_with_a.should.equal([])
2022-02-12 13:59:15 +00:00
begins_with_a_recursive = list(store.get_keys_beginning_with("/a", recursive=True))
set(begins_with_a_recursive).should.equal({"/a/b/c", "/a/c/d"})
2022-02-12 13:59:15 +00:00
def test_get_key_beginning_with_aws():
"""
ParameterDict should load the default parameters if we request a key starting with '/aws'
:return:
"""
2022-08-13 09:49:43 +00:00
store = ParameterDict("accnt", "region")
2022-02-12 13:59:15 +00:00
uswest_params = set(
store.get_keys_beginning_with(
"/aws/service/global-infrastructure/regions/us-west-1", recursive=False
)
)
uswest_params.should.equal(
{
"/aws/service/global-infrastructure/regions/us-west-1",
"/aws/service/global-infrastructure/regions/us-west-1/domain",
"/aws/service/global-infrastructure/regions/us-west-1/geolocationCountry",
"/aws/service/global-infrastructure/regions/us-west-1/geolocationRegion",
"/aws/service/global-infrastructure/regions/us-west-1/longName",
"/aws/service/global-infrastructure/regions/us-west-1/partition",
}
)
def test_ssm_parameter_from_unknown_region():
store = ParameterDict("accnt", "region")
list(
store.get_keys_beginning_with(
"/aws/service/ami-amazon-linux-latest", recursive=False
)
).should.equal([])