Skip to content

Commit 644ce28

Browse files
committed
improved test_deploy_lambda__to_aws
1 parent 0434ce1 commit 644ce28

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

osbot_fast_api_serverless/deploy/Deploy__Serverless__Fast_API.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from osbot_utils.utils.Objects import obj
12
from osbot_aws.aws.lambda_.Lambda import DEFAULT__LAMBDA__EPHEMERAL_STORAGE, DEFAULT__LAMBDA__MEMORY_SIZE
23
from osbot_aws.aws.lambda_.dependencies.Lambda__Dependency import Lambda__Dependency
34
from osbot_utils.helpers.Random_Guid import Random_Guid
@@ -39,13 +40,13 @@ def deploy_lambda(self):
3940
ephemeral_storage = self.ephemeral_storage,
4041
memory_size = self.memory_size )
4142
with Deploy_Lambda(run, **kwargs) as _:
42-
#_.add_osbot_aws()
4343
_.add_file__boto3__lambda() # this file allows the dynamically load of dependencies
4444
_.set_env_variable(ENV_VAR__FAST_API__AUTH__API_KEY__NAME , self.api_key__name ())
4545
_.set_env_variable(ENV_VAR__FAST_API__AUTH__API_KEY__VALUE, self.api_key__value())
4646
return _
4747

48-
# main methods
48+
def delete_function(self):
49+
return self.lambda_function().delete()
4950

5051

5152
def create_or_update__lambda_function(self):
@@ -68,12 +69,17 @@ def create__lambda_function__url(self):
6869
function_url = result.get('function_url_create').get('FunctionUrl')
6970
return function_url
7071

72+
def lambda_configuration(self):
73+
return obj(self.lambda_function().info().get('Configuration'))
74+
7175
def lambda_name(self):
7276
return BASE__LAMBDA_NAME__FAST_API__SERVERLESS
7377

7478
def lambda_function(self):
7579
return self.deploy_lambda().lambda_function()
7680

81+
82+
7783
def lambda_files_bucket_name(self):
7884
return self.lambda_function().s3_bucket
7985

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import pytest
22
from unittest import TestCase
3+
from osbot_fast_api.api.Fast_API import ENV_VAR__FAST_API__AUTH__API_KEY__NAME, ENV_VAR__FAST_API__AUTH__API_KEY__VALUE
4+
from osbot_utils.utils.Env import get_env
5+
from osbot_utils.utils.Objects import __
36
from osbot_fast_api_serverless.deploy.Deploy__Serverless__Fast_API import Deploy__Serverless__Fast_API
47

58

@@ -8,10 +11,52 @@ class test_deploy_lambda__to_aws(TestCase):
811
@classmethod
912
def setUpClass(cls):
1013
cls.deploy_fast_api = Deploy__Serverless__Fast_API()
14+
cls.aws_config = cls.deploy_fast_api.aws_config
15+
cls.account_id = cls.aws_config.account_id()
16+
cls.region_name = cls.aws_config.region_name()
1117
with cls.deploy_fast_api as _:
1218
if _.aws_config.aws_configured() is False:
1319
pytest.skip("this test needs valid AWS credentials")
20+
assert cls.deploy_fast_api.s3().client().meta.endpoint_url == f'https://s3.{cls.aws_config.region_name()}.amazonaws.com'
1421

15-
def test__init__(self):
22+
def test___init__(self):
1623
with self.deploy_fast_api as _:
17-
assert type(_) is Deploy__Serverless__Fast_API
24+
assert type(_) is Deploy__Serverless__Fast_API
25+
26+
def test_1__upload_lambda_dependencies_to_s3(self):
27+
with self.deploy_fast_api as _:
28+
_.upload_lambda_dependencies_to_s3()
29+
bucket = _.lambda_files_bucket_name()
30+
assert 'lambdas-dependencies/osbot-fast-api.zip' in _.s3().find_files(bucket, 'lambdas-dependencies')
31+
32+
def test_2__create_or_update__lambda_function(self):
33+
with self.deploy_fast_api as _:
34+
assert _.create_or_update__lambda_function() is True
35+
assert _.create__lambda_function__url ().endswith('.lambda-url.eu-west-1.on.aws/')
36+
assert _.lambda_function().exists () is True
37+
38+
39+
40+
def test_3__lambda_configuration(self):
41+
with self.deploy_fast_api.lambda_configuration() as _:
42+
assert _.Architectures == ['x86_64']
43+
assert _.Handler == 'osbot_fast_api_serverless.fast_api.lambda_handler.run'
44+
assert _.CodeSize < 10000
45+
assert _.Environment.Variables == __(FAST_API__AUTH__API_KEY__NAME = get_env(ENV_VAR__FAST_API__AUTH__API_KEY__NAME ),
46+
FAST_API__AUTH__API_KEY__VALUE = get_env(ENV_VAR__FAST_API__AUTH__API_KEY__VALUE))
47+
assert _.EphemeralStorage == __(Size=512)
48+
assert _.FunctionName == 'fast-api__serverless__dev'
49+
assert _.FunctionArn == f'arn:aws:lambda:{self.region_name}:{self.account_id}:function:fast-api__serverless__dev'
50+
assert _.LastUpdateStatus == 'Successful'
51+
assert _.LoggingConfig ==__(LogFormat = 'Text' ,
52+
LogGroup = '/aws/lambda/fast-api__serverless__dev')
53+
54+
assert _.MemorySize == 512
55+
assert _.Role == f'arn:aws:iam::{self.account_id}:role/temp_role_for_lambda_invocation'
56+
assert _.Runtime == 'python3.11'
57+
assert _.State == 'Active'
58+
assert _.Timeout == 60
59+
60+
def test_4__delete_function(self):
61+
with self.deploy_fast_api as _:
62+
assert _.delete_function() is True

0 commit comments

Comments
 (0)