@@ -19,12 +19,12 @@ def test_tag_object(self):
1919 tag_object (spanMock , "function.request" , payload )
2020 spanMock .set_tag .assert_has_calls (
2121 [
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" ),
2424 call ("function.request.hello" , "world" ),
2525 call ("function.request.anotherThing.blah" , None ),
2626 call ("function.request.anotherThing.foo" , "bar" ),
27- call ("function.request.anotherThing.nice" , True ),
27+ call ("function.request.anotherThing.nice" , " True" ),
2828 ],
2929 True ,
3030 )
@@ -40,12 +40,12 @@ def test_redacted_tag_object(self):
4040 tag_object (spanMock , "function.request" , payload )
4141 spanMock .set_tag .assert_has_calls (
4242 [
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" ),
4545 call ("function.request.authorization" , "redacted" ),
4646 call ("function.request.anotherThing.blah" , None ),
4747 call ("function.request.anotherThing.password" , "redacted" ),
48- call ("function.request.anotherThing.nice" , True ),
48+ call ("function.request.anotherThing.nice" , " True" ),
4949 ],
5050 True ,
5151 )
@@ -62,7 +62,7 @@ def test_json_tag_object(self):
6262 call ("function.request.token" , "redacted" ),
6363 call ("function.request.jsonString.stringifyThisJson.0.here" , "is" ),
6464 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" ),
6666 ],
6767 True ,
6868 )
@@ -79,18 +79,59 @@ def test_unicode_tag_object(self):
7979 call ("function.request.token" , "redacted" ),
8080 call ("function.request.jsonString.stringifyThisJson.0.here" , "is" ),
8181 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" ),
8383 ],
8484 True ,
8585 )
8686
8787 def test_decimal_tag_object (self ):
88- payload = {"myValue" : Decimal (500.50 )}
88+ payload = {"myValue" : Decimal (500.5 )}
8989 spanMock = MagicMock ()
9090 tag_object (spanMock , "function.request" , payload )
9191 spanMock .set_tag .assert_has_calls (
9292 [
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" ),
94135 ],
95136 True ,
96137 )
0 commit comments