File tree Expand file tree Collapse file tree 2 files changed +5
-1
lines changed Expand file tree Collapse file tree 2 files changed +5
-1
lines changed Original file line number Diff line number Diff line change 11
11
},
12
12
"response" : " invalid key" ,
13
13
"response-headers" : {
14
+ "content-type" : " text/plain; charset=utf-8"
14
15
}
15
16
}
Original file line number Diff line number Diff line change 4
4
from unittest .mock import patch
5
5
6
6
import requests
7
+ from requests .utils import get_encoding_from_headers
7
8
8
9
9
10
@contextmanager
@@ -25,11 +26,13 @@ def get_response(
25
26
response headers.
26
27
"""
27
28
mock_result = requests .Response ()
29
+ mock_result .status_code = http_headers .pop ("status" , 200 )
30
+ mock_result .headers .update (http_headers )
31
+ mock_result .encoding = get_encoding_from_headers (mock_result .headers )
28
32
if is_raw_response :
29
33
mock_result ._content = http_response .encode () # type: ignore # This modifies a "hidden" attribute.
30
34
else :
31
35
mock_result ._content = json .dumps (http_response ).encode ()
32
- mock_result .status_code = http_headers .get ("status" , 200 )
33
36
return mock_result
34
37
35
38
def assert_called_with_fields (
You can’t perform that action at this time.
0 commit comments