File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -345,11 +345,10 @@ def __init__(
345345 content_type = "application/json"
346346
347347 if content_type is UNSET :
348- content_type = "text/plain"
349-
350- # body must be bytes
351- if isinstance (body , six .text_type ):
352- body = body .encode ("utf-8" )
348+ if isinstance (body , six .text_type ) and _has_unicode (body ):
349+ content_type = "text/plain; charset=utf-8"
350+ else :
351+ content_type = "text/plain"
353352
354353 self .body = body
355354 self .status = status
Original file line number Diff line number Diff line change @@ -924,6 +924,21 @@ def run():
924924 assert_reset ()
925925
926926
927+ def test_handles_unicode_body ():
928+ url = "http://example.com/test"
929+
930+ @responses .activate
931+ def run ():
932+ responses .add (responses .GET , url , body = "михољско лето" )
933+
934+ resp = requests .get (url )
935+
936+ assert_response (resp , "михољско лето" , content_type = "text/plain; charset=utf-8" )
937+
938+ run ()
939+ assert_reset ()
940+
941+
927942def test_handles_buffered_reader_body ():
928943 url = "http://example.com/test"
929944
You can’t perform that action at this time.
0 commit comments