@@ -19,12 +19,12 @@ def test_tag_object(self):
19
19
tag_object (spanMock , "function.request" , payload )
20
20
spanMock .set_tag .assert_has_calls (
21
21
[
22
- call ("function.request.vals.0.thingOne" , 1 ),
23
- call ("function.request.vals.1.thingTwo" , 2 ),
22
+ call ("function.request.vals.0.thingOne" , "1" ),
23
+ call ("function.request.vals.1.thingTwo" , "2" ),
24
24
call ("function.request.hello" , "world" ),
25
25
call ("function.request.anotherThing.blah" , None ),
26
26
call ("function.request.anotherThing.foo" , "bar" ),
27
- call ("function.request.anotherThing.nice" , True ),
27
+ call ("function.request.anotherThing.nice" , " True" ),
28
28
],
29
29
True ,
30
30
)
@@ -40,12 +40,12 @@ def test_redacted_tag_object(self):
40
40
tag_object (spanMock , "function.request" , payload )
41
41
spanMock .set_tag .assert_has_calls (
42
42
[
43
- call ("function.request.vals.0.thingOne" , 1 ),
44
- call ("function.request.vals.1.thingTwo" , 2 ),
43
+ call ("function.request.vals.0.thingOne" , "1" ),
44
+ call ("function.request.vals.1.thingTwo" , "2" ),
45
45
call ("function.request.authorization" , "redacted" ),
46
46
call ("function.request.anotherThing.blah" , None ),
47
47
call ("function.request.anotherThing.password" , "redacted" ),
48
- call ("function.request.anotherThing.nice" , True ),
48
+ call ("function.request.anotherThing.nice" , " True" ),
49
49
],
50
50
True ,
51
51
)
@@ -62,7 +62,7 @@ def test_json_tag_object(self):
62
62
call ("function.request.token" , "redacted" ),
63
63
call ("function.request.jsonString.stringifyThisJson.0.here" , "is" ),
64
64
call ("function.request.jsonString.stringifyThisJson.0.an" , "object" ),
65
- call ("function.request.jsonString.stringifyThisJson.0.number" , 1 ),
65
+ call ("function.request.jsonString.stringifyThisJson.0.number" , "1" ),
66
66
],
67
67
True ,
68
68
)
@@ -79,18 +79,59 @@ def test_unicode_tag_object(self):
79
79
call ("function.request.token" , "redacted" ),
80
80
call ("function.request.jsonString.stringifyThisJson.0.here" , "is" ),
81
81
call ("function.request.jsonString.stringifyThisJson.0.an" , "object" ),
82
- call ("function.request.jsonString.stringifyThisJson.0.number" , 1 ),
82
+ call ("function.request.jsonString.stringifyThisJson.0.number" , "1" ),
83
83
],
84
84
True ,
85
85
)
86
86
87
87
def test_decimal_tag_object (self ):
88
- payload = {"myValue" : Decimal (500.50 )}
88
+ payload = {"myValue" : Decimal (500.5 )}
89
89
spanMock = MagicMock ()
90
90
tag_object (spanMock , "function.request" , payload )
91
91
spanMock .set_tag .assert_has_calls (
92
92
[
93
- call ("function.request.myValue" , Decimal (500.50 )),
93
+ call ("function.request.myValue" , "500.5" ),
94
+ ],
95
+ True ,
96
+ )
97
+
98
+ class CustomResponse (object ):
99
+ """
100
+ For example, chalice.app.Response class
101
+ """
102
+
103
+ def __init__ (self , body , headers = None , status_code : int = 200 ):
104
+ self .body = body
105
+ if headers is None :
106
+ headers = {}
107
+ self .headers = headers
108
+ self .status_code = status_code
109
+
110
+ def __str__ (self ):
111
+ return str (self .body )
112
+
113
+ class ResponseHasToDict (CustomResponse ):
114
+ def to_dict (self ):
115
+ return self .headers
116
+
117
+ def test_custom_response (self ):
118
+ payload = self .CustomResponse ({"hello" : "world" }, {"key1" : "val1" }, 200 )
119
+ spanMock = MagicMock ()
120
+ tag_object (spanMock , "function.response" , payload )
121
+ spanMock .set_tag .assert_has_calls (
122
+ [
123
+ call ("function.response" , "{'hello': 'world'}" ),
124
+ ],
125
+ True ,
126
+ )
127
+
128
+ def test_custom_response_to_dict (self ):
129
+ payload = self .ResponseHasToDict ({"hello" : "world" }, {"key1" : "val1" }, 200 )
130
+ spanMock = MagicMock ()
131
+ tag_object (spanMock , "function.response" , payload )
132
+ spanMock .set_tag .assert_has_calls (
133
+ [
134
+ call ("function.response.key1" , "val1" ),
94
135
],
95
136
True ,
96
137
)
0 commit comments