Skip to content

Commit 6dce326

Browse files
kabakcheymvantellingen
authored andcommitted
Fix raw_response feature inside Client.option ctx manager
1 parent c5acb16 commit 6dce326

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/zeep/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,21 @@ def options(self, timeout=NotSet, raw_response=NotSet):
167167
168168
169169
"""
170-
# Store current options
171-
old_raw_raw_response = self.raw_response
170+
if raw_response is not NotSet:
171+
# Store current options
172+
old_raw_response = self.raw_response
172173

173-
# Set new options
174-
self.raw_response = raw_response
174+
# Set new options
175+
self.raw_response = raw_response
175176

176177
if timeout is not NotSet:
177178
timeout_ctx = self.transport._options(timeout=timeout)
178179
timeout_ctx.__enter__()
179180

180181
yield
181182

182-
self.raw_response = old_raw_raw_response
183+
if raw_response is not NotSet:
184+
self.raw_response = old_raw_response
183185

184186
if timeout is not NotSet:
185187
timeout_ctx.__exit__(None, None, None)

tests/test_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ def test_set_context_options_timeout():
183183
assert obj.transport.operation_timeout is None
184184

185185

186+
def test_set_context_options_raw_response():
187+
obj = client.Client('tests/wsdl_files/soap.wsdl')
188+
189+
assert obj.raw_response is False
190+
with obj.options(raw_response=True):
191+
assert obj.raw_response is True
192+
193+
with obj.options():
194+
# Check that raw_response is not changed by default value
195+
assert obj.raw_response is True
196+
# Check that the original value returned
197+
assert obj.raw_response is False
198+
199+
186200
@pytest.mark.requests
187201
def test_default_soap_headers():
188202
header = xsd.ComplexType(

0 commit comments

Comments
 (0)