Skip to content

Commit

Permalink
Test rest exception claass
Browse files Browse the repository at this point in the history
  • Loading branch information
callumforrester committed Jul 23, 2024
1 parent d6499cd commit 168f501
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/client/test_rest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from typing import Type
from unittest.mock import Mock, patch

import pytest

from blueapi.client.rest import BlueapiRestClient, BlueskyRemoteControlError


@pytest.fixture
def rest() -> BlueapiRestClient:
return BlueapiRestClient()


@pytest.mark.parametrize(
"code,expected_exception",
[
(404, KeyError),
(450, BlueskyRemoteControlError),
(500, BlueskyRemoteControlError),
],
)
@patch("blueapi.client.rest.requests.request")
def test_rest_error_code(
mock_request: Mock,
rest: BlueapiRestClient,
code: int,
expected_exception: type[Exception],
):
response = Mock()
response.status_code = code
mock_request.return_value = response
with pytest.raises(expected_exception):
rest.get_plans()

0 comments on commit 168f501

Please sign in to comment.