notify.html5: use new json save and load functions (#10416)
* update to use new save_json and load_json * it is no longer possible to determine if the json file contains valid or empty data. * fix lint
This commit is contained in:
parent
c8648fbfb8
commit
59e943b3c1
2 changed files with 40 additions and 72 deletions
|
@ -57,24 +57,13 @@ class TestHtml5Notify(object):
|
|||
|
||||
m = mock_open()
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
service = html5.get_service(hass, {})
|
||||
|
||||
assert service is not None
|
||||
|
||||
def test_get_service_with_bad_json(self):
|
||||
"""Test ."""
|
||||
hass = MagicMock()
|
||||
|
||||
m = mock_open(read_data='I am not JSON')
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
):
|
||||
service = html5.get_service(hass, {})
|
||||
|
||||
assert service is None
|
||||
|
||||
@patch('pywebpush.WebPusher')
|
||||
def test_sending_message(self, mock_wp):
|
||||
"""Test sending message."""
|
||||
|
@ -86,7 +75,8 @@ class TestHtml5Notify(object):
|
|||
|
||||
m = mock_open(read_data=json.dumps(data))
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
service = html5.get_service(hass, {'gcm_sender_id': '100'})
|
||||
|
||||
|
@ -120,7 +110,8 @@ class TestHtml5Notify(object):
|
|||
|
||||
m = mock_open()
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
hass.config.path.return_value = 'file.conf'
|
||||
service = html5.get_service(hass, {})
|
||||
|
@ -158,7 +149,8 @@ class TestHtml5Notify(object):
|
|||
|
||||
m = mock_open()
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
hass.config.path.return_value = 'file.conf'
|
||||
service = html5.get_service(hass, {})
|
||||
|
@ -193,7 +185,8 @@ class TestHtml5Notify(object):
|
|||
|
||||
m = mock_open()
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
hass.config.path.return_value = 'file.conf'
|
||||
service = html5.get_service(hass, {})
|
||||
|
@ -222,7 +215,7 @@ class TestHtml5Notify(object):
|
|||
}))
|
||||
assert resp.status == 400
|
||||
|
||||
with patch('homeassistant.components.notify.html5._save_config',
|
||||
with patch('homeassistant.components.notify.html5.save_json',
|
||||
return_value=False):
|
||||
# resp = view.post(Request(builder.get_environ()))
|
||||
resp = yield from client.post(REGISTER_URL, data=json.dumps({
|
||||
|
@ -243,14 +236,12 @@ class TestHtml5Notify(object):
|
|||
}
|
||||
|
||||
m = mock_open(read_data=json.dumps(config))
|
||||
|
||||
with patch('homeassistant.components.notify.html5.open', m,
|
||||
create=True):
|
||||
with patch(
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
hass.config.path.return_value = 'file.conf'
|
||||
|
||||
with patch('homeassistant.components.notify.html5.os.path.isfile',
|
||||
return_value=True):
|
||||
service = html5.get_service(hass, {})
|
||||
service = html5.get_service(hass, {})
|
||||
|
||||
assert service is not None
|
||||
|
||||
|
@ -291,12 +282,11 @@ class TestHtml5Notify(object):
|
|||
|
||||
m = mock_open(read_data=json.dumps(config))
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
hass.config.path.return_value = 'file.conf'
|
||||
with patch('homeassistant.components.notify.html5.os.path.isfile',
|
||||
return_value=True):
|
||||
service = html5.get_service(hass, {})
|
||||
service = html5.get_service(hass, {})
|
||||
|
||||
assert service is not None
|
||||
|
||||
|
@ -324,7 +314,7 @@ class TestHtml5Notify(object):
|
|||
|
||||
@asyncio.coroutine
|
||||
def test_unregistering_device_view_handles_json_safe_error(
|
||||
self, loop, test_client):
|
||||
self, loop, test_client):
|
||||
"""Test that the HTML unregister view handles JSON write errors."""
|
||||
hass = MagicMock()
|
||||
|
||||
|
@ -335,12 +325,11 @@ class TestHtml5Notify(object):
|
|||
|
||||
m = mock_open(read_data=json.dumps(config))
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
hass.config.path.return_value = 'file.conf'
|
||||
with patch('homeassistant.components.notify.html5.os.path.isfile',
|
||||
return_value=True):
|
||||
service = html5.get_service(hass, {})
|
||||
service = html5.get_service(hass, {})
|
||||
|
||||
assert service is not None
|
||||
|
||||
|
@ -357,7 +346,7 @@ class TestHtml5Notify(object):
|
|||
client = yield from test_client(app)
|
||||
hass.http.is_banned_ip.return_value = False
|
||||
|
||||
with patch('homeassistant.components.notify.html5._save_config',
|
||||
with patch('homeassistant.components.notify.html5.save_json',
|
||||
return_value=False):
|
||||
resp = yield from client.delete(REGISTER_URL, data=json.dumps({
|
||||
'subscription': SUBSCRIPTION_1['subscription'],
|
||||
|
@ -375,7 +364,8 @@ class TestHtml5Notify(object):
|
|||
|
||||
m = mock_open()
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
hass.config.path.return_value = 'file.conf'
|
||||
service = html5.get_service(hass, {})
|
||||
|
@ -406,17 +396,16 @@ class TestHtml5Notify(object):
|
|||
hass = MagicMock()
|
||||
|
||||
data = {
|
||||
'device': SUBSCRIPTION_1,
|
||||
'device': SUBSCRIPTION_1
|
||||
}
|
||||
|
||||
m = mock_open(read_data=json.dumps(data))
|
||||
with patch(
|
||||
'homeassistant.components.notify.html5.open', m, create=True
|
||||
'homeassistant.util.json.open',
|
||||
m, create=True
|
||||
):
|
||||
hass.config.path.return_value = 'file.conf'
|
||||
with patch('homeassistant.components.notify.html5.os.path.isfile',
|
||||
return_value=True):
|
||||
service = html5.get_service(hass, {'gcm_sender_id': '100'})
|
||||
service = html5.get_service(hass, {'gcm_sender_id': '100'})
|
||||
|
||||
assert service is not None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue