11import pytest
22from 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 __
36from 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