Ejemplo n.º 1
0
async def test_override(attached_pipettes):
    # This test will check that setting modified pipette configs
    # works as expected
    changes = {'pickUpCurrent': 1}

    test_id = attached_pipettes['left']['id']
    # Check data has not been changed yet
    c, _ = pipette_config.load_config_dict(test_id)
    assert c['pickUpCurrent'] == \
        pipette_config.list_mutable_configs(
            pipette_id=test_id)['pickUpCurrent']

    # Check that data is changed and matches the changes specified
    pipette_config.override(pipette_id=test_id, fields=changes)

    c, _ = pipette_config.load_config_dict(test_id)
    assert c['pickUpCurrent']['value'] == changes['pickUpCurrent']

    # Check that None reverts a setting to default
    changes2 = {'pickUpCurrent': None}
    # Check that data is changed and matches the changes specified
    pipette_config.override(pipette_id=test_id, fields=changes2)

    c, _ = pipette_config.load_config_dict(test_id)
    assert c['pickUpCurrent']['value'] == \
        pipette_config.list_mutable_configs(
            pipette_id=test_id)['pickUpCurrent']['default']
Ejemplo n.º 2
0
async def test_incorrect_modify_pipette_settings(attached_pipettes):
    out_of_range = {'pickUpCurrent': 1000}
    with pytest.raises(ValueError,
                       match='pickUpCurrent out of range with 1000'):
        # check over max fails
        pipette_config.override(pipette_id=attached_pipettes['left']['id'],
                                fields=out_of_range)
Ejemplo n.º 3
0
async def modify_pipette_settings(request: web.Request) -> web.Response:
    """
    Expects a dictionary with mutable configs
    wrapped in a `fields` key such as:
    {
        'fields': {
            'pickUpCurrent': {'value': some_value},
            'dropTipSpeed': {'value': some_value}
        }

    }
    If a value needs to be reset, simply type in the body formatted as above:
        'configKey': null

    }
    """
    pipette_id = request.match_info['id']

    data = await request.json()
    fields = data.get('fields', {})
    # Convert fields to dict of field name to value
    fields = {
        k: None if v is None else v.get('value')
        for k, v in fields.items()
    }
    if fields:
        try:
            pc.override(fields=fields, pipette_id=pipette_id)
        except ValueError as e:
            return web.json_response({'message': str(e)}, status=412)

    updated_configs = {'fields': pc.list_mutable_configs(pipette_id)}
    return web.json_response(updated_configs, status=200)
Ejemplo n.º 4
0
async def patch_pipette_setting(
        pipette_id: str,
        settings_update: PipetteSettingsUpdate) \
        -> PipetteSettings:

    # Convert fields to dict of field name to value
    fields = settings_update.setting_fields or {}
    field_values = {
        k: None if v is None else v.value
        for k, v in fields.items()
    }
    if field_values:
        try:
            pipette_config.override(fields=field_values, pipette_id=pipette_id)
        except ValueError as e:
            raise V1HandlerError(
                status_code=status.HTTP_412_PRECONDITION_FAILED,
                message=str(e))
    r = _pipette_settings_from_config(pipette_config, pipette_id)
    return r