Iot/added deprecation errors (#4192)

Co-authored-by: arielb <ariel.beck@cyberark.com>
This commit is contained in:
Ariel Beck 2021-08-18 12:32:58 +03:00 committed by GitHub
parent c296a9431e
commit ce449bf86b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 1 deletions

View File

@ -58,3 +58,4 @@ Moto is written by Steve Pulec with contributions from:
* [Craig Anderson](https://github.com/craiga)
* [Robert Lewis](https://github.com/ralewis85)
* [Kyle Jones](https://github.com/Kerl1310)
* [Ariel Beck](https://github.com/arielb135)

View File

@ -515,6 +515,12 @@ class IoTBackend(BaseBackend):
if len(filtered_thing_types) == 0:
raise ResourceNotFoundException()
thing_type = filtered_thing_types[0]
if thing_type.metadata["deprecated"]:
# note - typo (depreated) exists also in the original exception.
raise InvalidRequestException(
msg=f"Can not create new thing with depreated thing type:{thing_type_name}"
)
if attribute_payload is None:
attributes = {}
elif "attributes" not in attribute_payload:
@ -662,6 +668,12 @@ class IoTBackend(BaseBackend):
if len(filtered_thing_types) == 0:
raise ResourceNotFoundException()
thing_type = filtered_thing_types[0]
if thing_type.metadata["deprecated"]:
raise InvalidRequestException(
msg=f"Can not update a thing to use deprecated thing type: {thing_type_name}"
)
thing.thing_type = thing_type
if remove_thing_type:
@ -1365,7 +1377,7 @@ class IoTBackend(BaseBackend):
topic_pattern=topic,
sql=sql,
region_name=self.region_name,
**kwargs
**kwargs,
)
def replace_topic_rule(self, rule_name, **kwargs):

View File

@ -2240,3 +2240,39 @@ class TestTopicRules:
client.deprecate_thing_type(
thingTypeName=thing_type_name, undoDeprecate=False
)
@mock_iot
def test_create_thing_with_deprecated_type(self):
client = boto3.client("iot", region_name="ap-northeast-1")
thing_type_name = "my-type-name"
client.create_thing_type(
thingTypeName=thing_type_name,
thingTypeProperties={"searchableAttributes": ["s1", "s2", "s3"]},
)
client.deprecate_thing_type(thingTypeName=thing_type_name, undoDeprecate=False)
with pytest.raises(client.exceptions.InvalidRequestException):
client.create_thing(thingName="thing-name", thingTypeName=thing_type_name)
@mock_iot
def test_update_thing_with_deprecated_type(self):
client = boto3.client("iot", region_name="ap-northeast-1")
thing_type_name = "my-type-name"
thing_name = "thing-name"
client.create_thing_type(
thingTypeName=thing_type_name,
thingTypeProperties={"searchableAttributes": ["s1", "s2", "s3"]},
)
deprecated_thing_type_name = "my-type-name-deprecated"
client.create_thing_type(
thingTypeName=deprecated_thing_type_name,
thingTypeProperties={"searchableAttributes": ["s1", "s2", "s3"]},
)
client.deprecate_thing_type(
thingTypeName=deprecated_thing_type_name, undoDeprecate=False
)
client.create_thing(thingName=thing_name, thingTypeName=thing_type_name)
with pytest.raises(client.exceptions.InvalidRequestException):
client.update_thing(
thingName=thing_name, thingTypeName=deprecated_thing_type_name
)