@@ -31,7 +31,7 @@ def on_exception(self, exception: Exception) -> Any:
31
31
32
32
33
33
@pytest .fixture
34
- def handler ():
34
+ def function_handler ():
35
35
@lambda_handler
36
36
def handler (event , context ):
37
37
if context is None :
@@ -41,20 +41,51 @@ def handler(event, context):
41
41
return handler
42
42
43
43
44
- class TestLambdaHandler :
44
+ @pytest .fixture
45
+ def method_handler ():
46
+ class Adapter :
47
+ @lambda_handler
48
+ def __call__ (self , event , context ):
49
+ if context is None :
50
+ raise EventAwareException (message = 'no such context' , event = event )
51
+ return event
52
+
53
+ return Adapter ()
54
+
55
+
56
+ class TestLambdaHandlerDecorateFunction :
57
+
58
+ @pytest .fixture
59
+ def event (self ):
60
+ return {'route' : []}
61
+
62
+ def test_call_order (self , function_handler , event ):
63
+ result = function_handler (event , {})
64
+
65
+ assert result == event
66
+ assert event ['route' ] == ['before' , 'after' ]
67
+
68
+ def test_call_exception (self , function_handler , event ):
69
+ with pytest .raises (EventAwareException , match = 'no such context' ):
70
+ function_handler (event , None )
71
+
72
+ assert event ['route' ] == ['before' , 'on_exception' ]
73
+
74
+
75
+ class TestLambdaHandlerDecorateMethod :
45
76
46
77
@pytest .fixture
47
78
def event (self ):
48
79
return {'route' : []}
49
80
50
- def test_call_order (self , handler , event ):
51
- result = handler (event , {})
81
+ def test_call_order (self , method_handler , event ):
82
+ result = method_handler (event , {})
52
83
53
84
assert result == event
54
85
assert event ['route' ] == ['before' , 'after' ]
55
86
56
- def test_call_exception (self , handler , event ):
87
+ def test_call_exception (self , method_handler , event ):
57
88
with pytest .raises (EventAwareException , match = 'no such context' ):
58
- handler (event , None )
89
+ method_handler (event , None )
59
90
60
91
assert event ['route' ] == ['before' , 'on_exception' ]
0 commit comments