diff --git a/osbot_local_stack/aws/lambdas/workflows/s3_events.py b/osbot_local_stack/aws/lambdas/workflows/s3_events.py index d282c50..9ad2b69 100644 --- a/osbot_local_stack/aws/lambdas/workflows/s3_events.py +++ b/osbot_local_stack/aws/lambdas/workflows/s3_events.py @@ -1,4 +1,5 @@ -from osbot_local_stack.utils.Version import version__osbot_local_stack +import requests def run(event, context): - return f'current version: {version__osbot_local_stack}' \ No newline at end of file + result = requests.get('https://httpbin.org/get') + return f'{result.status_code}' diff --git a/osbot_local_stack/testing/TestCase__Local_Stack.py b/osbot_local_stack/testing/TestCase__Local_Stack.py index bcb869d..5fd9202 100644 --- a/osbot_local_stack/testing/TestCase__Local_Stack.py +++ b/osbot_local_stack/testing/TestCase__Local_Stack.py @@ -14,6 +14,8 @@ def setUpClass(cls): cls.temp_asw_credentials.set_vars() if cls.aws_region is None: cls.aws_region = aws_config.region_name() + else: + aws_config.set_region(cls.aws_region) cls.local_stack.activate() @classmethod diff --git a/tests/integration/aws/lambdas/dev/test_with__osbot_utils.py b/tests/integration/aws/lambdas/dev/test_with__osbot_utils.py index daf5fc3..c7ef65e 100644 --- a/tests/integration/aws/lambdas/dev/test_with__osbot_utils.py +++ b/tests/integration/aws/lambdas/dev/test_with__osbot_utils.py @@ -2,7 +2,7 @@ from osbot_local_stack.utils.Version import version__osbot_local_stack from osbot_local_stack.testing.TestCase__Local_Stack__Temp_Lambda import TestCase__Local_Stack__Temp_Lambda -class test_hello_world(TestCase__Local_Stack__Temp_Lambda): +class test_with__osbot_utils(TestCase__Local_Stack__Temp_Lambda): @classmethod def setUpClass(cls): diff --git a/tests/integration/aws/lambdas/workflows/test_s3_events.py b/tests/integration/aws/lambdas/workflows/test_s3_events.py index a55a673..d979890 100644 --- a/tests/integration/aws/lambdas/workflows/test_s3_events.py +++ b/tests/integration/aws/lambdas/workflows/test_s3_events.py @@ -1,22 +1,55 @@ +import pytest + +from osbot_utils.utils.Env import set_env + +from osbot_aws.deploy.Deploy_Lambda import Deploy_Lambda + +from osbot_aws.AWS_Config import aws_config + +from osbot_aws.aws.lambda_.Lambda import Lambda + +from osbot_local_stack.testing.TestCase__Local_Stack import TestCase__Local_Stack +from osbot_utils.utils.Dev import pprint from osbot_local_stack.aws.lambdas.workflows.s3_events import run from osbot_local_stack.utils.Version import version__osbot_local_stack -from osbot_local_stack.testing.TestCase__Local_Stack__Temp_Lambda import TestCase__Local_Stack__Temp_Lambda - -class test_hello_world(TestCase__Local_Stack__Temp_Lambda): +from osbot_local_stack.testing.TestCase__Local_Stack__Temp_Lambda import TestCase__Local_Stack__Temp_Lambda, \ + LAMBDA__DEPENDENCIES__REQUESTS - @classmethod - def setUpClass(cls): - cls.lambda_handler = run - super().setUpClass() - @classmethod - def tearDownClass(cls): - super().tearDownClass() +class test_s3_events__create_bucket_and_lambda(TestCase__Local_Stack__Temp_Lambda): + lambda_handler = run + #delete_after_run = False @classmethod def create_temp_lambda(cls): cls.deploy_lambda.add_osbot_utils() + cls.deploy_lambda.add_modules(LAMBDA__DEPENDENCIES__REQUESTS) super().create_temp_lambda() def test_invoke(self): - assert self.lambda_function.invoke() == f'current version: {version__osbot_local_stack}' + response = self.lambda_function.invoke() + assert response == '200' + +@pytest.mark.skip("Only for local development") +class test_s3_events(TestCase__Local_Stack): + aws_region = 'sa-east-1' #'ap-south-1' + s3_bucket = "local-stack-jfpzjbftqgxd" + lambda_handler = run + + def setUp(self): + set_env('OSBOT_LAMBDA_S3_BUCKET', self.s3_bucket) + + def test_invoke(self): + + with Deploy_Lambda(handler=self.lambda_handler) as _: + _.add_osbot_utils() + _.add_modules(LAMBDA__DEPENDENCIES__REQUESTS) + _.update() + response = _.invoke() + pprint(response) + +# *** Skipping delete Lambda function: osbot_local_stack.aws.lambdas.workflows.s3_events +# *** Skipping delete bucket *** +# *** bucket name: local-stack-jfpzjbftqgxd +# *** region name: sa-east-1 +