Fix resource group get-group-query & update-query-query (#3934)

* Fix resource group get-group-query & update-query-query

* Remove list logic

* Added tests

* Fix tests

* Fix update query tests

* fix tests
This commit is contained in:
usmangani1 2021-05-19 01:28:21 +05:30 committed by GitHub
parent 867cf078de
commit 4ad6c3932e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 3 deletions

View File

@ -71,6 +71,9 @@ class ResourceGroupsResponse(BaseResponse):
def get_group_query(self):
group_name = self._get_param("GroupName")
group_arn = self._get_param("Group")
if group_arn and not group_name:
group_name = group_arn.split(":")[-1]
group = self.resourcegroups_backend.get_group(group_name=group_name)
return json.dumps(
{
@ -165,6 +168,9 @@ class ResourceGroupsResponse(BaseResponse):
def update_group_query(self):
group_name = self._get_param("GroupName")
resource_query = self._get_param("ResourceQuery")
group_arn = self._get_param("Group")
if group_arn and not group_name:
group_name = group_arn.split(":")[-1]
group = self.resourcegroups_backend.update_group_query(
group_name=group_name, resource_query=resource_query
)

View File

@ -64,11 +64,18 @@ def test_get_group():
def test_get_group_query():
resource_groups = boto3.client("resource-groups", region_name="us-east-1")
test_create_group()
get_response = test_get_group()
response = resource_groups.get_group_query(GroupName="test_resource_group")
response["GroupQuery"]["ResourceQuery"]["Type"].should.contain("TAG_FILTERS_1_0")
response_get = resource_groups.get_group_query(
Group=get_response.get("Group").get("GroupArn")
)
response_get["GroupQuery"]["ResourceQuery"]["Type"].should.contain(
"TAG_FILTERS_1_0"
)
@mock_resourcegroups
def test_get_tags():
@ -136,7 +143,7 @@ def test_untag():
def test_update_group():
resource_groups = boto3.client("resource-groups", region_name="us-east-1")
test_get_group()
get_response = test_get_group()
response = resource_groups.update_group(
GroupName="test_resource_group", Description="description_2"
@ -220,7 +227,7 @@ def test_create_group_with_configuration():
def test_update_group_query():
resource_groups = boto3.client("resource-groups", region_name="us-east-1")
test_create_group()
group_response = test_get_group()
response = resource_groups.update_group_query(
GroupName="test_resource_group",
@ -245,3 +252,25 @@ def test_update_group_query():
response["GroupQuery"]["ResourceQuery"]["Type"].should.contain(
"CLOUDFORMATION_STACK_1_0"
)
response = resource_groups.update_group_query(
Group=group_response.get("Group").get("GroupArn"),
ResourceQuery={
"Type": "TAG_FILTERS_1_0",
"Query": json.dumps(
{
"ResourceTypeFilters": ["AWS::AllSupported"],
"TagFilters": [
{"Key": "resources_tag_key", "Values": ["resources_tag_value"]}
],
}
),
},
)
response["GroupQuery"]["ResourceQuery"]["Type"].should.contain("TAG_FILTERS_1_0")
response = resource_groups.get_group_query(
Group=group_response.get("Group").get("GroupArn")
)
response["GroupQuery"]["ResourceQuery"]["Type"].should.contain("TAG_FILTERS_1_0")