def test_update_devices_fail_noinit():
    api = OwletAPI()

    with pytest.raises(OwletNotInitializedException) as info:
        api.update_devices()

    assert 'Please login first' in str(info.value)
def test_update_devices_fail_noresponse():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)

    api = OwletAPI()
    api.set_email("*****@*****.**")
    api.set_password("moped")
    api.login()

    with pytest.raises(OwletTemporaryCommunicationException) as info:
        api.update_devices()

    assert 'Server request failed - no response' in str(info.value)
def test_update_devices_fail_invalidjson():
    responses.add(responses.POST,
                  'https://user-field.aylanetworks.com/users/sign_in.json',
                  json=LOGIN_PAYLOAD,
                  status=200)

    api = OwletAPI()
    api.set_email("*****@*****.**")
    api.set_password("moped")
    api.login()

    responses.add(responses.GET,
                  'https://ads-field.aylanetworks.com/apiv1/devices.json',
                  body="invalid",
                  status=200)

    with pytest.raises(OwletTemporaryCommunicationException) as info:
        api.update_devices()

    assert 'Server did not send valid json' in str(info.value)