def test_override_save(config_tempdir): cdir = CONFIG['pipette_config_overrides_dir'] overrides = { 'pickUpCurrent': { 'value': 1231.213 }, 'dropTipSpeed': { 'value': 121 }, 'dropTipShake': { 'value': False } } new_id = 'aoa2109j09cj2a' model = 'p300_multi_v1' old_pconf = pipette_config.load('p300_multi_v1.4', new_id) assert old_pconf.quirks == ['dropTipShake'] pipette_config.save_overrides(new_id, overrides, model) assert (cdir / f'{new_id}.json').is_file() loaded = pipette_config.load_overrides(new_id) assert loaded['pickUpCurrent']['value'] == \ overrides['pickUpCurrent']['value'] assert loaded['dropTipSpeed']['value'] == \ overrides['dropTipSpeed']['value'] new_pconf = pipette_config.load('p300_multi_v1.4', new_id) assert new_pconf.quirks == []
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)
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