diff --git a/AUTHORS.md b/AUTHORS.md index 0228ac665..31a348ce4 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -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) \ No newline at end of file diff --git a/moto/iot/models.py b/moto/iot/models.py index 706582ac9..ad0e459f7 100644 --- a/moto/iot/models.py +++ b/moto/iot/models.py @@ -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): diff --git a/tests/test_iot/test_iot.py b/tests/test_iot/test_iot.py index ac32dc3af..d4505df1a 100644 --- a/tests/test_iot/test_iot.py +++ b/tests/test_iot/test_iot.py @@ -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 + )