getting tests working in server mode
This commit is contained in:
parent
41af98c98b
commit
20dc8ae5c4
@ -292,22 +292,24 @@ class LambdaFunction(BaseModel):
|
||||
|
||||
return self.get_configuration()
|
||||
|
||||
def update_function_code(self, spec):
|
||||
if 'DryRun' in spec and spec['DryRun']:
|
||||
def update_function_code(self, updated_spec):
|
||||
if 'DryRun' in updated_spec and updated_spec['DryRun']:
|
||||
return self.get_configuration()
|
||||
|
||||
if 'Publish' in spec and spec['Publish']:
|
||||
if 'Publish' in updated_spec and updated_spec['Publish']:
|
||||
self.set_version(self.version + 1)
|
||||
|
||||
if 'ZipFile' in spec:
|
||||
# using the "hackery" from __init__" because it seems to work
|
||||
if 'ZipFile' in updated_spec:
|
||||
self.code['ZipFile'] = updated_spec['ZipFile']
|
||||
|
||||
# using the "hackery" from __init__ because it seems to work
|
||||
# TODOs and FIXMEs included, because they'll need to be fixed
|
||||
# in both places now
|
||||
try:
|
||||
to_unzip_code = base64.b64decode(
|
||||
bytes(spec['ZipFile'], 'utf-8'))
|
||||
bytes(updated_spec['ZipFile'], 'utf-8'))
|
||||
except Exception:
|
||||
to_unzip_code = base64.b64decode(spec['ZipFile'])
|
||||
to_unzip_code = base64.b64decode(updated_spec['ZipFile'])
|
||||
|
||||
self.code_bytes = to_unzip_code
|
||||
self.code_size = len(to_unzip_code)
|
||||
@ -316,11 +318,11 @@ class LambdaFunction(BaseModel):
|
||||
# TODO: we should be putting this in a lambda bucket
|
||||
self.code['UUID'] = str(uuid.uuid4())
|
||||
self.code['S3Key'] = '{}-{}'.format(self.function_name, self.code['UUID'])
|
||||
else:
|
||||
elif 'S3Bucket' in updated_spec and 'S3Key' in updated_spec:
|
||||
key = None
|
||||
try:
|
||||
# FIXME: does not validate bucket region
|
||||
key = s3_backend.get_key(spec['S3Bucket'], spec['S3Key'])
|
||||
key = s3_backend.get_key(updated_spec['S3Bucket'], updated_spec['S3Key'])
|
||||
except MissingBucket:
|
||||
if do_validate_s3():
|
||||
raise ValueError(
|
||||
|
@ -123,14 +123,16 @@ class LambdaResponse(BaseResponse):
|
||||
return self._add_policy(request, full_url, headers)
|
||||
|
||||
def configuration(self, request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
if request.method == 'PUT':
|
||||
return self._put_configuration(request, full_url)
|
||||
return self._put_configuration(request)
|
||||
else:
|
||||
raise ValueError("Cannot handle request")
|
||||
|
||||
def code(self, request, full_url, headers):
|
||||
self.setup_class(request, full_url, headers)
|
||||
if request.method == 'PUT':
|
||||
return self._put_code(request, full_url, headers)
|
||||
return self._put_code()
|
||||
else:
|
||||
raise ValueError("Cannot handle request")
|
||||
|
||||
@ -321,26 +323,26 @@ class LambdaResponse(BaseResponse):
|
||||
else:
|
||||
return 404, {}, "{}"
|
||||
|
||||
def _put_configuration(self, request, full_url):
|
||||
function_name = self._get_param('FunctionName', None)
|
||||
def _put_configuration(self, request):
|
||||
function_name = self.path.rsplit('/', 2)[-2]
|
||||
qualifier = self._get_param('Qualifier', None)
|
||||
|
||||
fn = self.lambda_backend.get_function(function_name, qualifier)
|
||||
|
||||
if fn:
|
||||
config = fn.update_configuration(json.loads(request.body))
|
||||
config = fn.update_configuration(self.json_body)
|
||||
return 200, {}, json.dumps(config)
|
||||
else:
|
||||
return 404, {}, "{}"
|
||||
|
||||
def _put_code(self, request, full_url, headers):
|
||||
function_name = self._get_param('FunctionName', None)
|
||||
def _put_code(self):
|
||||
function_name = self.path.rsplit('/', 2)[-2]
|
||||
qualifier = self._get_param('Qualifier', None)
|
||||
|
||||
fn = self.lambda_backend.get_function(function_name, qualifier)
|
||||
|
||||
if fn:
|
||||
config = fn.update_function_code(json.loads(request.body))
|
||||
config = fn.update_function_code(self.json_body)
|
||||
return 200, {}, json.dumps(config)
|
||||
else:
|
||||
return 404, {}, "{}"
|
||||
|
@ -1295,7 +1295,6 @@ def test_update_configuration():
|
||||
|
||||
|
||||
@mock_lambda
|
||||
@freeze_time('2015-01-01 00:00:00')
|
||||
def test_update_function():
|
||||
conn = boto3.client('lambda', 'us-west-2')
|
||||
|
||||
@ -1317,7 +1316,7 @@ def test_update_function():
|
||||
|
||||
zip_content_two = get_test_zip_file2()
|
||||
|
||||
conn.update_function_code(
|
||||
fxn_updated = conn.update_function_code(
|
||||
FunctionName='testFunction',
|
||||
ZipFile=zip_content_two,
|
||||
Publish=True
|
||||
|
Loading…
Reference in New Issue
Block a user