Refactored test_list_thing_groups into class TestListThingGroup
This commit is contained in:
parent
40d1c8c9b9
commit
5fd8179653
@ -787,9 +787,7 @@ def test_delete_principal_thing():
|
|||||||
client.delete_certificate(certificateId=cert_id)
|
client.delete_certificate(certificateId=cert_id)
|
||||||
|
|
||||||
|
|
||||||
@mock_iot
|
class TestListThingGroup:
|
||||||
def test_list_thing_groups():
|
|
||||||
client = boto3.client("iot", region_name="ap-northeast-1")
|
|
||||||
group_name_1a = "my-group-name-1a"
|
group_name_1a = "my-group-name-1a"
|
||||||
group_name_1b = "my-group-name-1b"
|
group_name_1b = "my-group-name-1b"
|
||||||
group_name_2a = "my-group-name-2a"
|
group_name_2a = "my-group-name-2a"
|
||||||
@ -805,44 +803,68 @@ def test_list_thing_groups():
|
|||||||
},
|
},
|
||||||
group_name_1b: {},
|
group_name_1b: {},
|
||||||
}
|
}
|
||||||
group_catalog = generate_thing_group_tree(client, tree_dict)
|
|
||||||
|
|
||||||
# begin tests
|
@mock_iot
|
||||||
# should list all groups
|
def test_should_list_all_groups(self):
|
||||||
|
# setup
|
||||||
|
client = boto3.client("iot", region_name="ap-northeast-1")
|
||||||
|
group_catalog = generate_thing_group_tree(client, self.tree_dict)
|
||||||
|
# test
|
||||||
resp = client.list_thing_groups()
|
resp = client.list_thing_groups()
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(8)
|
resp["thingGroups"].should.have.length_of(8)
|
||||||
# should list all groups non-recursively
|
|
||||||
|
|
||||||
|
@mock_iot
|
||||||
|
def test_should_list_all_groups_non_recursively(self):
|
||||||
|
# setup
|
||||||
|
client = boto3.client("iot", region_name="ap-northeast-1")
|
||||||
|
group_catalog = generate_thing_group_tree(client, self.tree_dict)
|
||||||
|
# test
|
||||||
resp = client.list_thing_groups(recursive=False)
|
resp = client.list_thing_groups(recursive=False)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(2)
|
resp["thingGroups"].should.have.length_of(2)
|
||||||
|
|
||||||
# should list all groups filtered by parent
|
|
||||||
resp = client.list_thing_groups(parentGroup=group_name_1a)
|
@mock_iot
|
||||||
|
def test_should_list_all_groups_filtered_by_parent(self):
|
||||||
|
# setup
|
||||||
|
client = boto3.client("iot", region_name="ap-northeast-1")
|
||||||
|
group_catalog = generate_thing_group_tree(client, self.tree_dict)
|
||||||
|
# test
|
||||||
|
resp = client.list_thing_groups(parentGroup=self.group_name_1a)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(6)
|
resp["thingGroups"].should.have.length_of(6)
|
||||||
resp = client.list_thing_groups(parentGroup=group_name_2a)
|
resp = client.list_thing_groups(parentGroup=self.group_name_2a)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(2)
|
resp["thingGroups"].should.have.length_of(2)
|
||||||
resp = client.list_thing_groups(parentGroup=group_name_1b)
|
resp = client.list_thing_groups(parentGroup=self.group_name_1b)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(0)
|
resp["thingGroups"].should.have.length_of(0)
|
||||||
try:
|
with assert_raises(ClientError) as e:
|
||||||
client.list_thing_groups(parentGroup="inexistant-group-name")
|
client.list_thing_groups(parentGroup="inexistant-group-name")
|
||||||
except client.exceptions.ResourceNotFoundException as exc:
|
e.exception.response["Error"]["Code"].should.equal("ResourceNotFoundException")
|
||||||
error_code = exc.response["Error"]["Code"]
|
|
||||||
error_code.should.equal("ResourceNotFoundException")
|
@mock_iot
|
||||||
else:
|
def test_should_list_all_groups_filtered_by_parent_non_recursively(self):
|
||||||
raise Exception("Should have raised error")
|
# setup
|
||||||
# should list all groups filtered by parent non-recursively
|
client = boto3.client("iot", region_name="ap-northeast-1")
|
||||||
resp = client.list_thing_groups(parentGroup=group_name_1a, recursive=False)
|
group_catalog = generate_thing_group_tree(client, self.tree_dict)
|
||||||
|
# test
|
||||||
|
resp = client.list_thing_groups(parentGroup=self.group_name_1a, recursive=False)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(2)
|
resp["thingGroups"].should.have.length_of(2)
|
||||||
resp = client.list_thing_groups(parentGroup=group_name_2a, recursive=False)
|
resp = client.list_thing_groups(parentGroup=self.group_name_2a, recursive=False)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(2)
|
resp["thingGroups"].should.have.length_of(2)
|
||||||
|
|
||||||
# should list all groups filtered by name prefix
|
|
||||||
|
@mock_iot
|
||||||
|
def test_should_list_all_groups_filtered_by_name_prefix(self):
|
||||||
|
# setup
|
||||||
|
client = boto3.client("iot", region_name="ap-northeast-1")
|
||||||
|
group_catalog = generate_thing_group_tree(client, self.tree_dict)
|
||||||
|
# test
|
||||||
resp = client.list_thing_groups(namePrefixFilter="my-group-name-1")
|
resp = client.list_thing_groups(namePrefixFilter="my-group-name-1")
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(2)
|
resp["thingGroups"].should.have.length_of(2)
|
||||||
@ -852,7 +874,14 @@ def test_list_thing_groups():
|
|||||||
resp = client.list_thing_groups(namePrefixFilter="prefix-which-doesn-not-match")
|
resp = client.list_thing_groups(namePrefixFilter="prefix-which-doesn-not-match")
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(0)
|
resp["thingGroups"].should.have.length_of(0)
|
||||||
# should list all groups filtered by name prefix non-recursively
|
|
||||||
|
|
||||||
|
@mock_iot
|
||||||
|
def test_should_list_all_groups_filtered_by_name_prefix_non_recursively(self):
|
||||||
|
# setup
|
||||||
|
client = boto3.client("iot", region_name="ap-northeast-1")
|
||||||
|
group_catalog = generate_thing_group_tree(client, self.tree_dict)
|
||||||
|
# test
|
||||||
resp = client.list_thing_groups(namePrefixFilter="my-group-name-1", recursive=False)
|
resp = client.list_thing_groups(namePrefixFilter="my-group-name-1", recursive=False)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(2)
|
resp["thingGroups"].should.have.length_of(2)
|
||||||
@ -860,19 +889,25 @@ def test_list_thing_groups():
|
|||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(0)
|
resp["thingGroups"].should.have.length_of(0)
|
||||||
|
|
||||||
# should list all groups filtered by name prefix and parent
|
|
||||||
|
@mock_iot
|
||||||
|
def test_should_list_all_groups_filtered_by_name_prefix_and_parent(self):
|
||||||
|
# setup
|
||||||
|
client = boto3.client("iot", region_name="ap-northeast-1")
|
||||||
|
group_catalog = generate_thing_group_tree(client, self.tree_dict)
|
||||||
|
# test
|
||||||
resp = client.list_thing_groups(
|
resp = client.list_thing_groups(
|
||||||
namePrefixFilter="my-group-name-2", parentGroup=group_name_1a
|
namePrefixFilter="my-group-name-2", parentGroup=self.group_name_1a
|
||||||
)
|
)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(2)
|
resp["thingGroups"].should.have.length_of(2)
|
||||||
resp = client.list_thing_groups(
|
resp = client.list_thing_groups(
|
||||||
namePrefixFilter="my-group-name-3", parentGroup=group_name_1a
|
namePrefixFilter="my-group-name-3", parentGroup=self.group_name_1a
|
||||||
)
|
)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(4)
|
resp["thingGroups"].should.have.length_of(4)
|
||||||
resp = client.list_thing_groups(
|
resp = client.list_thing_groups(
|
||||||
namePrefixFilter="prefix-which-doesn-not-match", parentGroup=group_name_1a
|
namePrefixFilter="prefix-which-doesn-not-match", parentGroup=self.group_name_1a
|
||||||
)
|
)
|
||||||
resp.should.have.key("thingGroups")
|
resp.should.have.key("thingGroups")
|
||||||
resp["thingGroups"].should.have.length_of(0)
|
resp["thingGroups"].should.have.length_of(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user