feature/refresh_trusted_advisor_check (#3705)
* Support - added refresh_trusted_advisor_check - Returns a random check status - Returns the check id in the response - Testing for these two functionalities * test_support - addressed PR comments, to cycle through a faked number of check status responses
This commit is contained in:
parent
b6d7704b23
commit
e61d794cbc
@ -13,6 +13,7 @@ class SupportBackend(BaseBackend):
|
||||
def __init__(self, region_name=None):
|
||||
super(SupportBackend, self).__init__()
|
||||
self.region_name = region_name
|
||||
self.check_status = {}
|
||||
|
||||
def reset(self):
|
||||
region_name = self.region_name
|
||||
@ -24,6 +25,39 @@ class SupportBackend(BaseBackend):
|
||||
checks = ADVISOR_CHECKS["checks"]
|
||||
return checks
|
||||
|
||||
def refresh_trusted_advisor_check(self, check_id):
|
||||
self.advance_check_status(check_id)
|
||||
status = {
|
||||
"status": {
|
||||
"checkId": check_id,
|
||||
"status": self.check_status[check_id],
|
||||
"millisUntilNextRefreshable": 123,
|
||||
}
|
||||
}
|
||||
return status
|
||||
|
||||
def advance_check_status(self, check_id):
|
||||
"""
|
||||
Fake an advancement through statuses on refreshing TA checks
|
||||
"""
|
||||
if check_id not in self.check_status:
|
||||
self.check_status[check_id] = "none"
|
||||
|
||||
elif self.check_status[check_id] == "none":
|
||||
self.check_status[check_id] = "enqueued"
|
||||
|
||||
elif self.check_status[check_id] == "enqueued":
|
||||
self.check_status[check_id] = "processing"
|
||||
|
||||
elif self.check_status[check_id] == "processing":
|
||||
self.check_status[check_id] = "success"
|
||||
|
||||
elif self.check_status[check_id] == "success":
|
||||
self.check_status[check_id] = "abandoned"
|
||||
|
||||
elif self.check_status[check_id] == "abandoned":
|
||||
self.check_status[check_id] = "none"
|
||||
|
||||
|
||||
support_backends = {}
|
||||
|
||||
|
@ -18,3 +18,9 @@ class SupportResponse(BaseResponse):
|
||||
)
|
||||
|
||||
return json.dumps({"checks": checks})
|
||||
|
||||
def refresh_trusted_advisor_check(self):
|
||||
check_id = self._get_param("checkId")
|
||||
status = self.support_backend.refresh_trusted_advisor_check(check_id=check_id,)
|
||||
|
||||
return json.dumps(status)
|
||||
|
@ -43,3 +43,115 @@ def test_describe_trusted_advisor_checks_returns_an_expected_check_name():
|
||||
check_names.append(check["name"])
|
||||
|
||||
check_names.should.contain("Unassociated Elastic IP Addresses")
|
||||
|
||||
|
||||
@mock_support
|
||||
def test_refresh_trusted_advisor_check_returns_expected_check():
|
||||
"""
|
||||
A refresh of a trusted advisor check returns the check id
|
||||
in the response
|
||||
"""
|
||||
client = boto3.client("support", "us-east-1")
|
||||
check_name = "XXXIIIY"
|
||||
response = client.refresh_trusted_advisor_check(checkId=check_name)
|
||||
response["status"]["checkId"].should.equal(check_name)
|
||||
|
||||
|
||||
@mock_support
|
||||
def test_refresh_trusted_advisor_check_returns_an_expected_status():
|
||||
"""
|
||||
A refresh of a trusted advisor check returns an expected status
|
||||
"""
|
||||
client = boto3.client("support", "us-east-1")
|
||||
possible_statuses = ["none", "enqueued", "processing", "success", "abandoned"]
|
||||
check_name = "XXXIIIY"
|
||||
response = client.refresh_trusted_advisor_check(checkId=check_name)
|
||||
actual_status = [response["status"]["status"]]
|
||||
set(actual_status).issubset(possible_statuses).should.be.true
|
||||
|
||||
|
||||
@mock_support
|
||||
def test_refresh_trusted_advisor_check_cycles_to_new_status_on_each_call():
|
||||
"""
|
||||
On each call, the next expected status is returned
|
||||
"""
|
||||
client = boto3.client("support", "us-east-1")
|
||||
check_name = "XXXIIIY"
|
||||
actual_statuses = []
|
||||
possible_statuses = ["none", "enqueued", "processing", "success", "abandoned"]
|
||||
|
||||
for status in possible_statuses:
|
||||
response = client.refresh_trusted_advisor_check(checkId=check_name)
|
||||
actual_statuses.append(response["status"]["status"])
|
||||
|
||||
actual_statuses.should.equal(possible_statuses)
|
||||
|
||||
|
||||
@mock_support
|
||||
def test_refresh_trusted_advisor_check_cycles_to_new_status_on_each_call():
|
||||
"""
|
||||
Called only three times, only three expected statuses are returned
|
||||
"""
|
||||
client = boto3.client("support", "us-east-1")
|
||||
check_name = "XXXIIIY"
|
||||
actual_statuses = []
|
||||
possible_statuses = ["none", "enqueued", "processing"]
|
||||
|
||||
for status in possible_statuses:
|
||||
response = client.refresh_trusted_advisor_check(checkId=check_name)
|
||||
actual_statuses.append(response["status"]["status"])
|
||||
|
||||
unexpected_statuses = set(["success", "abandoned"]).issubset(actual_statuses)
|
||||
|
||||
actual_statuses.should.equal(
|
||||
possible_statuses
|
||||
) and unexpected_statuses.should.be.false
|
||||
|
||||
|
||||
@mock_support
|
||||
def test_refresh_trusted_advisor_check_cycles_to_new_status_on_with_two_checks():
|
||||
"""
|
||||
On each call, the next expected status is returned when additional checks are made
|
||||
"""
|
||||
client = boto3.client("support", "us-east-1")
|
||||
check_1_name = "XXXIIIY"
|
||||
check_2_name = "XXXIIIZ"
|
||||
check_1_statuses = []
|
||||
check_2_statuses = []
|
||||
possible_statuses = ["none", "enqueued", "processing", "success", "abandoned"]
|
||||
|
||||
for check in possible_statuses:
|
||||
response = client.refresh_trusted_advisor_check(checkId=check_1_name)
|
||||
check_1_statuses.append(response["status"]["status"])
|
||||
|
||||
for check in possible_statuses:
|
||||
response = client.refresh_trusted_advisor_check(checkId=check_2_name)
|
||||
check_2_statuses.append(response["status"]["status"])
|
||||
|
||||
check_1_statuses.should.equal(possible_statuses) and check_2_statuses.should.equal(
|
||||
possible_statuses
|
||||
)
|
||||
|
||||
|
||||
@mock_support
|
||||
def test_refresh_trusted_advisor_check_cycle_continues_on_full_cycle():
|
||||
"""
|
||||
After cycling through all statuses, the check continues the cycle
|
||||
"""
|
||||
|
||||
client = boto3.client("support", "us-east-1")
|
||||
check_name = "XXXIIIY"
|
||||
possible_statuses = [
|
||||
"none",
|
||||
"enqueued",
|
||||
"processing",
|
||||
"success",
|
||||
"abandoned",
|
||||
]
|
||||
|
||||
for status in possible_statuses:
|
||||
client.refresh_trusted_advisor_check(checkId=check_name)
|
||||
|
||||
expected_none_response = client.refresh_trusted_advisor_check(checkId=check_name)
|
||||
|
||||
expected_none_response["status"]["status"].should.equal("none")
|
||||
|
Loading…
Reference in New Issue
Block a user