Merge pull request #2460 from EDITD/master

Add Tags to UsagePlan Model - API Gateway
This commit is contained in:
Steve Pulec 2019-10-08 09:33:47 -05:00 committed by GitHub
commit 1f9f86e97b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 14 deletions

View File

@ -332,15 +332,16 @@ class ApiKey(BaseModel, dict):
class UsagePlan(BaseModel, dict):
def __init__(self, name=None, description=None, apiStages=[],
throttle=None, quota=None):
def __init__(self, name=None, description=None, apiStages=None,
throttle=None, quota=None, tags=None):
super(UsagePlan, self).__init__()
self['id'] = create_id()
self['name'] = name
self['description'] = description
self['apiStages'] = apiStages
self['apiStages'] = apiStages if apiStages else []
self['throttle'] = throttle
self['quota'] = quota
self['tags'] = tags
class UsagePlanKey(BaseModel, dict):

View File

@ -1029,20 +1029,27 @@ def test_usage_plans():
usage_plan['name'].should.equal(usage_plan_name)
usage_plan['apiStages'].should.equal([])
usage_plan_name = 'TEST-PLAN-2'
usage_plan_description = 'Description'
usage_plan_quota = {'limit': 10, 'period': 'DAY', 'offset': 0}
usage_plan_throttle = {'rateLimit': 2, 'burstLimit': 1}
usage_plan_api_stages = [{'apiId': 'foo', 'stage': 'bar'}]
payload = {'name': usage_plan_name, 'description': usage_plan_description, 'quota': usage_plan_quota, 'throttle': usage_plan_throttle, 'apiStages': usage_plan_api_stages}
payload = {
'name': 'TEST-PLAN-2',
'description': 'Description',
'quota': {'limit': 10, 'period': 'DAY', 'offset': 0},
'throttle': {'rateLimit': 2, 'burstLimit': 1},
'apiStages': [{'apiId': 'foo', 'stage': 'bar'}],
'tags': {'tag_key': 'tag_value'},
}
response = client.create_usage_plan(**payload)
usage_plan_id = response['id']
usage_plan = client.get_usage_plan(usagePlanId=usage_plan_id)
usage_plan['name'].should.equal(usage_plan_name)
usage_plan['description'].should.equal(usage_plan_description)
usage_plan['apiStages'].should.equal(usage_plan_api_stages)
usage_plan['throttle'].should.equal(usage_plan_throttle)
usage_plan['quota'].should.equal(usage_plan_quota)
# The payload should remain unchanged
for key, value in payload.items():
usage_plan.should.have.key(key).which.should.equal(value)
# Status code should be 200
usage_plan['ResponseMetadata'].should.have.key('HTTPStatusCode').which.should.equal(200)
# An Id should've been generated
usage_plan.should.have.key('id').which.should_not.be.none
response = client.get_usage_plans()
len(response['items']).should.equal(2)