added deprecate_thing_type method for IOT (#4184)

Co-authored-by: arielb <ariel.beck@cyberark.com>
This commit is contained in:
Ariel Beck 2021-08-17 20:05:18 +03:00 committed by GitHub
parent 1d90946072
commit 2f5a702f1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 0 deletions

View File

@ -629,6 +629,15 @@ class IoTBackend(BaseBackend):
thing_type = self.describe_thing_type(thing_type_name)
del self.thing_types[thing_type.arn]
def deprecate_thing_type(self, thing_type_name, undo_deprecate):
thing_types = [
_ for _ in self.thing_types.values() if _.thing_type_name == thing_type_name
]
if len(thing_types) == 0:
raise ResourceNotFoundException()
thing_types[0].metadata["deprecated"] = not undo_deprecate
return thing_types[0]
def update_thing(
self,
thing_name,

View File

@ -106,6 +106,14 @@ class IoTResponse(BaseResponse):
self.iot_backend.delete_thing_type(thing_type_name=thing_type_name)
return json.dumps(dict())
def deprecate_thing_type(self):
thing_type_name = self._get_param("thingTypeName")
undo_deprecate = self._get_param("undoDeprecate")
thing_type = self.iot_backend.deprecate_thing_type(
thing_type_name=thing_type_name, undo_deprecate=undo_deprecate
)
return json.dumps(thing_type.to_dict())
def update_thing(self):
thing_name = self._get_param("thingName")
thing_type_name = self._get_param("thingTypeName")

View File

@ -2210,3 +2210,33 @@ class TestTopicRules:
res = client.list_topic_rules()
res.should.have.key("rules").which.should.have.length_of(0)
@mock_iot
def test_deprecate_undeprecate_thing_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"]},
)
res = client.describe_thing_type(thingTypeName=thing_type_name)
res["thingTypeMetadata"]["deprecated"].should.equal(False)
client.deprecate_thing_type(thingTypeName=thing_type_name, undoDeprecate=False)
res = client.describe_thing_type(thingTypeName=thing_type_name)
res["thingTypeMetadata"]["deprecated"].should.equal(True)
client.deprecate_thing_type(thingTypeName=thing_type_name, undoDeprecate=True)
res = client.describe_thing_type(thingTypeName=thing_type_name)
res["thingTypeMetadata"]["deprecated"].should.equal(False)
@mock_iot
def test_deprecate_thing_type_not_exist(self):
client = boto3.client("iot", region_name="ap-northeast-1")
thing_type_name = "my-type-name"
with pytest.raises(client.exceptions.ResourceNotFoundException):
client.deprecate_thing_type(
thingTypeName=thing_type_name, undoDeprecate=False
)