1 parent
ae9e3d83d7
commit
d1a621601d
42 files changed
+307
-473
No files matched your search
@@ -49,7 +49,7 @@ REGISTER_URL = '/api/notify.html5'
|
||||
PUBLISH_URL = '/api/notify.html5/callback'
|
||||
|
||||
|
||||
async def mock_client(hass, aiohttp_client, registrations=None):
|
||||
async def mock_client(hass, hass_client, registrations=None):
|
||||
"""Create a test client for HTML5 views."""
|
||||
if registrations is None:
|
||||
registrations = {}
|
||||
@@ -62,7 +62,7 @@ async def mock_client(hass, aiohttp_client, registrations=None):
|
||||
}
|
||||
})
|
||||
|
||||
return await aiohttp_client(hass.http.app)
|
||||
return await hass_client()
|
||||
|
||||
|
||||
class TestHtml5Notify:
|
||||
@@ -151,9 +151,9 @@ class TestHtml5Notify:
|
||||
assert mock_wp.mock_calls[4][2]['gcm_key'] is None
|
||||
|
||||
|
||||
async def test_registering_new_device_view(hass, aiohttp_client):
|
||||
async def test_registering_new_device_view(hass, hass_client):
|
||||
"""Test that the HTML view works."""
|
||||
client = await mock_client(hass, aiohttp_client)
|
||||
client = await mock_client(hass, hass_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, aiohttp_client):
|
||||
}
|
||||
|
||||
|
||||
async def test_registering_new_device_expiration_view(hass, aiohttp_client):
|
||||
async def test_registering_new_device_expiration_view(hass, hass_client):
|
||||
"""Test that the HTML view works."""
|
||||
client = await mock_client(hass, aiohttp_client)
|
||||
client = await mock_client(hass, hass_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, aiohttp_client):
|
||||
}
|
||||
|
||||
|
||||
async def test_registering_new_device_fails_view(hass, aiohttp_client):
|
||||
async def test_registering_new_device_fails_view(hass, hass_client):
|
||||
"""Test subs. are not altered when registering a new device fails."""
|
||||
registrations = {}
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
client = await mock_client(hass, hass_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, aiohttp_client):
|
||||
assert registrations == {}
|
||||
|
||||
|
||||
async def test_registering_existing_device_view(hass, aiohttp_client):
|
||||
async def test_registering_existing_device_view(hass, hass_client):
|
||||
"""Test subscription is updated when registering existing device."""
|
||||
registrations = {}
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
client = await mock_client(hass, hass_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, aiohttp_client):
|
||||
}
|
||||
|
||||
|
||||
async def test_registering_existing_device_fails_view(hass, aiohttp_client):
|
||||
async def test_registering_existing_device_fails_view(hass, hass_client):
|
||||
"""Test sub. is not updated when registering existing device fails."""
|
||||
registrations = {}
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
client = await mock_client(hass, hass_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, aiohttp_client):
|
||||
}
|
||||
|
||||
|
||||
async def test_registering_new_device_validation(hass, aiohttp_client):
|
||||
async def test_registering_new_device_validation(hass, hass_client):
|
||||
"""Test various errors when registering a new device."""
|
||||
client = await mock_client(hass, aiohttp_client)
|
||||
client = await mock_client(hass, hass_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, aiohttp_client):
|
||||
assert resp.status == 400
|
||||
|
||||
|
||||
async def test_unregistering_device_view(hass, aiohttp_client):
|
||||
async def test_unregistering_device_view(hass, hass_client):
|
||||
"""Test that the HTML unregister view works."""
|
||||
registrations = {
|
||||
'some device': SUBSCRIPTION_1,
|
||||
'other device': SUBSCRIPTION_2,
|
||||
}
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
resp = await client.delete(REGISTER_URL, data=json.dumps({
|
||||
@@ -270,10 +270,10 @@ async def test_unregistering_device_view(hass, aiohttp_client):
|
||||
|
||||
|
||||
async def test_unregister_device_view_handle_unknown_subscription(
|
||||
hass, aiohttp_client):
|
||||
hass, hass_client):
|
||||
"""Test that the HTML unregister view handles unknown subscriptions."""
|
||||
registrations = {}
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
resp = await client.delete(REGISTER_URL, data=json.dumps({
|
||||
@@ -286,13 +286,13 @@ async def test_unregister_device_view_handle_unknown_subscription(
|
||||
|
||||
|
||||
async def test_unregistering_device_view_handles_save_error(
|
||||
hass, aiohttp_client):
|
||||
hass, hass_client):
|
||||
"""Test that the HTML unregister view handles save errors."""
|
||||
registrations = {
|
||||
'some device': SUBSCRIPTION_1,
|
||||
'other device': SUBSCRIPTION_2,
|
||||
}
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json',
|
||||
side_effect=HomeAssistantError()):
|
||||
@@ -307,23 +307,23 @@ async def test_unregistering_device_view_handles_save_error(
|
||||
}
|
||||
|
||||
|
||||
async def test_callback_view_no_jwt(hass, aiohttp_client):
|
||||
async def test_callback_view_no_jwt(hass, hass_client):
|
||||
"""Test that the notification callback view works without JWT."""
|
||||
client = await mock_client(hass, aiohttp_client)
|
||||
client = await mock_client(hass, hass_client)
|
||||
resp = await client.post(PUBLISH_URL, data=json.dumps({
|
||||
'type': 'push',
|
||||
'tag': '3bc28d69-0921-41f1-ac6a-7a627ba0aa72'
|
||||
}))
|
||||
|
||||
assert resp.status == 401, resp.response
|
||||
assert resp.status == 401
|
||||
|
||||
|
||||
async def test_callback_view_with_jwt(hass, aiohttp_client):
|
||||
async def test_callback_view_with_jwt(hass, hass_client):
|
||||
"""Test that the notification callback view works with JWT."""
|
||||
registrations = {
|
||||
'device': SUBSCRIPTION_1
|
||||
}
|
||||
client = await mock_client(hass, aiohttp_client, registrations)
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('pywebpush.WebPusher') as mock_wp:
|
||||
await hass.services.async_call('notify', 'notify', {
|
||||
|
||||
Reference in new issue
Block a user