|
1 | 1 | """Tests for art module.""" |
2 | 2 | from unittest.mock import Mock, patch |
3 | 3 |
|
| 4 | +import pytest |
| 5 | + |
| 6 | +from samsungtvws import exceptions |
4 | 7 | from samsungtvws.art import SamsungTVArt |
5 | 8 | from samsungtvws.remote import SamsungTVWS |
6 | 9 |
|
7 | 10 | from .const import ( |
8 | 11 | D2D_SERVICE_MESSAGE_AVAILABLE_SAMPLE, |
| 12 | + D2D_SERVICE_MESSAGE_SEND_IMAGE_ERROR, |
9 | 13 | MS_CHANNEL_CONNECT_SAMPLE, |
10 | 14 | MS_CHANNEL_DISCONNECT_SAMPLE, |
11 | 15 | MS_CHANNEL_READY_SAMPLE, |
@@ -110,3 +114,29 @@ def test_change_matte(connection: Mock) -> None: |
110 | 114 | connection.send.assert_called_once_with( |
111 | 115 | '{"method": "ms.channel.emit", "params": {"event": "art_app_request", "to": "host", "data": "{\\"request\\": \\"change_matte\\", \\"content_id\\": \\"test\\", \\"matte_id\\": \\"none\\", \\"id\\": \\"07e72228-7110-4655-aaa6-d81b5188c219\\"}"}}' |
112 | 116 | ) |
| 117 | + |
| 118 | + |
| 119 | +def test_send_image_failure(connection: Mock) -> None: |
| 120 | + """Ensure send_image failure raises error and doesn't hang indefinitely.""" |
| 121 | + with patch( |
| 122 | + "samsungtvws.art.uuid.uuid4", |
| 123 | + return_value="07e72228-7110-4655-aaa6-d81b5188c219", |
| 124 | + ), patch("samsungtvws.art.random.randrange", return_value=4091151321): |
| 125 | + connection.recv.side_effect = [ |
| 126 | + MS_CHANNEL_CONNECT_SAMPLE, |
| 127 | + MS_CHANNEL_READY_SAMPLE, |
| 128 | + D2D_SERVICE_MESSAGE_SEND_IMAGE_ERROR, |
| 129 | + ] |
| 130 | + tv_art = SamsungTVArt("127.0.0.1") |
| 131 | + |
| 132 | + with pytest.raises( |
| 133 | + exceptions.ResponseError, |
| 134 | + match="`send_image` request failed with error number -1", |
| 135 | + ): |
| 136 | + tv_art.upload( |
| 137 | + b"", file_type="png", matte="none", date="2023:05:02 15:06:39" |
| 138 | + ) |
| 139 | + |
| 140 | + connection.send.assert_called_once_with( |
| 141 | + '{"method": "ms.channel.emit", "params": {"event": "art_app_request", "to": "host", "data": "{\\"request\\": \\"send_image\\", \\"file_type\\": \\"png\\", \\"conn_info\\": {\\"d2d_mode\\": \\"socket\\", \\"connection_id\\": 4091151321, \\"id\\": \\"07e72228-7110-4655-aaa6-d81b5188c219\\"}, \\"image_date\\": \\"2023:05:02 15:06:39\\", \\"matte_id\\": \\"none\\", \\"file_size\\": 0, \\"id\\": \\"07e72228-7110-4655-aaa6-d81b5188c219\\"}"}}' |
| 142 | + ) |
0 commit comments