Skip to content

Commit 3c8d03f

Browse files
mamiksikfilak-sap
authored andcommitted
service: correct batch response API for headers
ODataHttpResponse should be complainant with the requests.Response, which stores headers as dict {header: value}. This change allows us to use ODataHttpResponse and requests.Response interchangeably which is a desired behavior.
1 parent 35b333d commit 3c8d03f

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616
- URL encode $filter contents - Barton Ip
1717
- JSON errors caused by invalid content length of Batch responses - Barton Ip
1818

19+
### Changed
20+
- ODataHttpResponse.from_string produces header of type {header: value} instead of [(header, value)] - Martin Miksik
21+
1922
## [1.5.0]
2023

2124
### Added

pyodata/v2/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def makefile(self, *args, **kwargs):
137137
response.length = response.fp.__sizeof__()
138138

139139
return ODataHttpResponse(
140-
response.getheaders(),
140+
dict(response.getheaders()),
141141
response.status,
142142
response.read(len(data)) # the len here will give a 'big enough' value to read the whole content
143143
)

tests/test_service_v2.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pyodata.v2.model
1010
import pyodata.v2.service
1111
from pyodata.exceptions import PyODataException, HttpError, ExpressionError
12-
from pyodata.v2.service import EntityKey, EntityProxy, GetEntitySetFilter
12+
from pyodata.v2.service import EntityKey, EntityProxy, GetEntitySetFilter, ODataHttpResponse, HTTP_CODE_OK
1313

1414
from tests.conftest import assert_request_contains_header, contents_of_fixtures_file
1515

@@ -2126,3 +2126,20 @@ def test_parsing_of_datetime_before_unix_time(service):
21262126

21272127
result = request.execute()
21282128
assert result.Date == datetime.datetime(1945, 5, 8, 19, 0, tzinfo=datetime.timezone.utc)
2129+
2130+
2131+
def test_odata_http_response():
2132+
"""Test that ODataHttpResponse is complaint with requests.Reponse"""
2133+
2134+
response_string = 'HTTP/1.1 200 OK \n' \
2135+
'Content-Type: application/json\n' \
2136+
'\n' \
2137+
'{"d": {"ID": 23 }}'
2138+
2139+
response = ODataHttpResponse.from_string(response_string)
2140+
2141+
assert response.status_code == HTTP_CODE_OK
2142+
2143+
assert isinstance(response.headers, dict)
2144+
assert response.headers['Content-Type'] == 'application/json'
2145+
assert response.json()['d']['ID'] == 23

0 commit comments

Comments
 (0)