Skip to content

Commit

Permalink
Upgrade aiohttp to 1.3.0
Browse files Browse the repository at this point in the history
Also fix some errors in the tests so that sessions aren't leaking
anymore. This fixes #1.
  • Loading branch information
postlund committed Feb 9, 2017
1 parent dcf76b9 commit db2de78
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 38 deletions.
7 changes: 0 additions & 7 deletions docs/testing.rst
Expand Up @@ -88,14 +88,7 @@ example (boiler plate code for creating a device is done during setup):
self.assertEqual(playing.media_type, const.MEDIA_TYPE_UNKNOWN)
self.assertEqual(playing.play_state, const.PLAY_STATE_NO_MEDIA)
yield from self.atv.logout()
It's easy to see that the usecase *nothing_playing* is used, which configures
the fake device in such a way that nothing is playing. Metadata is then
fetched with the regular public API and verified to be correct. Most test
cases look like this, which make them easy to understand.

.. note::

Currently, a logout must be done explicitly from the test case. This will
be fixed in the future.
1 change: 0 additions & 1 deletion pyatv/internal/apple_tv.py
Expand Up @@ -21,7 +21,6 @@ class BaseAppleTV:
def __init__(self, requester):
"""Initialize a new Apple TV base implemenation."""
self.daap = requester
self.controlpromptupdate()

def server_info(self):
"""Request and return server information."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -16,7 +16,7 @@
zip_safe=False,
platforms='any',
install_requires=[
'aiohttp==1.2.0',
'aiohttp==1.3.0',
'zeroconf==0.18.0',
],
test_suite='tests',
Expand Down
34 changes: 5 additions & 29 deletions tests/test_functional.py
@@ -1,6 +1,7 @@
"""Functional tests using the API with a fake Apple TV."""

import pyatv
import asyncio
import aiohttp
import ipaddress

Expand Down Expand Up @@ -34,10 +35,12 @@ def setUp(self):
self.log_handler = LogOutputHandler(self)

def tearDown(self):
self.loop.run_until_complete(self.atv.logout())
AioHTTPTestCase.tearDown(self)
self.log_handler.tearDown()

def get_app(self, loop):
@asyncio.coroutine
def get_application(self, loop):
self.fake_atv = FakeAppleTV(
loop, HSGID, PAIRING_GUID, SESSION_ID, self)
self.usecase = AppleTVUseCases(self.fake_atv)
Expand Down Expand Up @@ -106,7 +109,6 @@ def test_pairing_with_device(self):
response.close()
yield from session.close()
yield from handler.stop()
yield from self.atv.logout()

@unittest_run_loop
def test_play_url(self):
Expand All @@ -128,8 +130,6 @@ def test_login_failed(self):
with self.assertRaises(exceptions.AuthenticationError):
yield from self.atv.login()

yield from self.atv.logout()

# This test verifies issue #2 (automatic re-login). It uses the artwork
# API, but it could have been any API since the login code is the same.
@unittest_run_loop
Expand All @@ -146,78 +146,66 @@ def test_relogin_if_session_expired(self):
artwork = yield from self.atv.metadata.artwork()
self.assertEqual(artwork, EXPECTED_ARTWORK)

yield from self.atv.logout()

@unittest_run_loop
def test_login_with_hsgid_succeed(self):
session_id = yield from self.atv.login()
self.assertEqual(SESSION_ID, session_id)
yield from self.atv.logout()

@unittest_run_loop
def test_login_with_pairing_guid_succeed(self):
yield from self.atv.logout()
self.atv = self.get_connected_device(PAIRING_GUID)
session_id = yield from self.atv.login()
self.assertEqual(SESSION_ID, session_id)
yield from self.atv.logout()

@unittest_run_loop
def test_button_play(self):
yield from self.atv.remote_control.play()
self.assertEqual(self.fake_atv.last_button_pressed, 'play')
yield from self.atv.logout()

@unittest_run_loop
def test_button_pause(self):
yield from self.atv.remote_control.pause()
self.assertEqual(self.fake_atv.last_button_pressed, 'pause')
yield from self.atv.logout()

@unittest_run_loop
def test_button_next(self):
yield from self.atv.remote_control.next()
self.assertEqual(self.fake_atv.last_button_pressed, 'nextitem')
yield from self.atv.logout()

@unittest_run_loop
def test_button_previous(self):
yield from self.atv.remote_control.previous()
self.assertEqual(self.fake_atv.last_button_pressed, 'previtem')
yield from self.atv.logout()

@unittest_run_loop
def test_button_select(self):
yield from self.atv.remote_control.select()
self.assertEqual(self.fake_atv.last_button_pressed, 'select')
yield from self.atv.logout()

@unittest_run_loop
def test_button_menu(self):
yield from self.atv.remote_control.menu()
self.assertEqual(self.fake_atv.last_button_pressed, 'menu')
yield from self.atv.logout()

@unittest_run_loop
def test_button_topmenu(self):
yield from self.atv.remote_control.topmenu()
self.assertEqual(self.fake_atv.last_button_pressed, 'topmenu')
yield from self.atv.logout()

@unittest_run_loop
def test_metadata_artwork(self):
self.usecase.change_artwork(EXPECTED_ARTWORK)

artwork = yield from self.atv.metadata.artwork()
self.assertEqual(artwork, EXPECTED_ARTWORK)
yield from self.atv.logout()

@unittest_run_loop
def test_metadata_artwork_none_if_not_available(self):
self.usecase.change_artwork(b'')

artwork = yield from self.atv.metadata.artwork()
self.assertIsNone(artwork)
yield from self.atv.logout()

@unittest_run_loop
def test_metadata_none_type_when_not_playing(self):
Expand All @@ -227,8 +215,6 @@ def test_metadata_none_type_when_not_playing(self):
self.assertEqual(playing.media_type, const.MEDIA_TYPE_UNKNOWN)
self.assertEqual(playing.play_state, const.PLAY_STATE_NO_MEDIA)

yield from self.atv.logout()

@unittest_run_loop
def test_metadata_video_paused(self):
self.usecase.video_playing(paused=True, title='dummy',
Expand All @@ -241,8 +227,6 @@ def test_metadata_video_paused(self):
self.assertEqual(playing.total_time, 123)
self.assertEqual(playing.position, 3)

yield from self.atv.logout()

@unittest_run_loop
def test_metadata_video_playing(self):
self.usecase.video_playing(paused=False, title='video',
Expand All @@ -255,8 +239,6 @@ def test_metadata_video_playing(self):
self.assertEqual(playing.total_time, 40)
self.assertEqual(playing.position, 10)

yield from self.atv.logout()

@unittest_run_loop
def test_metadata_music_paused(self):
self.usecase.music_playing(paused=True, title='music',
Expand All @@ -272,8 +254,6 @@ def test_metadata_music_paused(self):
self.assertEqual(playing.total_time, 222)
self.assertEqual(playing.position, 49)

yield from self.atv.logout()

@unittest_run_loop
def test_metadata_music_playing(self):
self.usecase.music_playing(paused=False, title='music',
Expand All @@ -289,18 +269,14 @@ def test_metadata_music_playing(self):
self.assertEqual(playing.total_time, 2)
self.assertEqual(playing.position, 1)

yield from self.atv.logout()

@unittest_run_loop
def test_seek_in_playing_media(self):
yield from self.atv.remote_control.set_position(60)
self.assertEqual(self.fake_atv.properties['dacp.playingtime'], 60000)
yield from self.atv.logout()

@unittest_run_loop
def test_metadata_loading(self):
self.usecase.media_is_loading()

playing = yield from self.atv.metadata.playing()
self.assertEqual(playing.play_state, const.PLAY_STATE_LOADING)
yield from self.atv.logout()

0 comments on commit db2de78

Please sign in to comment.