diff --git a/sidecar/app/query/status.py b/sidecar/app/query/status.py index 9768cc6..81b3f9e 100644 --- a/sidecar/app/query/status.py +++ b/sidecar/app/query/status.py @@ -25,7 +25,7 @@ def from_json(cls, response: dict[str, str]): status_str = response.get("status", "") try: return cls[status_str] - except ValueError: + except KeyError: return cls.UNKNOWN diff --git a/sidecar/tests/app/query/test_status.py b/sidecar/tests/app/query/test_status.py index 4a35c4e..a77afcd 100644 --- a/sidecar/tests/app/query/test_status.py +++ b/sidecar/tests/app/query/test_status.py @@ -113,3 +113,19 @@ def test_status_history_status_event_json( "start_time": now, "end_time": now2, } + + +def test_status_from_json(): + # matching string + status = Status.from_json({"status": "STARTING"}) + assert status == Status.STARTING + status = Status.from_json({"status": "UNKNOWN"}) + assert status == Status.UNKNOWN + + # non-mathcing string + status = Status.from_json({"status": "not-a-status"}) + assert status == Status.UNKNOWN + + # empty json + status = Status.from_json({}) + assert status == Status.UNKNOWN