Esempio n. 1
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']
    whole_config = pc.load_config_dict(pipette_id)
    config_match = pc.list_mutable_configs(pipette_id)
    data = await request.json()
    if not data.get('fields'):
        return web.json_response(config_match, status=200)

    for key, value in data['fields'].items():
        if value and not isinstance(value['value'], bool):
            config = value['value']
            default = config_match[key]
            if config < default['min'] or config > default['max']:
                return web.json_response(
                    {'message': '{} out of range with {}'.format(key, config)},
                    status=412)
    pc.save_overrides(pipette_id, data['fields'], whole_config.get('model'))
    updated_configs = {'fields': pc.list_mutable_configs(pipette_id)}
    return web.json_response(updated_configs, status=200)
Esempio n. 2
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']
async def test_modify_pipette_settings(
        async_server, loop, async_client, attached_pipettes):
    # This test will check that setting modified pipette configs
    # works as expected
    changes = {
        'fields': {
            'pickUpCurrent': {'value': 1}
        }
    }

    no_changes = {
        'fields': {
            'pickUpCurrent': {'value': 1}
            }
        }

    test_id = attached_pipettes['left']['id']
    # Check data has not been changed yet
    resp = await async_client.get('/settings/pipettes/{}'.format(test_id))
    body = await resp.json()
    assert body['fields']['pickUpCurrent'] == \
        pipette_config.list_mutable_configs(
            pipette_id=test_id)['pickUpCurrent']

    # Check that data is changed and matches the changes specified
    resp = await async_client.patch(
        '/settings/pipettes/{}'.format(test_id),
        json=changes)
    patch_body = await resp.json()
    assert resp.status == 200
    check = await async_client.get('/settings/pipettes/{}'.format(test_id))
    body = await check.json()
    print(patch_body)
    assert body['fields'] == patch_body['fields']

    # Check that None reverts a setting to default
    changes2 = {
        'fields': {
            'pickUpCurrent': None
            }
        }
    resp = await async_client.patch(
        '/settings/pipettes/{}'.format(test_id),
        json=changes2)
    assert resp.status == 200
    check = await async_client.get('/settings/pipettes/{}'.format(test_id))
    body = await check.json()
    assert body['fields']['pickUpCurrent']['value'] == \
        pipette_config.list_mutable_configs(
            pipette_id=test_id)['pickUpCurrent']['default']

    # check no fields returns no changes
    resp = await async_client.patch(
        '/settings/pipettes/{}'.format(test_id),
        json=no_changes)
    body = await resp.json()
    assert body['fields'] == pipette_config.list_mutable_configs(test_id)
    assert resp.status == 200
Esempio n. 4
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)
Esempio n. 5
0
async def test_receive_pipette_settings(async_client, attached_pipettes):

    test_id = attached_pipettes['left']['id']
    resp = await async_client.get('/settings/pipettes')
    body = await resp.json()
    assert test_id in body
    assert body[test_id]['fields'] == pipette_config.list_mutable_configs(
        pipette_id=test_id)
Esempio n. 6
0
def _make_pipette_response_body(pipette_id):
    whole_config = pc.load_config_dict(pipette_id)
    res = {
        'info': {
            'name': whole_config.get('name'),
            'model': whole_config.get('model')
        },
        'fields': pc.list_mutable_configs(pipette_id)
    }
    return res
Esempio n. 7
0
async def pipette_settings(request: web.Request) -> web.Response:
    res = {}
    for id in pc.known_pipettes():
        whole_config = pc.load_config_dict(id)
        res[id] = {
            'info': {
                'name': whole_config.get('name'),
                'model': whole_config.get('model')
            },
            'fields': pc.list_mutable_configs(pipette_id=id)
        }
    return web.json_response(res, status=200)
async def test_receive_pipette_settings_one_pipette(
        async_server, loop, async_client, attached_pipettes):
    # This will check that sending a known pipette id works,
    # and sending an unknown one does not
    test_id = attached_pipettes['left']['id']
    resp = await async_client.get('/settings/pipettes/{}'.format(test_id))
    body = await resp.json()
    assert body['fields'] == pipette_config.list_mutable_configs(
        pipette_id=test_id)

    # Non-existent pipette id and get 404
    resp = await async_client.get(
        '/settings/pipettes/{}'.format('wannabepipette'))
    assert resp.status == 404
Esempio n. 9
0
async def pipette_settings_id(request: web.Request) -> web.Response:
    pipette_id = request.match_info['id']
    if pipette_id not in pc.known_pipettes():
        return web.json_response(
            {'message': '{} is not a valid pipette id'.format(pipette_id)},
            status=404)
    whole_config = pc.load_config_dict(pipette_id)
    res = {
        'info': {
            'name': whole_config.get('name'),
            'model': whole_config.get('model')
        },
        'fields': pc.list_mutable_configs(pipette_id)
    }
    return web.json_response(res, status=200)
Esempio n. 10
0
def test_mutable_configs_only(monkeypatch):
    # Test that only set mutable configs are populated in this dictionary

    monkeypatch.setattr(pipette_config, 'MUTABLE_CONFIGS',
                        ['tipLength', 'plungerCurrent'])

    new_id = 'aoa2109j09cj2a'
    model = 'p300_multi_v1'

    pipette_config.save_overrides(new_id, {}, model)

    config = pipette_config.list_mutable_configs(new_id)
    # instead of dealing with unordered lists, convert to set and check whether
    # these lists have a difference between them
    difference = set(list(config.keys())) - \
        set(pipette_config.MUTABLE_CONFIGS)
    # ensure empty
    assert bool(difference) is False
Esempio n. 11
0
def test_mutable_configs_unknown_pipette_id():
    with patch("opentrons.config.pipette_config.known_pipettes",
               return_val={}):
        config = pipette_config.list_mutable_configs("a")
        assert config == {}