Skip to content

Commit

Permalink
started adding lamdba/workflows/s3_events
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Oct 15, 2024
1 parent e24b678 commit c62b883
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
5 changes: 3 additions & 2 deletions osbot_local_stack/aws/lambdas/workflows/s3_events.py
Original file line number Diff line number Diff line change
@@ -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}'
result = requests.get('https://httpbin.org/get')
return f'{result.status_code}'
2 changes: 2 additions & 0 deletions osbot_local_stack/testing/TestCase__Local_Stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
55 changes: 44 additions & 11 deletions tests/integration/aws/lambdas/workflows/test_s3_events.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c62b883

Please sign in to comment.