Skip to content

Commit eb037b7

Browse files
committed
add another test for non_json_body
1 parent 74f83e4 commit eb037b7

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

tests/unit_tests/client/test_rest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
UnauthorisedAccessError,
1919
UnknownPlanError,
2020
_create_task_exceptions,
21+
_exception,
2122
)
2223
from blueapi.config import OIDCConfig
2324
from blueapi.service.authentication import SessionCacheManager, SessionManager
@@ -120,6 +121,21 @@ def test_create_task_exceptions(
120121
assert err.args[1] == content
121122

122123

124+
def test_exception_non_json_body_falls_back_to_text():
125+
import json
126+
127+
response = Mock(spec=requests.Response)
128+
response.status_code = 500
129+
response.text = "Internal Server Error"
130+
response.json.side_effect = json.JSONDecodeError("Expecting value", "", 0)
131+
response.request = Mock()
132+
response.request.url = "http://localhost:8000/test"
133+
response.content = b"Internal Server Error"
134+
err = _exception(response)
135+
assert isinstance(err, BlueskyRemoteControlError)
136+
assert err.args[1] == "Internal Server Error"
137+
138+
123139
def test_auth_request_functionality(
124140
rest_with_auth: BlueapiRestClient,
125141
mock_authn_server: responses.RequestsMock,

0 commit comments

Comments
 (0)