@@ -29,12 +29,6 @@ def cfg(aws_keys):
2929 return conf
3030
3131
32- @pytest .fixture
33- def lambda_client (aws_keys ):
34- key_id , secret = aws_keys
35- return get_client ('lambda' , key_id , secret , region = 'us-east-1' )
36-
37-
3832class TestPythonLambdaUnit ():
3933 """ Class containing unit (non-integration) tests for Python-Lambda """
4034
@@ -75,7 +69,7 @@ class TestPythonLambdaIntegration():
7569
7670 pytestmark = [pytest .mark .integration ]
7771
78- def test_deploy_lambda (self , cfg , lambda_client ):
72+ def test_deploy_lambda (self , cfg ):
7973 """
8074 Deploys a lambda function, tests that we can see/use it
8175 Updates that same function with different config, invokes to verify the
@@ -85,15 +79,15 @@ def test_deploy_lambda(self, cfg, lambda_client):
8579 full_name = example_function .config ['function_name' ] + '_' + suff
8680 deploy_function (example_function , function_name_suffix = suff )
8781 assert function_exists (cfg , full_name )
88- resp = lambda_client . invoke ( FunctionName = full_name , InvocationType = 'RequestResponse' )
89- assert resp [ 'Payload' ]. read (). decode ( 'utf-8' ) == '"Hello! My input event is {}"'
82+ resp = invoke_function ( cfg , full_name )
83+ assert resp == '"Hello! My input event is {}"'
9084 deploy_function (example_function_update , function_name_suffix = suff )
91- resp = lambda_client . invoke ( FunctionName = full_name , InvocationType = 'RequestResponse' )
92- assert resp [ 'Payload' ]. read (). decode ( 'utf-8' ) == '"Hello! I have been updated! My input event is {}"'
85+ resp = invoke_function ( cfg , full_name )
86+ assert resp == '"Hello! I have been updated! My input event is {}"'
9387 assert delete_function (cfg , full_name )
9488 assert not delete_function (cfg , full_name )
9589
96- def test_deploy_lambda_with_requirements (self , cfg , lambda_client ):
90+ def test_deploy_lambda_with_requirements (self , cfg ):
9791 """
9892 Deploys and invokes a lambda that has requirements, this time with no suffix
9993 Also passes an argument that is checked
@@ -103,24 +97,22 @@ def test_deploy_lambda_with_requirements(self, cfg, lambda_client):
10397 req_fpath = './tests/test_lambdas/requirements.txt'
10498 deploy_function (function_with_requirements , requirements_fpath = req_fpath )
10599 assert function_exists (cfg , full_name )
106- resp = lambda_client .invoke (FunctionName = full_name ,
107- InvocationType = 'RequestResponse' ,
108- Payload = json .dumps ({'magic' : 17 }))
109- assert resp ['Payload' ].read ().decode ('utf-8' ) == '"I successfully imported pytest! Magic: 17"'
100+ resp = invoke_function (cfg , full_name , event = {'magic' : 17 })
101+ assert resp == '"I successfully imported pytest! Magic: 17"'
110102 assert delete_function (cfg , full_name )
111103
112- def test_deploy_lambda_with_package (self , cfg , lambda_client ):
104+ def test_deploy_lambda_with_package (self , cfg ):
113105 """
114106 Deploys and invokes a lambda that has package based dependencies
115107 """
116108 full_name = function_with_package .config ['function_name' ]
117109 deploy_function (function_with_package , package_objects = [package ])
118110 assert function_exists (cfg , full_name )
119- resp = lambda_client . invoke ( FunctionName = full_name , InvocationType = 'RequestResponse' )
120- assert resp [ 'Payload' ]. read (). decode ( 'utf-8' ) == '"I successfully called magic_function: 21"'
111+ resp = invoke_function ( cfg , full_name )
112+ assert resp == '"I successfully called magic_function: 21"'
121113 assert delete_function (cfg , full_name )
122114
123- def test_deploy_lambda_with_package_and_requirements (self , cfg , lambda_client ):
115+ def test_deploy_lambda_with_package_and_requirements (self , cfg ):
124116 """
125117 Deploys and invokes a lambda that uses both an independently packaged
126118 dependency and one given from requirements.
@@ -130,6 +122,14 @@ def test_deploy_lambda_with_package_and_requirements(self, cfg, lambda_client):
130122 deploy_function (function_with_req_pack , requirements_fpath = req_fpath ,
131123 package_objects = [package ])
132124 assert function_exists (cfg , full_name )
133- resp = lambda_client . invoke ( FunctionName = full_name , InvocationType = 'RequestResponse' )
134- assert resp [ 'Payload' ]. read (). decode ( 'utf-8' ) == '"Imported pytest, magic_function: 21"'
125+ resp = invoke_function ( cfg , full_name )
126+ assert resp == '"Imported pytest, magic_function: 21"'
135127 assert delete_function (cfg , full_name )
128+
129+ def test_invoke_invalid_lambda (self , cfg ):
130+ """
131+ Tries to execute an invalid lambda. Should fail
132+ """
133+ full_name = 'not_a_lambda_name'
134+ resp = invoke_function (cfg , full_name )
135+ assert resp is None
0 commit comments