Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion homeassistant/components/notify/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
ATTR_KEYS = 'keys'
ATTR_AUTH = 'auth'
ATTR_P256DH = 'p256dh'
ATTR_EXPIRATIONTIME = 'expirationTime'

ATTR_TAG = 'tag'
ATTR_ACTION = 'action'
Expand All @@ -71,7 +72,9 @@
vol.Schema({
# pylint: disable=no-value-for-parameter
vol.Required(ATTR_ENDPOINT): vol.Url(),
vol.Required(ATTR_KEYS): KEYS_SCHEMA
vol.Required(ATTR_KEYS): KEYS_SCHEMA,
vol.Optional(ATTR_EXPIRATIONTIME):
vol.Any(None, cv.positive_int)
}))

REGISTER_SCHEMA = vol.Schema({
Expand Down
46 changes: 46 additions & 0 deletions tests/components/notify/test_html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
},
},
}
SUBSCRIPTION_4 = {
'browser': 'chrome',
'subscription': {
'endpoint': 'https://google.com',
'expirationTime': None,
'keys': {'auth': 'auth', 'p256dh': 'p256dh'}
},
}

REGISTER_URL = '/api/notify.html5'
PUBLISH_URL = '/api/notify.html5/callback'
Expand Down Expand Up @@ -139,6 +147,44 @@ def test_registering_new_device_view(self, loop, test_client):
handle = m()
assert json.loads(handle.write.call_args[0][0]) == expected

@asyncio.coroutine
def test_registering_new_device_expiration_view(self, loop, test_client):
"""Test that the HTML view works."""
hass = MagicMock()
expected = {
'unnamed device': SUBSCRIPTION_4,
}

m = mock_open()
with patch(
'homeassistant.components.notify.html5.open', m, create=True
):
hass.config.path.return_value = 'file.conf'
service = html5.get_service(hass, {})

assert service is not None

# assert hass.called
assert len(hass.mock_calls) == 3

view = hass.mock_calls[1][1][0]
assert view.json_path == hass.config.path.return_value
assert view.registrations == {}

hass.loop = loop
app = mock_http_component_app(hass)
view.register(app.router)
client = yield from test_client(app)
hass.http.is_banned_ip.return_value = False
resp = yield from client.post(REGISTER_URL,
data=json.dumps(SUBSCRIPTION_4))

content = yield from resp.text()
assert resp.status == 200, content
assert view.registrations == expected
handle = m()
assert json.loads(handle.write.call_args[0][0]) == expected

@asyncio.coroutine
def test_registering_new_device_validation(self, loop, test_client):
"""Test various errors when registering a new device."""
Expand Down