Skip to content

Commit e818c6b

Browse files
authored
Merge pull request #124 from epenet/send_image_error
Add tests for send image error
2 parents f51335a + 9fcd0b4 commit e818c6b

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

tests/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
with open("tests/fixtures/event_d2d_service_message_available.json") as file:
44
D2D_SERVICE_MESSAGE_AVAILABLE_SAMPLE = file.read()
5+
with open("tests/fixtures/event_d2d_service_message_send_image_error.json") as file:
6+
D2D_SERVICE_MESSAGE_SEND_IMAGE_ERROR = file.read()
57
with open("tests/fixtures/event_ms_channel_connect.json") as file:
68
MS_CHANNEL_CONNECT_SAMPLE = file.read()
79
with open("tests/fixtures/event_ms_channel_disconnect.json") as file:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"data": "{\"id\":\"3d99854f-a8cf-4971-afd6-058b7151da16\",\"event\":\"error\",\"request_data\":\"{\\\"request\\\": \\\"send_image\\\", \\\"file_type\\\": \\\"png\\\", \\\"conn_info\\\": {\\\"d2d_mode\\\": \\\"socket\\\", \\\"connection_id\\\": 2825700145, \\\"id\\\": \\\"3d99854f-a8cf-4971-afd6-058b7151da16\\\"}, \\\"image_date\\\": \\\"2022:04:06 08:52:23\\\", \\\"matte_id\\\": \\\"modern_apricot\\\", \\\"file_size\\\": 16123877, \\\"id\\\": \\\"3d99854f-a8cf-4971-afd6-058b7151da16\\\"}\",\"error_code\":\"-1\",\"target_client_id\":\"ada14710-7e2e-47bb-885b-1715512a2d40\"}",
3+
"event": "d2d_service_message",
4+
"from": "77151bce-7dd2-4c4c-9b78-4d33b16fb1b"
5+
}

tests/test_art.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
"""Tests for art module."""
22
from unittest.mock import Mock, patch
33

4+
import pytest
5+
6+
from samsungtvws import exceptions
47
from samsungtvws.art import SamsungTVArt
58
from samsungtvws.remote import SamsungTVWS
69

710
from .const import (
811
D2D_SERVICE_MESSAGE_AVAILABLE_SAMPLE,
12+
D2D_SERVICE_MESSAGE_SEND_IMAGE_ERROR,
913
MS_CHANNEL_CONNECT_SAMPLE,
1014
MS_CHANNEL_DISCONNECT_SAMPLE,
1115
MS_CHANNEL_READY_SAMPLE,
@@ -110,3 +114,29 @@ def test_change_matte(connection: Mock) -> None:
110114
connection.send.assert_called_once_with(
111115
'{"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\\"}"}}'
112116
)
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

Comments
 (0)