1
- import unittest
2
- import json
1
+
2
+
3
3
import contextlib
4
+ import json
5
+ import time
6
+ import unittest
4
7
from io import StringIO
5
8
6
9
from firetail_lambda import firetail_handler
7
10
11
+
8
12
class TestSimple (unittest .TestCase ):
9
13
10
14
def test_handler_api (self ):
@@ -19,6 +23,35 @@ def handler(event, context):
19
23
output = temp_stdout .getvalue ().strip ()
20
24
self .assertEqual (output , 'firetail:loggingapi:eyJldmVudCI6IHt9LCAicmVzcG9uc2UiOiBbMjAxLCAie1wibWVzc2FnZVwiOiBcInN1Y2Nlc3NcIn0iXX0=' )
21
25
26
+ def test_incorrect_handler_api (self ):
27
+ event = {}
28
+ @firetail_handler ()
29
+ def handler (argument ):
30
+ return 201 , json .dumps ({"message" : "success" })
31
+
32
+ temp_stdout = StringIO ()
33
+ with contextlib .redirect_stdout (temp_stdout ):
34
+ handler (event )
35
+ output = temp_stdout .getvalue ().strip ()
36
+ self .assertEqual (output , '' )
37
+
38
+ def test_handler_sleeper_api (self ):
39
+ event = {}
40
+ @firetail_handler (enable_sleeper = True )
41
+ def handler (event , context ):
42
+ return 201 , json .dumps ({"message" : "success" })
43
+
44
+ temp_stdout = StringIO ()
45
+ with contextlib .redirect_stdout (temp_stdout ):
46
+ start = time .time ()
47
+ handler (event , "" )
48
+ end = time .time ()
49
+
50
+ difference = end - start
51
+ output = temp_stdout .getvalue ().strip ()
52
+ self .assertGreaterEqual (difference , .5 )
53
+ self .assertEqual (output , 'firetail:loggingapi:eyJldmVudCI6IHt9LCAicmVzcG9uc2UiOiBbMjAxLCAie1wibWVzc2FnZVwiOiBcInN1Y2Nlc3NcIn0iXX0=' )
54
+
22
55
23
- if __name__ == '__main__' :
24
- unittest .main ()
56
+ if __name__ == '__main__' : # pragma: no cover
57
+ unittest .main () # pragma: no cover
0 commit comments