Skip to content

Commit d4f4d3b

Browse files
committed
added test_deploy_lambda__to_aws__dev__qa__prod
1 parent 65d33ec commit d4f4d3b

4 files changed

Lines changed: 67 additions & 7 deletions

File tree

osbot_fast_api_serverless/deploy/Deploy__Serverless__Fast_API.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from osbot_utils.utils.Http import GET_json
12
from osbot_utils.utils.Objects import obj
23
from osbot_aws.aws.lambda_.Lambda import DEFAULT__LAMBDA__EPHEMERAL_STORAGE, DEFAULT__LAMBDA__MEMORY_SIZE
34
from osbot_aws.aws.lambda_.dependencies.Lambda__Dependency import Lambda__Dependency
@@ -13,7 +14,10 @@
1314
from osbot_fast_api_serverless.deploy.Schema__AWS_Setup__Serverless__Fast_API import Schema__AWS_Setup__Serverless__Fast_API
1415

1516
BASE__LAMBDA_NAME__FAST_API__SERVERLESS = 'fast-api__serverless' # make this a Safe_Str__Lambda_Name
16-
17+
DEFAULT__ERROR_MESSAGE__WHEN_FAST_API_IS_OK = ('The adapter was unable to infer a handler to use for the '
18+
'event. This is likely related to how the Lambda function was '
19+
'invoked. (Are you testing locally? Make sure the request '
20+
'payload is valid for a supported handler.)')
1721

1822
class Deploy__Serverless__Fast_API(Type_Safe):
1923
aws_config : AWS_Config
@@ -45,9 +49,14 @@ def deploy_lambda(self):
4549
_.set_env_variable(ENV_VAR__FAST_API__AUTH__API_KEY__VALUE, self.api_key__value())
4650
return _
4751

48-
def delete_function(self):
52+
def delete(self):
4953
return self.lambda_function().delete()
5054

55+
def create(self):
56+
if self.create_or_update__lambda_function():
57+
self.create__lambda_function__url()
58+
return True
59+
return False
5160

5261
def create_or_update__lambda_function(self):
5362
with self.deploy_lambda() as _:
@@ -69,6 +78,15 @@ def create__lambda_function__url(self):
6978
function_url = result.get('function_url_create').get('FunctionUrl')
7079
return function_url
7180

81+
def invoke(self, payload=None):
82+
return self.lambda_function().invoke(payload)
83+
84+
def invoke__function_url(self, path=''):
85+
with self.lambda_function() as _:
86+
url = _.function_url() + path
87+
headers = { self.api_key__name(): self.api_key__value()}
88+
return GET_json(url, headers=headers)
89+
7290
def lambda_configuration(self):
7391
return obj(self.lambda_function().info().get('Configuration'))
7492

poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/deploy_aws/test_deploy_lambda__to_aws.py renamed to tests/deploy_aws/test_deploy_lambda__to_aws__dev.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from osbot_fast_api_serverless.deploy.Deploy__Serverless__Fast_API import Deploy__Serverless__Fast_API
77

88

9-
class test_deploy_lambda__to_aws(TestCase):
9+
class test_deploy_lambda__to_aws__dev(TestCase):
1010

1111
@classmethod
1212
def setUpClass(cls):
@@ -59,4 +59,4 @@ def test_3__lambda_configuration(self):
5959

6060
def test_4__delete_function(self):
6161
with self.deploy_fast_api as _:
62-
assert _.delete_function() is True
62+
assert _.delete() is True
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
from unittest import TestCase
3+
from osbot_fast_api_serverless.utils.Version import version__osbot_fast_api_serverless
4+
from osbot_fast_api_serverless.deploy.Deploy__Serverless__Fast_API import Deploy__Serverless__Fast_API, DEFAULT__ERROR_MESSAGE__WHEN_FAST_API_IS_OK
5+
6+
7+
class test_deploy_lambda__to_aws__dev__qa__prod(TestCase):
8+
@classmethod
9+
def setUpClass(cls):
10+
cls.deploy_fast_api__dev = Deploy__Serverless__Fast_API(stage = 'dev')
11+
cls.deploy_fast_api__qa = Deploy__Serverless__Fast_API(stage = 'qa')
12+
cls.deploy_fast_api__prod = Deploy__Serverless__Fast_API(stage = 'prod')
13+
14+
with cls.deploy_fast_api__dev as _:
15+
if _.aws_config.aws_configured() is False:
16+
pytest.skip("this test needs valid AWS credentials")
17+
18+
def test_1__check_stages(self):
19+
assert self.deploy_fast_api__dev .stage == 'dev'
20+
assert self.deploy_fast_api__qa .stage == 'qa'
21+
assert self.deploy_fast_api__prod.stage == 'prod'
22+
23+
def test_2__create(self):
24+
assert self.deploy_fast_api__dev .create() is True
25+
assert self.deploy_fast_api__qa .create() is True
26+
assert self.deploy_fast_api__prod.create() is True
27+
28+
def test_3__invoke(self):
29+
assert self.deploy_fast_api__dev .invoke().get('errorMessage') == DEFAULT__ERROR_MESSAGE__WHEN_FAST_API_IS_OK
30+
assert self.deploy_fast_api__qa .invoke().get('errorMessage') == DEFAULT__ERROR_MESSAGE__WHEN_FAST_API_IS_OK
31+
assert self.deploy_fast_api__prod.invoke().get('errorMessage') == DEFAULT__ERROR_MESSAGE__WHEN_FAST_API_IS_OK
32+
33+
def test_3__invoke__function_url(self):
34+
version = {'version': version__osbot_fast_api_serverless}
35+
assert self.deploy_fast_api__dev .invoke__function_url('/info/version') == version
36+
assert self.deploy_fast_api__qa .invoke__function_url('/info/version') == version
37+
assert self.deploy_fast_api__prod.invoke__function_url('/info/version') == version
38+
39+
def test_4__delete(self):
40+
assert self.deploy_fast_api__dev .delete() is True
41+
assert self.deploy_fast_api__qa .delete() is True
42+
assert self.deploy_fast_api__prod.delete() is True

0 commit comments

Comments
 (0)