예제 #1
0
async def test_on_welcome(app, init_app, client, mocker, welcome):
    conn = connection.fget(app)
    status = service_status.fget(app)
    status.set_autoconnecting(True)

    ok_msg = ','.join(welcome)
    nok_welcome = welcome.copy()
    nok_welcome[2] = 'NOPE'
    nok_msg = ','.join(nok_welcome)
    conn._on_event(ok_msg)
    assert status.desc().handshake_info.is_compatible_firmware

    status.service_info.device_id = '1234567f0case'
    conn._on_event(ok_msg)
    assert status.desc().handshake_info.is_valid_device_id

    status.service_info.device_id = '01345'
    with pytest.warns(UserWarning, match='Handshake error'):
        conn._on_event(ok_msg)
    assert not status.desc().handshake_info.is_valid_device_id

    status.service_info.device_id = None
    app['config']['skip_version_check'] = True
    conn._on_event(nok_msg)
    assert status.desc().handshake_info.is_compatible_firmware

    app['config']['skip_version_check'] = False
    with pytest.warns(UserWarning, match='Handshake error'):
        conn._on_event(nok_msg)
    assert not status.desc().handshake_info.is_compatible_firmware
    assert not status.desc().is_synchronized
def states(app):
    status = service_status.fget(app)
    return [
        status.disconnected_ev.is_set(),
        status.connected_ev.is_set(),
        status.synchronized_ev.is_set(),
    ]
async def test_on_welcome(app, init_app, client, mocker, welcome):
    mocker.patch(TESTED + '.web.GracefulExit', DummyExit)
    conn = connection.fget(app)
    status = service_status.fget(app)
    status.set_autoconnecting(True)

    ok_msg = ','.join(welcome)
    nok_welcome = welcome.copy()
    nok_welcome[2] = 'NOPE'
    nok_msg = ','.join(nok_welcome)
    await conn._on_event(ok_msg)
    assert status.desc().handshake_info.is_compatible_firmware
    status.service_info.device_id = '1234567f0case'
    await conn._on_event(ok_msg)
    assert status.desc().handshake_info.is_valid_device_id

    status.service_info.device_id = '01345'
    with pytest.warns(UserWarning, match='Handshake error'):
        await conn._on_event(ok_msg)
    assert not status.desc().handshake_info.is_valid_device_id

    status.service_info.device_id = None
    app['config']['skip_version_check'] = True
    await conn._on_event(nok_msg)
    assert status.desc().handshake_info.is_compatible_firmware

    app['config']['skip_version_check'] = False
    with pytest.warns(UserWarning, match='Handshake error'):
        await conn._on_event(nok_msg)
    assert not status.desc().handshake_info.is_compatible_firmware
    assert not status.desc().is_synchronized

    with pytest.raises(DummyExit):
        await conn._on_event(connection.SETUP_MODE_PREFIX)
예제 #4
0
async def test_on_cbox_err(app, init_app, client, cbox_err):
    conn = connection.fget(app)
    status = service_status.fget(app)
    status.set_connected('addr')
    assert status.desc().device_address == 'addr'

    msg = ':'.join(cbox_err)
    conn._on_event(msg)

    # shouldn't fail on non-existent error message
    msg = ':'.join([cbox_err[0], 'ffff'])
    conn._on_event(msg)

    # shouldn't fail on invalid error
    msg = ':'.join([cbox_err[0], 'not hex'])
    conn._on_event(msg)
예제 #5
0
async def test_start_update(app, client):
    service_status.fget(app).set_updating()

    with pytest.raises(exceptions.UpdateInProgress):
        await spark.fget(app).list_objects()
async def test_start_update(app, client):
    await service_status.wait_synchronized(app)
    service_status.fget(app).set_updating()

    with pytest.raises(exceptions.UpdateInProgress):
        await controller.fget(app).read_all_blocks()