Fix aiohttp deprecation warnings (#13240)
* Fix aiohttp deprecation warnings * Fix Ring deprecation warning * Lint
This commit is contained in:
parent
a86bf81768
commit
89a19c89a7
45 changed files with 221 additions and 225 deletions
|
@ -49,7 +49,7 @@ REGISTER_URL = '/api/notify.html5'
|
|||
PUBLISH_URL = '/api/notify.html5/callback'
|
||||
|
||||
|
||||
async def mock_client(hass, test_client, registrations=None):
|
||||
async def mock_client(hass, aiohttp_client, registrations=None):
|
||||
"""Create a test client for HTML5 views."""
|
||||
if registrations is None:
|
||||
registrations = {}
|
||||
|
@ -62,7 +62,7 @@ async def mock_client(hass, test_client, registrations=None):
|
|||
}
|
||||
})
|
||||
|
||||
return await test_client(hass.http.app)
|
||||
return await aiohttp_client(hass.http.app)
|
||||
|
||||
|
||||
class TestHtml5Notify(object):
|
||||
|
@ -151,9 +151,9 @@ class TestHtml5Notify(object):
|
|||
assert mock_wp.mock_calls[4][2]['gcm_key'] is None
|
||||
|
||||
|
||||
async def test_registering_new_device_view(hass, test_client):
|
||||
async def test_registering_new_device_view(hass, aiohttp_client):
|
||||
"""Test that the HTML view works."""
|
||||
client = await mock_client(hass, test_client)
|
||||
client = await mock_client(hass, aiohttp_client)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_1))
|
||||
|
@ -165,9 +165,9 @@ async def test_registering_new_device_view(hass, test_client):
|
|||
}
|
||||
|
||||
|
||||
async def test_registering_new_device_expiration_view(hass, test_client):
|
||||
async def test_registering_new_device_expiration_view(hass, aiohttp_client):
|
||||
"""Test that the HTML view works."""
|
||||
client = await mock_client(hass, test_client)
|
||||
client = await mock_client(hass, aiohttp_client)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_4))
|
||||
|
@ -178,10 +178,10 @@ async def test_registering_new_device_expiration_view(hass, test_client):
|
|||
}
|
||||
|
||||
|
||||
async def test_registering_new_device_fails_view(hass, test_client):
|
||||
async def test_registering_new_device_fails_view(hass, aiohttp_client):
|
||||
"""Test subs. are not altered when registering a new device fails."""
|
||||
registrations = {}
|
||||
client = await mock_client(hass, test_client, registrations)
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json',
|
||||
side_effect=HomeAssistantError()):
|
||||
|
@ -191,10 +191,10 @@ async def test_registering_new_device_fails_view(hass, test_client):
|
|||
assert registrations == {}
|
||||
|
||||
|
||||
async def test_registering_existing_device_view(hass, test_client):
|
||||
async def test_registering_existing_device_view(hass, aiohttp_client):
|
||||
"""Test subscription is updated when registering existing device."""
|
||||
registrations = {}
|
||||
client = await mock_client(hass, test_client, registrations)
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_1))
|
||||
|
@ -209,10 +209,10 @@ async def test_registering_existing_device_view(hass, test_client):
|
|||
}
|
||||
|
||||
|
||||
async def test_registering_existing_device_fails_view(hass, test_client):
|
||||
async def test_registering_existing_device_fails_view(hass, aiohttp_client):
|
||||
"""Test sub. is not updated when registering existing device fails."""
|
||||
registrations = {}
|
||||
client = await mock_client(hass, test_client, registrations)
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_1))
|
||||
|
@ -225,9 +225,9 @@ async def test_registering_existing_device_fails_view(hass, test_client):
|
|||
}
|
||||
|
||||
|
||||
async def test_registering_new_device_validation(hass, test_client):
|
||||
async def test_registering_new_device_validation(hass, aiohttp_client):
|
||||
"""Test various errors when registering a new device."""
|
||||
client = await mock_client(hass, test_client)
|
||||
client = await mock_client(hass, aiohttp_client)
|
||||
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps({
|
||||
'browser': 'invalid browser',
|
||||
|
@ -249,13 +249,13 @@ async def test_registering_new_device_validation(hass, test_client):
|
|||
assert resp.status == 400
|
||||
|
||||
|
||||
async def test_unregistering_device_view(hass, test_client):
|
||||
async def test_unregistering_device_view(hass, aiohttp_client):
|
||||
"""Test that the HTML unregister view works."""
|
||||
registrations = {
|
||||
'some device': SUBSCRIPTION_1,
|
||||
'other device': SUBSCRIPTION_2,
|
||||
}
|
||||
client = await mock_client(hass, test_client, registrations)
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
resp = await client.delete(REGISTER_URL, data=json.dumps({
|
||||
|
@ -269,11 +269,11 @@ async def test_unregistering_device_view(hass, test_client):
|
|||
}
|
||||
|
||||
|
||||
async def test_unregister_device_view_handle_unknown_subscription(hass,
|
||||
test_client):
|
||||
async def test_unregister_device_view_handle_unknown_subscription(
|
||||
hass, aiohttp_client):
|
||||
"""Test that the HTML unregister view handles unknown subscriptions."""
|
||||
registrations = {}
|
||||
client = await mock_client(hass, test_client, registrations)
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
resp = await client.delete(REGISTER_URL, data=json.dumps({
|
||||
|
@ -285,13 +285,14 @@ async def test_unregister_device_view_handle_unknown_subscription(hass,
|
|||
assert len(mock_save.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_unregistering_device_view_handles_save_error(hass, test_client):
|
||||
async def test_unregistering_device_view_handles_save_error(
|
||||
hass, aiohttp_client):
|
||||
"""Test that the HTML unregister view handles save errors."""
|
||||
registrations = {
|
||||
'some device': SUBSCRIPTION_1,
|
||||
'other device': SUBSCRIPTION_2,
|
||||
}
|
||||
client = await mock_client(hass, test_client, registrations)
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json',
|
||||
side_effect=HomeAssistantError()):
|
||||
|
@ -306,9 +307,9 @@ async def test_unregistering_device_view_handles_save_error(hass, test_client):
|
|||
}
|
||||
|
||||
|
||||
async def test_callback_view_no_jwt(hass, test_client):
|
||||
async def test_callback_view_no_jwt(hass, aiohttp_client):
|
||||
"""Test that the notification callback view works without JWT."""
|
||||
client = await mock_client(hass, test_client)
|
||||
client = await mock_client(hass, aiohttp_client)
|
||||
resp = await client.post(PUBLISH_URL, data=json.dumps({
|
||||
'type': 'push',
|
||||
'tag': '3bc28d69-0921-41f1-ac6a-7a627ba0aa72'
|
||||
|
@ -317,12 +318,12 @@ async def test_callback_view_no_jwt(hass, test_client):
|
|||
assert resp.status == 401, resp.response
|
||||
|
||||
|
||||
async def test_callback_view_with_jwt(hass, test_client):
|
||||
async def test_callback_view_with_jwt(hass, aiohttp_client):
|
||||
"""Test that the notification callback view works with JWT."""
|
||||
registrations = {
|
||||
'device': SUBSCRIPTION_1
|
||||
}
|
||||
client = await mock_client(hass, test_client, registrations)
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
|
||||
with patch('pywebpush.WebPusher') as mock_wp:
|
||||
await hass.services.async_call('notify', 'notify', {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue