Fixed apigateway usage plan api when dealing with non existing usage plans and non existing api keys
This commit is contained in:
parent
e09dfac95b
commit
05860fcdd1
5 changed files with 101 additions and 2 deletions
|
|
@ -1797,6 +1797,14 @@ def test_usage_plans():
|
|||
response = client.get_usage_plans()
|
||||
len(response["items"]).should.equal(0)
|
||||
|
||||
# # Try to get info about a non existing usage
|
||||
with assert_raises(ClientError) as ex:
|
||||
client.get_usage_plan(usagePlanId="not_existing")
|
||||
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"Invalid Usage Plan ID specified"
|
||||
)
|
||||
|
||||
usage_plan_name = "TEST-PLAN"
|
||||
payload = {"name": usage_plan_name}
|
||||
response = client.create_usage_plan(**payload)
|
||||
|
|
@ -1879,6 +1887,30 @@ def test_usage_plan_keys():
|
|||
response = client.get_usage_plan_keys(usagePlanId=usage_plan_id)
|
||||
len(response["items"]).should.equal(0)
|
||||
|
||||
# Try to get info about a non existing api key
|
||||
with assert_raises(ClientError) as ex:
|
||||
client.get_usage_plan_key(usagePlanId=usage_plan_id, keyId="not_existing_key")
|
||||
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"Invalid API Key identifier specified"
|
||||
)
|
||||
|
||||
# Try to get info about an existing api key that has not jet added to a valid usage plan
|
||||
with assert_raises(ClientError) as ex:
|
||||
client.get_usage_plan_key(usagePlanId=usage_plan_id, keyId=key_id)
|
||||
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"Invalid Usage Plan ID specified"
|
||||
)
|
||||
|
||||
# Try to get info about an existing api key that has not jet added to a valid usage plan
|
||||
with assert_raises(ClientError) as ex:
|
||||
client.get_usage_plan_key(usagePlanId="not_existing_plan_id", keyId=key_id)
|
||||
ex.exception.response["Error"]["Code"].should.equal("NotFoundException")
|
||||
ex.exception.response["Error"]["Message"].should.equal(
|
||||
"Invalid Usage Plan ID specified"
|
||||
)
|
||||
|
||||
|
||||
@mock_apigateway
|
||||
def test_create_usage_plan_key_non_existent_api_key():
|
||||
|
|
|
|||
|
|
@ -39,6 +39,10 @@ def test_usage_plans_apis():
|
|||
fetched_plan = json.loads(res.data)
|
||||
fetched_plan.should.equal(created_plan)
|
||||
|
||||
# Not existing usage plan
|
||||
res = test_client.get("/usageplans/{0}".format("not_existing"))
|
||||
res.status_code.should.equal(404)
|
||||
|
||||
# Delete usage plan
|
||||
res = test_client.delete("/usageplans/{0}".format(created_plan["id"]))
|
||||
res.data.should.equal(b"{}")
|
||||
|
|
@ -61,6 +65,24 @@ def test_usage_plans_keys():
|
|||
res = test_client.get("/usageplans/{0}/keys".format(usage_plan_id))
|
||||
json.loads(res.data)["item"].should.have.length_of(0)
|
||||
|
||||
# Invalid api key (does not exists at all)
|
||||
res = test_client.get(
|
||||
"/usageplans/{0}/keys/{1}".format(usage_plan_id, "not_existing")
|
||||
)
|
||||
res.status_code.should.equal(404)
|
||||
|
||||
# not existing usage plan with existing api key
|
||||
res = test_client.get(
|
||||
"/usageplans/{0}/keys/{1}".format("not_existing", created_api_key["id"])
|
||||
)
|
||||
res.status_code.should.equal(404)
|
||||
|
||||
# not jet added api key
|
||||
res = test_client.get(
|
||||
"/usageplans/{0}/keys/{1}".format(usage_plan_id, created_api_key["id"])
|
||||
)
|
||||
res.status_code.should.equal(404)
|
||||
|
||||
# Create usage plan key
|
||||
res = test_client.post(
|
||||
"/usageplans/{0}/keys".format(usage_plan_id),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue