1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
|
"""Tests for Roku Models."""
from datetime import datetime
import pytest
import xmltodict
from rokuecp import RokuError, models
from . import load_fixture
ACTIVE_APP_NETFLIX = xmltodict.parse(load_fixture("active-app-netflix.xml"))
ACTIVE_APP_PLUTO = xmltodict.parse(load_fixture("active-app-pluto.xml"))
ACTIVE_APP_TV = xmltodict.parse(load_fixture("active-app-tvinput-dtv.xml"))
APPS = xmltodict.parse(load_fixture("apps.xml"))
APPS_TV = xmltodict.parse(load_fixture("apps-tv.xml"))
DEVICE_INFO = xmltodict.parse(load_fixture("device-info.xml"))
DEVICE_INFO_3500X = xmltodict.parse(load_fixture("device-info-3500x.xml"))
DEVICE_INFO_7820X = xmltodict.parse(load_fixture("device-info-7820x.xml"))
DEVICE_INFO_C147X = xmltodict.parse(load_fixture("device-info-c147x.xml"))
DEVICE_INFO_D803X = xmltodict.parse(load_fixture("device-info-d803x.xml"))
MEDIA_PLAYER_CLOSE = xmltodict.parse(load_fixture("media-player-close.xml"))
MEDIA_PLAYER_PLUTO_LIVE = xmltodict.parse(load_fixture("media-player-pluto-live.xml"))
MEDIA_PLAYER_PLUTO_PAUSE = xmltodict.parse(load_fixture("media-player-pluto-pause.xml"))
MEDIA_PLAYER_PLUTO_PLAY = xmltodict.parse(load_fixture("media-player-pluto-play.xml"))
TV_ACTIVE_CHANNEL = xmltodict.parse(load_fixture("tv-active-channel.xml"))
TV_CHANNELS = xmltodict.parse(load_fixture("tv-channels.xml"))
DEVICE = {
"info": DEVICE_INFO["device-info"],
"apps": APPS["apps"]["app"],
"app": ACTIVE_APP_PLUTO["active-app"],
"media": MEDIA_PLAYER_PLUTO_PLAY["player"],
"available": True,
"standby": False,
}
DEVICE_TV = {
"info": DEVICE_INFO_7820X["device-info"],
"apps": APPS_TV["apps"]["app"],
"app": ACTIVE_APP_TV["active-app"],
"channels": TV_CHANNELS["tv-channels"]["channel"],
"channel": TV_ACTIVE_CHANNEL["tv-channel"]["channel"],
"available": True,
"standby": False,
}
def test_device() -> None:
"""Test the Device model."""
device = models.Device(DEVICE)
assert device
assert device.info
assert isinstance(device.info, models.Info)
assert device.state
assert isinstance(device.state, models.State)
assert device.apps
assert isinstance(device.apps, list)
assert device.app
assert isinstance(device.app, models.Application)
assert device.media
assert isinstance(device.media, models.MediaState)
assert isinstance(device.channels, list)
assert len(device.channels) == 0
assert device.channel is None
def test_device_no_data() -> None:
"""Test the Device model with no device info."""
with pytest.raises(RokuError):
models.Device({})
def test_device_tv() -> None:
"""Test the Device model with Roku TV."""
device = models.Device(DEVICE_TV)
assert device
assert device.info
assert isinstance(device.info, models.Info)
assert device.state
assert isinstance(device.state, models.State)
assert device.apps
assert isinstance(device.apps, list)
assert device.app
assert isinstance(device.app, models.Application)
assert device.app.app_id == "tvinput.dtv"
assert device.media is None
assert isinstance(device.channels, list)
assert len(device.channels) == 2
assert isinstance(device.channel, models.Channel)
def test_device_as_dict() -> None:
"""Test the dictionary version of Device."""
device = models.Device(DEVICE)
assert device
device_dict = device.as_dict()
assert device_dict
assert isinstance(device_dict, dict)
assert isinstance(device_dict["info"], dict)
assert isinstance(device_dict["state"], dict)
assert isinstance(device_dict["apps"], list)
assert len(device_dict["apps"]) == 8
assert device_dict["app"]
assert isinstance(device_dict["app"], dict)
assert device_dict["channel"] is None
assert device_dict["media"]
assert isinstance(device_dict["media"], dict)
assert isinstance(device_dict["channels"], list)
assert len(device_dict["channels"]) == 0
def test_device_tv_as_dict() -> None:
"""Test the dictionary version of Device."""
device = models.Device(DEVICE_TV)
assert device
device_dict = device.as_dict()
assert device_dict
assert isinstance(device_dict, dict)
assert isinstance(device_dict["info"], dict)
assert isinstance(device_dict["state"], dict)
assert isinstance(device_dict["apps"], list)
assert len(device_dict["apps"]) == 10
assert device_dict["app"]
assert isinstance(device_dict["app"], dict)
assert device_dict["channel"]
assert isinstance(device_dict["channel"], dict)
assert device_dict["media"] is None
assert isinstance(device_dict["channels"], list)
assert len(device_dict["channels"]) == 2
def test_info() -> None:
"""Test the Info model."""
info = models.Info.from_dict(DEVICE_INFO["device-info"])
assert info
assert info.name == "My Roku 3"
assert info.brand == "Roku"
assert info.device_location is None
assert info.device_type == "box"
assert info.network_type == "ethernet"
assert info.network_name is None
assert info.model_name == "Roku 3"
assert info.model_number == "4200X"
assert info.serial_number == "1GU48T017973"
assert info.ethernet_support
assert info.ethernet_mac == "b0:a7:37:96:4d:fa"
assert info.wifi_mac == "b0:a7:37:96:4d:fb"
assert not info.supports_airplay
assert not info.supports_find_remote
assert not info.supports_private_listening
assert not info.supports_wake_on_wlan
assert not info.headphones_connected
assert info.version == "7.5.0"
def test_info_without_client_device_name() -> None:
"""Test the Info model without a client device name."""
temp = {
**DEVICE_INFO["device-info"],
"user-device-name": None,
"friendly-device-name": None,
"default-device-name": None,
}
info = models.Info.from_dict(temp)
assert info
assert info.name == "Roku Roku 3"
def test_info_stick_3500x() -> None:
"""Test the Info model with Roku Stick."""
info = models.Info.from_dict(DEVICE_INFO_3500X["device-info"])
assert info
assert info.name == "My Roku Stick"
assert info.brand == "Roku"
assert info.device_location is None
assert info.device_type == "stick"
assert info.network_type == "wifi"
assert info.network_name == "NetworkSSID"
assert info.model_name == "Roku Stick"
assert info.model_number == "3500X"
assert info.serial_number == "2L647N055555"
assert not info.ethernet_support
assert info.ethernet_mac is None
assert info.wifi_mac == "b0:a7:37:6a:ec:2d"
assert not info.supports_airplay
assert info.supports_find_remote
assert not info.supports_private_listening
assert not info.supports_wake_on_wlan
assert not info.headphones_connected
assert info.version == "10.0.0"
def test_info_tv_7820x() -> None:
"""Test the Info model with TV model 7820X."""
info = models.Info.from_dict(DEVICE_INFO_7820X["device-info"])
assert info
assert info.name == '58" Onn Roku TV'
assert info.brand == "Onn"
assert info.device_location == "Living room"
assert info.device_type == "tv"
assert info.network_type == "wifi"
assert info.network_name == "NetworkSSID"
assert info.model_name == "100005844"
assert info.model_number == "7820X"
assert info.serial_number == "YN00H5555555"
assert info.ethernet_support
assert info.ethernet_mac == "d4:3a:2e:07:fd:cb"
assert info.wifi_mac == "d8:13:99:f8:b0:c6"
assert info.supports_airplay
assert info.supports_find_remote
assert info.supports_private_listening
assert info.supports_wake_on_wlan
assert not info.headphones_connected
assert info.version == "9.2.0"
def test_info_tv_c147x() -> None:
"""Test the Info model with TV model C147X."""
info = models.Info.from_dict(DEVICE_INFO_C147X["device-info"])
assert info
assert info.name == "TCL•Roku TV - X000008YG08J"
assert info.brand == "TCL"
assert info.device_location is None
assert info.device_type == "tv"
assert info.network_type == "wifi"
assert info.network_name == "NetworkSSID"
assert info.model_name == "55S20"
assert info.model_number == "C147X"
assert info.serial_number == "X000008YG08J"
assert info.ethernet_support
assert info.ethernet_mac == "34:51:80:6d:01:42"
assert info.wifi_mac == "d4:ab:cd:f8:e1:d5"
assert info.supports_airplay
assert not info.supports_find_remote
assert info.supports_private_listening
assert info.supports_wake_on_wlan
assert not info.headphones_connected
assert info.version == "11.5.0"
def test_info_tv_d803x() -> None:
"""Test the Info model with TV model D803X."""
info = models.Info.from_dict(DEVICE_INFO_D803X["device-info"])
assert info
assert info.name == '42" Onn Roku TV'
assert info.brand == "onn."
assert info.device_location is None
assert info.device_type == "tv"
assert info.network_type == "wifi"
assert info.network_name == "NetworkSSID"
assert info.model_name == "100018254"
assert info.model_number == "D803X"
assert info.serial_number == "X00755550DCH"
assert not info.ethernet_support
assert info.ethernet_mac is None
assert info.wifi_mac == "d4:ab:cd:2f:6b:55"
assert info.supports_airplay
assert not info.supports_find_remote
assert info.supports_private_listening
assert info.supports_wake_on_wlan
assert not info.headphones_connected
assert info.version == "10.0.0"
def test_application() -> None:
"""Test the Application model."""
app = models.Application.from_dict(APPS["apps"]["app"][0])
assert app
assert app.app_id == "11"
assert app.name == "Roku Channel Store"
def test_application_active_app() -> None:
"""Test the Application model with active app."""
app = models.Application.from_dict(ACTIVE_APP_NETFLIX["active-app"])
assert app
assert app.app_id == "12"
assert app.name == "Netflix"
assert app.version == "4.1.218"
def test_channel() -> None:
"""Test the Channel model."""
channel = models.Channel.from_dict(TV_CHANNELS["tv-channels"]["channel"][0])
assert channel
assert channel.name == "WhatsOn"
assert channel.number == "1.1"
assert channel.channel_type == "air-digital"
assert not channel.hidden
assert channel.program_title is None
assert channel.program_description is None
assert channel.program_rating is None
assert channel.signal_mode is None
assert channel.signal_strength is None
def test_channel_active_tv() -> None:
"""Test the Channel model with active TV channel."""
channel = models.Channel.from_dict(TV_ACTIVE_CHANNEL["tv-channel"]["channel"])
description = """The team will travel all around the world in order to shut down
a global crime ring."""
assert channel
assert channel.name == "getTV"
assert channel.number == "14.3"
assert channel.channel_type == "air-digital"
assert not channel.hidden
assert channel.program_title == "Airwolf"
assert channel.program_description == description.replace("\n", " ")
assert channel.program_rating == "TV-14-D-V"
assert channel.signal_mode == "480i"
assert channel.signal_strength == -75
def test_channel_active_tv_signal_stength_non_numeric() -> None:
"""Test the Channel model with active TV channel and non-numeric signal strength."""
active_channel = {
**TV_ACTIVE_CHANNEL["tv-channel"]["channel"],
"signal-strength": "n/a",
}
channel = models.Channel.from_dict(active_channel)
description = """The team will travel all around the world in order to shut down
a global crime ring."""
assert channel
assert channel.name == "getTV"
assert channel.number == "14.3"
assert channel.channel_type == "air-digital"
assert not channel.hidden
assert channel.program_title == "Airwolf"
assert channel.program_description == description.replace("\n", " ")
assert channel.program_rating == "TV-14-D-V"
assert channel.signal_mode == "480i"
assert channel.signal_strength is None
def test_media_state_close() -> None:
"""Test the MediaState model with closed media."""
state = models.MediaState.from_dict(MEDIA_PLAYER_CLOSE["player"])
assert state is None
def test_media_state_live() -> None:
"""Test the MediaState model with live media."""
state = models.MediaState.from_dict(MEDIA_PLAYER_PLUTO_LIVE["player"])
assert state
assert isinstance(state.at, datetime)
assert not state.paused
assert state.live
assert state.duration == 95
assert state.position == 73
def test_media_state_pause() -> None:
"""Test the MediaState model with paused media."""
state = models.MediaState.from_dict(MEDIA_PLAYER_PLUTO_PAUSE["player"])
assert state
assert isinstance(state.at, datetime)
assert state.paused
assert not state.live
assert state.duration == 6496
assert state.position == 313
def test_media_state_play() -> None:
"""Test the MediaState model with playing media."""
state = models.MediaState.from_dict(MEDIA_PLAYER_PLUTO_PLAY["player"])
assert state
assert isinstance(state.at, datetime)
assert not state.paused
assert not state.live
assert state.duration == 6496
assert state.position == 38
def test_state() -> None:
"""Test the State model."""
state = models.State(available=True, standby=False)
assert state
assert isinstance(state.at, datetime)
|