Skip to content

Commit

Permalink
Add tests for new play_state logic
Browse files Browse the repository at this point in the history
  • Loading branch information
postlund committed Sep 26, 2017
1 parent 769b369 commit 4fa6e3f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyatv/__init__.py
Expand Up @@ -189,7 +189,7 @@ def _get_service_used_to_connect(details, protocol):
def _setup_airplay(loop, session, details):
airplay_service = details.airplay_service()
airplay_player = player.AirPlayPlayer(
loop, session, details.address, airplay_service.port)
loop, details.address, airplay_service.port)
airplay_http = HttpSession(
session, 'http://{0}:{1}/'.format(
details.address, airplay_service.port))
Expand Down
2 changes: 1 addition & 1 deletion pyatv/airplay/player.py
Expand Up @@ -23,7 +23,7 @@
class AirPlayPlayer:
"""This class helps with playing media from an URL."""

def __init__(self, loop, session, address, port=7000):
def __init__(self, loop, address, port=7000):
"""Initialize a new AirPlay instance."""
self.loop = loop
self.address = address
Expand Down
14 changes: 10 additions & 4 deletions tests/airplay/test_airplay.py
Expand Up @@ -3,7 +3,6 @@
import asyncio

from tests.log_output_handler import LogOutputHandler
from aiohttp import ClientSession
from aiohttp.test_utils import (AioHTTPTestCase, unittest_run_loop)

from pyatv.airplay import player
Expand Down Expand Up @@ -53,13 +52,20 @@ def test_play_video(self):
self.usecase.airplay_playback_playing()
self.usecase.airplay_playback_idle()

session = ClientSession(loop=self.loop)
aplay = player.AirPlayPlayer(
self.loop, session, '127.0.0.1', port=self.app.port)
self.loop, '127.0.0.1', port=self.app.port)
yield from aplay.play_url(STREAM, position=START_POSITION)

self.assertEqual(self.fake_atv.last_airplay_url, STREAM)
self.assertEqual(self.fake_atv.last_airplay_start, START_POSITION)
self.assertEqual(self.no_of_sleeps, 2) # playback + idle = 3

session.close()
@unittest_run_loop
def test_play_when_device_not_ready(self):
self.usecase.airplay_playback_not_ready()

aplay = player.AirPlayPlayer(
self.loop, '127.0.0.1', port=self.app.port)
yield from aplay.play_url(STREAM, position=START_POSITION)

self.assertEqual(self.no_of_sleeps, 0)
5 changes: 5 additions & 0 deletions tests/fake_daap_atv.py
Expand Up @@ -477,6 +477,11 @@ def airplay_playback_idle(self):
self.device.responses['airplay_playback'].insert(
0, AirPlayPlaybackResponse(plistlib.dumps(plist)))

def airplay_playback_not_ready(self):
"""Make playback-info return device not being ready."""
self.device.responses['airplay_playback'].insert(
0, AirPlayPlaybackResponse(plistlib.dumps(dict())))

def set_property(self, prop, value):
"""Change value of a property."""
# Use "fictional" properties to not tie them to DAP (if some other
Expand Down

0 comments on commit 4fa6e3f

Please sign in to comment.