Skip to content

Commit 0c280ba

Browse files
committed
Fix tests after changes to handle server errors and 404
1 parent 471580a commit 0c280ba

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tests/legacy/test_connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,23 @@ def test_connection_request_handle_post(connection):
149149

150150
def test_connection_decode_response_raw(connection):
151151
response = mock.Mock()
152+
response.status_code = 200
152153
response.raw = 'expected'
153154
assert connection._decode_response(
154155
response, 'json', raw=True) == 'expected'
155156

156157

157158
def test_connection_decode_response_json_ok(connection):
158159
response = mock.Mock()
160+
response.status_code = 200
159161
response.text = '{"status":"ok","data":"some-data"}'
160162
assert connection._decode_response(
161163
response, 'json', raw=False) == {"status": "ok", "data": "some-data"}
162164

163165

164166
def test_connection_decode_response_json_error(connection):
165167
response = mock.Mock()
168+
response.status_code = 400
166169
for status in ['error', 'badrequest']:
167170
response.text = json.dumps({"status": status, "message": "error"})
168171
with pytest.raises(APIError) as exc:
@@ -172,6 +175,7 @@ def test_connection_decode_response_json_error(connection):
172175

173176
def test_connection_decode_response_json_unknown(connection):
174177
response = mock.Mock()
178+
response.status_code = 400
175179
response.text = json.dumps({"status": "unexpected", "message": "error"})
176180
with pytest.raises(APIError) as exc:
177181
connection._decode_response(response, 'json', raw=False)
@@ -181,6 +185,7 @@ def test_connection_decode_response_json_unknown(connection):
181185
def test_connection_decode_response_jl(connection):
182186
jl_data = [{'row1': 'data1'}, {'row2': 'data2'}]
183187
response = mock.Mock()
188+
response.status_code = 200
184189
response.iter_lines.return_value = [json.dumps(x) for x in jl_data]
185190
assert list(connection._decode_response(
186191
response, 'jl', raw=False)) == jl_data

0 commit comments

Comments
 (0)