Skip to content

Commit c24575a

Browse files
committed
test: check if client handles json error messages from server correctly
1 parent 74ff188 commit c24575a

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/test_error_handling_non_json.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import pytest
22
import requests
3+
import json
34
from frost_sta_client.service.sensorthingsservice import SensorThingsService
45
from frost_sta_client.utils import transform_json_to_entity_list
6+
from frost_sta_client.model.thing import Thing
57

68

79
class DummyService(SensorThingsService):
@@ -39,3 +41,26 @@ def test_entitylist_iter_handles_non_json_error():
3941
it = iter(elist)
4042
with pytest.raises(requests.exceptions.HTTPError):
4143
next(it)
44+
45+
46+
class WorkingService(SensorThingsService):
47+
def __init__(self, url):
48+
super().__init__(url)
49+
50+
def execute(self, method, url, **kwargs):
51+
class Resp:
52+
status_code = 400
53+
text = '{"code":400,"type":"error","message":"Not a valid path for DELETE."}'
54+
55+
def json(self):
56+
return json.loads(self.text)
57+
58+
raise requests.exceptions.HTTPError(response=Resp())
59+
60+
61+
def test_basedao_handles_json_error(caplog):
62+
svc = WorkingService('http://example.org/FROST-Server/v1.1/Things')
63+
with pytest.raises(requests.exceptions.HTTPError):
64+
thing = Thing(id=1)
65+
svc.delete(thing)
66+
assert caplog.messages[-1] == "Deleting Thing failed with status-code 400, Not a valid path for DELETE."

0 commit comments

Comments
 (0)