don't set cacheClusterSize if cache not enabled
This commit is contained in:
parent
f1454ee280
commit
dd85f35f5a
@ -155,7 +155,8 @@ class Resource(object):
|
|||||||
class Stage(dict):
|
class Stage(dict):
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, name=None, deployment_id=None, variables=None):
|
def __init__(self, name=None, deployment_id=None, variables=None,
|
||||||
|
description='',cacheClusterEnabled=False,cacheClusterSize=None):
|
||||||
super(Stage, self).__init__()
|
super(Stage, self).__init__()
|
||||||
if variables is None:
|
if variables is None:
|
||||||
variables = {}
|
variables = {}
|
||||||
@ -163,9 +164,13 @@ class Stage(dict):
|
|||||||
self['deploymentId'] = deployment_id
|
self['deploymentId'] = deployment_id
|
||||||
self['methodSettings'] = {}
|
self['methodSettings'] = {}
|
||||||
self['variables'] = variables
|
self['variables'] = variables
|
||||||
self['description'] = ''
|
self['description'] = description
|
||||||
self['cacheClusterEnabled'] = False
|
self['cacheClusterEnabled'] = cacheClusterEnabled
|
||||||
self['cacheClusterSize'] = 0.5
|
if self['cacheClusterEnabled']:
|
||||||
|
self['cacheClusterSize'] = str(0.5)
|
||||||
|
|
||||||
|
if cacheClusterSize is not None:
|
||||||
|
self['cacheClusterSize'] = str(cacheClusterSize)
|
||||||
|
|
||||||
def apply_operations(self, patch_operations):
|
def apply_operations(self, patch_operations):
|
||||||
for op in patch_operations:
|
for op in patch_operations:
|
||||||
@ -173,8 +178,10 @@ class Stage(dict):
|
|||||||
self._apply_operation_to_variables(op)
|
self._apply_operation_to_variables(op)
|
||||||
elif '/cacheClusterEnabled' in op['path']:
|
elif '/cacheClusterEnabled' in op['path']:
|
||||||
self['cacheClusterEnabled'] = self._str2bool(op['value'])
|
self['cacheClusterEnabled'] = self._str2bool(op['value'])
|
||||||
|
if 'cacheClusterSize' not in self and self['cacheClusterEnabled']:
|
||||||
|
self['cacheClusterSize'] = str(0.5)
|
||||||
elif '/cacheClusterSize' in op['path']:
|
elif '/cacheClusterSize' in op['path']:
|
||||||
self['cacheClusterSize'] = float(op['value'])
|
self['cacheClusterSize'] = str(float(op['value']))
|
||||||
elif '/description' in op['path']:
|
elif '/description' in op['path']:
|
||||||
self['description'] = op['value']
|
self['description'] = op['value']
|
||||||
elif '/deploymentId' in op['path']:
|
elif '/deploymentId' in op['path']:
|
||||||
@ -324,10 +331,11 @@ class RestAPI(object):
|
|||||||
for method in httpretty.httpretty.METHODS:
|
for method in httpretty.httpretty.METHODS:
|
||||||
httpretty.register_uri(method, stage_url, body=self.resource_callback)
|
httpretty.register_uri(method, stage_url, body=self.resource_callback)
|
||||||
|
|
||||||
def create_stage(self, name, deployment_id,variables=None):
|
def create_stage(self, name, deployment_id,variables=None,description='',cacheClusterEnabled=None,cacheClusterSize=None):
|
||||||
if variables is None:
|
if variables is None:
|
||||||
variables = {}
|
variables = {}
|
||||||
stage = Stage(name=name, deployment_id=deployment_id,variables=variables)
|
stage = Stage(name=name, deployment_id=deployment_id,variables=variables,
|
||||||
|
description=description,cacheClusterSize=cacheClusterSize,cacheClusterEnabled=cacheClusterEnabled)
|
||||||
self.stages[name] = stage
|
self.stages[name] = stage
|
||||||
self.update_integration_mocks(name)
|
self.update_integration_mocks(name)
|
||||||
return stage
|
return stage
|
||||||
@ -429,11 +437,13 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
return api.get_stages()
|
return api.get_stages()
|
||||||
|
|
||||||
|
|
||||||
def create_stage(self, function_id, stage_name, deploymentId,variables=None):
|
def create_stage(self, function_id, stage_name, deploymentId,
|
||||||
|
variables=None,description='',cacheClusterEnabled=None,cacheClusterSize=None):
|
||||||
if variables is None:
|
if variables is None:
|
||||||
variables = {}
|
variables = {}
|
||||||
api = self.get_rest_api(function_id)
|
api = self.get_rest_api(function_id)
|
||||||
api.create_stage(stage_name,deploymentId,variables)
|
api.create_stage(stage_name,deploymentId,variables=variables,
|
||||||
|
description=description,cacheClusterEnabled=cacheClusterEnabled,cacheClusterSize=cacheClusterSize)
|
||||||
return api.stages.get(stage_name)
|
return api.stages.get(stage_name)
|
||||||
|
|
||||||
def update_stage(self, function_id, stage_name, patch_operations):
|
def update_stage(self, function_id, stage_name, patch_operations):
|
||||||
|
@ -114,8 +114,13 @@ class APIGatewayResponse(BaseResponse):
|
|||||||
stage_name = self._get_param("stageName")
|
stage_name = self._get_param("stageName")
|
||||||
deployment_id = self._get_param("deploymentId")
|
deployment_id = self._get_param("deploymentId")
|
||||||
stage_variables = self._get_param_with_default_value('variables',{})
|
stage_variables = self._get_param_with_default_value('variables',{})
|
||||||
|
description = self._get_param_with_default_value('description','')
|
||||||
|
cacheClusterEnabled = self._get_param_with_default_value('cacheClusterEnabled',False)
|
||||||
|
cacheClusterSize = self._get_param_with_default_value('cacheClusterSize',None)
|
||||||
|
|
||||||
stage_response = self.backend.create_stage(function_id, stage_name, deployment_id,variables=stage_variables)
|
stage_response = self.backend.create_stage(function_id, stage_name, deployment_id,
|
||||||
|
variables=stage_variables, description=description,
|
||||||
|
cacheClusterEnabled=cacheClusterEnabled, cacheClusterSize=cacheClusterSize)
|
||||||
elif self.method == 'GET':
|
elif self.method == 'GET':
|
||||||
stages = self.backend.get_stages(function_id)
|
stages = self.backend.get_stages(function_id)
|
||||||
return 200, headers, json.dumps({"item": stages})
|
return 200, headers, json.dumps({"item": stages})
|
||||||
|
@ -515,6 +515,40 @@ def test_update_stage_configuration():
|
|||||||
)
|
)
|
||||||
stage['stageName'].should.equal(stage_name)
|
stage['stageName'].should.equal(stage_name)
|
||||||
stage['deploymentId'].should.equal(deployment_id2)
|
stage['deploymentId'].should.equal(deployment_id2)
|
||||||
|
stage.shouldnt.have.key('cacheClusterSize')
|
||||||
|
|
||||||
|
client.update_stage(restApiId=api_id,stageName=stage_name,
|
||||||
|
patchOperations=[
|
||||||
|
{
|
||||||
|
"op" : "replace",
|
||||||
|
"path" : "/cacheClusterEnabled",
|
||||||
|
"value": "True"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
stage = client.get_stage(
|
||||||
|
restApiId=api_id,
|
||||||
|
stageName=stage_name
|
||||||
|
)
|
||||||
|
|
||||||
|
stage.should.have.key('cacheClusterSize').which.should.equal("0.5")
|
||||||
|
|
||||||
|
client.update_stage(restApiId=api_id,stageName=stage_name,
|
||||||
|
patchOperations=[
|
||||||
|
{
|
||||||
|
"op" : "replace",
|
||||||
|
"path" : "/cacheClusterSize",
|
||||||
|
"value": "1.6"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
stage = client.get_stage(
|
||||||
|
restApiId=api_id,
|
||||||
|
stageName=stage_name
|
||||||
|
)
|
||||||
|
|
||||||
|
stage.should.have.key('cacheClusterSize').which.should.equal("1.6")
|
||||||
|
|
||||||
|
|
||||||
client.update_stage(restApiId=api_id,stageName=stage_name,
|
client.update_stage(restApiId=api_id,stageName=stage_name,
|
||||||
patchOperations=[
|
patchOperations=[
|
||||||
@ -567,7 +601,7 @@ def test_update_stage_configuration():
|
|||||||
stage = client.get_stage(restApiId=api_id,stageName=stage_name)
|
stage = client.get_stage(restApiId=api_id,stageName=stage_name)
|
||||||
|
|
||||||
stage['description'].should.match('stage description update')
|
stage['description'].should.match('stage description update')
|
||||||
stage['cacheClusterSize'].should.equal(1.6)
|
stage['cacheClusterSize'].should.equal("1.6")
|
||||||
stage['variables']['environment'].should.match('dev')
|
stage['variables']['environment'].should.match('dev')
|
||||||
stage['variables'].should_not.have.key('region')
|
stage['variables'].should_not.have.key('region')
|
||||||
stage['cacheClusterEnabled'].should.be.true
|
stage['cacheClusterEnabled'].should.be.true
|
||||||
@ -662,10 +696,16 @@ def test_create_stage():
|
|||||||
'variables':{},
|
'variables':{},
|
||||||
'ResponseMetadata': {'HTTPStatusCode': 200},
|
'ResponseMetadata': {'HTTPStatusCode': 200},
|
||||||
'description':'',
|
'description':'',
|
||||||
'cacheClusterSize':0.5,
|
|
||||||
'cacheClusterEnabled':False
|
'cacheClusterEnabled':False
|
||||||
})
|
})
|
||||||
|
|
||||||
|
stage = client.get_stage(
|
||||||
|
restApiId=api_id,
|
||||||
|
stageName=new_stage_name
|
||||||
|
)
|
||||||
|
stage['stageName'].should.equal(new_stage_name)
|
||||||
|
stage['deploymentId'].should.equal(deployment_id2)
|
||||||
|
|
||||||
new_stage_name_with_vars = 'stage_with_vars'
|
new_stage_name_with_vars = 'stage_with_vars'
|
||||||
response = client.create_stage(restApiId=api_id,stageName=new_stage_name_with_vars,deploymentId=deployment_id2,variables={
|
response = client.create_stage(restApiId=api_id,stageName=new_stage_name_with_vars,deploymentId=deployment_id2,variables={
|
||||||
"env" : "dev"
|
"env" : "dev"
|
||||||
@ -680,17 +720,9 @@ def test_create_stage():
|
|||||||
'variables':{ "env" : "dev" },
|
'variables':{ "env" : "dev" },
|
||||||
'ResponseMetadata': {'HTTPStatusCode': 200},
|
'ResponseMetadata': {'HTTPStatusCode': 200},
|
||||||
'description':'',
|
'description':'',
|
||||||
'cacheClusterSize':0.5,
|
'cacheClusterEnabled': False
|
||||||
'cacheClusterEnabled':False
|
|
||||||
})
|
})
|
||||||
|
|
||||||
stage = client.get_stage(
|
|
||||||
restApiId=api_id,
|
|
||||||
stageName=new_stage_name
|
|
||||||
)
|
|
||||||
stage['stageName'].should.equal(new_stage_name)
|
|
||||||
stage['deploymentId'].should.equal(deployment_id2)
|
|
||||||
|
|
||||||
stage = client.get_stage(
|
stage = client.get_stage(
|
||||||
restApiId=api_id,
|
restApiId=api_id,
|
||||||
stageName=new_stage_name_with_vars
|
stageName=new_stage_name_with_vars
|
||||||
@ -699,6 +731,57 @@ def test_create_stage():
|
|||||||
stage['deploymentId'].should.equal(deployment_id2)
|
stage['deploymentId'].should.equal(deployment_id2)
|
||||||
stage['variables'].should.have.key('env').which.should.match("dev")
|
stage['variables'].should.have.key('env').which.should.match("dev")
|
||||||
|
|
||||||
|
new_stage_name = 'stage_with_vars_and_cache_settings'
|
||||||
|
response = client.create_stage(restApiId=api_id,stageName=new_stage_name,deploymentId=deployment_id2,variables={
|
||||||
|
"env" : "dev"
|
||||||
|
}, cacheClusterEnabled=True,description="hello moto")
|
||||||
|
|
||||||
|
response['ResponseMetadata'].pop('HTTPHeaders', None) # this is hard to match against, so remove it
|
||||||
|
|
||||||
|
response.should.equal({
|
||||||
|
'stageName':new_stage_name,
|
||||||
|
'deploymentId':deployment_id2,
|
||||||
|
'methodSettings':{},
|
||||||
|
'variables':{ "env" : "dev" },
|
||||||
|
'ResponseMetadata': {'HTTPStatusCode': 200},
|
||||||
|
'description':'hello moto',
|
||||||
|
'cacheClusterEnabled': True,
|
||||||
|
'cacheClusterSize' : "0.5"
|
||||||
|
})
|
||||||
|
|
||||||
|
stage = client.get_stage(
|
||||||
|
restApiId=api_id,
|
||||||
|
stageName=new_stage_name
|
||||||
|
)
|
||||||
|
|
||||||
|
stage['cacheClusterSize'].should.equal("0.5")
|
||||||
|
|
||||||
|
new_stage_name = 'stage_with_vars_and_cache_settings_and_size'
|
||||||
|
response = client.create_stage(restApiId=api_id,stageName=new_stage_name,deploymentId=deployment_id2,variables={
|
||||||
|
"env" : "dev"
|
||||||
|
}, cacheClusterEnabled=True,cacheClusterSize="1.6",description="hello moto")
|
||||||
|
|
||||||
|
response['ResponseMetadata'].pop('HTTPHeaders', None) # this is hard to match against, so remove it
|
||||||
|
|
||||||
|
response.should.equal({
|
||||||
|
'stageName':new_stage_name,
|
||||||
|
'deploymentId':deployment_id2,
|
||||||
|
'methodSettings':{},
|
||||||
|
'variables':{ "env" : "dev" },
|
||||||
|
'ResponseMetadata': {'HTTPStatusCode': 200},
|
||||||
|
'description':'hello moto',
|
||||||
|
'cacheClusterEnabled': True,
|
||||||
|
'cacheClusterSize' : "1.6"
|
||||||
|
})
|
||||||
|
|
||||||
|
stage = client.get_stage(
|
||||||
|
restApiId=api_id,
|
||||||
|
stageName=new_stage_name
|
||||||
|
)
|
||||||
|
stage['stageName'].should.equal(new_stage_name)
|
||||||
|
stage['deploymentId'].should.equal(deployment_id2)
|
||||||
|
stage['variables'].should.have.key('env').which.should.match("dev")
|
||||||
|
stage['cacheClusterSize'].should.equal("1.6")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user