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