Exemplo n.º 1
0
async def test_ignore_updates(virtual_smoothie_env, loop, test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    # Test no ignore file found
    r0 = await cli.get('/server/update/ignore')
    r0body = await r0.text()
    assert json.loads(r0body) == {'version': None}

    # Test that values are set correctly
    ignore_name = "testy_ignore.json"
    tmpdir = tempfile.mkdtemp("files")
    ignore_update.filepath = os.path.join(tmpdir, ignore_name)

    ignore = {'version': '3.1.3'}
    r1 = await cli.post('server/update/ignore', json=ignore)
    assert r1.status == 200

    # Test that you cannot pass an empty version
    ignore2 = {'version': ''}
    r2 = await cli.post('server/update/ignore', json=ignore2)
    assert r2.status == 400

    # Test that version in the temporary directory is still '3.1.3'
    r3 = await cli.get('/server/update/ignore')
    r3body = await r3.text()
    assert json.loads(r3body) == {'version': '3.1.3'}
Exemplo n.º 2
0
async def test_get_pipettes(virtual_smoothie_env, loop, test_client,
                            monkeypatch):
    test_model = 'p300_multi_v1'

    def dummy_read_model(mount):
        return test_model

    monkeypatch.setattr(robot._driver, 'read_pipette_model', dummy_read_model)
    robot.reset()

    app = init(loop)
    cli = await loop.create_task(test_client(app))

    model = pipette_config.load(test_model)
    expected = {
        'left': {
            'model': model.name,
            'tip_length': model.tip_length,
            'mount_axis': 'z',
            'plunger_axis': 'b'
        },
        'right': {
            'model': model.name,
            'tip_length': model.tip_length,
            'mount_axis': 'a',
            'plunger_axis': 'c'
        }
    }

    resp = await cli.get('/pipettes?refresh=true')
    text = await resp.text()
    assert resp.status == 200
    assert json.loads(text) == expected
Exemplo n.º 3
0
async def test_get_pipettes_uncommissioned(virtual_smoothie_env, loop,
                                           test_client, monkeypatch):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    def mock_parse_fail(self, gcode, mount):
        pass

    monkeypatch.setattr(SmoothieDriver_3_0_0, '_read_from_pipette',
                        mock_parse_fail)

    expected = {
        "left": {
            "mount_axis": "z",
            "plunger_axis": "b",
            "model": None
        },
        "right": {
            "mount_axis": "a",
            "plunger_axis": "c",
            "model": None
        }
    }

    robot._driver.simulating = False
    resp = await cli.get('/pipettes?refresh=true')
    robot._driver.simulating = True
    text = await resp.text()
    assert resp.status == 200
    assert json.loads(text) == expected
Exemplo n.º 4
0
async def test_wifi_list(virtual_smoothie_env, loop, test_client, monkeypatch):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    def mock_subprocess(cmd):
        # Command: `nmcli --terse --fields ssid,signal,active device wifi list`
        res = """Opentrons:81:yes
Big Duck:47:no
HP-Print-1-LaserJet Pro:35:no
Guest Wireless:24:no
"""
        return res, ''

    monkeypatch.setattr(wifi, '_subprocess', mock_subprocess)

    expected = json.dumps({
        'list': [
            {'ssid': 'Opentrons', 'signal': 81, 'active': True},
            {'ssid': 'Big Duck', 'signal': 47, 'active': False},
            {'ssid': 'HP-Print-1-LaserJet Pro', 'signal': 35, 'active': False},
            {'ssid': 'Guest Wireless', 'signal': 24, 'active': False}
        ]
    })

    resp = await cli.get('/wifi/list')
    text = await resp.text()
    assert resp.status == 200
    assert text == expected
Exemplo n.º 5
0
async def test_home_pipette_bad_request(virtual_smoothie_env, loop,
                                        test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    test_data = {}
    res = await cli.post('/robot/home', json=test_data)

    assert res.status == 400

    test_data_2 = {'target': 'pipette', 'mount': 'fake_mount'}

    res2 = await cli.post('/robot/home', json=test_data_2)

    assert res2.status == 400

    test_data_3 = {'mount': 'left'}

    res3 = await cli.post('/robot/home', json=test_data_3)

    assert res3.status == 400

    test_data_4 = {'target': 'pipette'}

    res4 = await cli.post('/robot/home', json=test_data_4)

    assert res4.status == 400
Exemplo n.º 6
0
async def test_get(virtual_smoothie_env, loop, test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    resp = await cli.get('/settings')
    body = await resp.json()
    assert resp.status == 200
    validate_response_body(body)
Exemplo n.º 7
0
async def test_home_robot(virtual_smoothie_env, loop, test_client):

    app = init(loop)
    cli = await loop.create_task(test_client(app))

    test_data = {'target': 'robot'}

    res = await cli.post('/robot/home', json=test_data)

    assert res.status == 200
Exemplo n.º 8
0
async def test_move_mount(virtual_smoothie_env, loop, test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))
    robot.home()
    # from opentrons.trackers import pose_tracker
    # print("Before: {}".format(tuple(
    #             pose_tracker.absolute(
    #                 robot.poses, robot._actuators['right']['carriage']))))
    data = {'target': 'mount', 'point': [100, 200, 50], 'mount': 'right'}
    res = await cli.post('/robot/move', json=data)
    assert res.status == 200
Exemplo n.º 9
0
async def test_set(virtual_smoothie_env, loop, test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))
    test_id = 'disableHomeOnBoot'

    resp = await cli.post('/settings', json={"id": test_id, "value": True})
    body = await resp.json()
    assert resp.status == 200
    validate_response_body(body)
    test_setting = list(
        filter(lambda x: x.get('id') == test_id, body.get('settings')))[0]
    assert test_setting.get('value')
Exemplo n.º 10
0
async def test_move_pipette(virtual_smoothie_env, loop, test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))
    robot.home()
    data = {
        'target': 'pipette',
        'point': [100, 200, 50],
        'mount': 'right',
        'model': 'p300_single_v1'
    }
    res = await cli.post('/robot/move', json=data)
    assert res.status == 200
Exemplo n.º 11
0
async def test_disengage_axes(virtual_smoothie_env, loop, test_client,
                              monkeypatch):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    def mock_send(self, command, timeout=None):
        pass

    monkeypatch.setattr(SmoothieDriver_3_0_0, '_send_command', mock_send)

    alltrue = {
        "x": {
            "enabled": True
        },
        "y": {
            "enabled": True
        },
        "z": {
            "enabled": True
        },
        "a": {
            "enabled": True
        },
        "b": {
            "enabled": True
        },
        "c": {
            "enabled": True
        }
    }
    res0 = await cli.get('/motors/engaged')
    result0 = await res0.text()
    assert res0.status == 200
    assert json.loads(result0) == alltrue

    postres = await cli.post('/motors/disengage', json={'axes': ['X', 'B']})
    assert postres.status == 200

    xbfalse = deepcopy(alltrue)
    xbfalse["x"]["enabled"] = False
    xbfalse["b"]["enabled"] = False
    res1 = await cli.get('/motors/engaged')
    result1 = await res1.text()
    assert res1.status == 200
    assert json.loads(result1) == xbfalse

    robot.home()
    res2 = await cli.get('/motors/engaged')
    result2 = await res2.text()
    assert res2.status == 200
    assert json.loads(result2) == alltrue
Exemplo n.º 12
0
async def test_robot_info(virtual_smoothie_env, loop, test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    res = await cli.get('/robot/positions')
    assert res.status == 200

    text = await res.text()
    body = json.loads(text)
    assert body['positions']['change_pipette']['target'] == 'mount'
    assert len(body['positions']['change_pipette']['left']) == 3
    assert len(body['positions']['change_pipette']['right']) == 3
    assert body['positions']['attach_tip']['target'] == 'pipette'
    assert len(body['positions']['attach_tip']['point']) == 3
Exemplo n.º 13
0
async def test_health(virtual_smoothie_env, loop, test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    expected = json.dumps({
        'name': 'opentrons-dev',
        'api_version': __version__,
        'fw_version': 'Virtual Smoothie',
        'logs': ['/logs/serial.log', '/logs/api.log']
    })
    resp = await cli.get('/health')
    text = await resp.text()
    assert resp.status == 200
    assert text == expected
Exemplo n.º 14
0
async def test_restart(virtual_smoothie_env, monkeypatch, loop, test_client):
    test_data = {"test": "pass"}

    async def mock_restart(request):
        return web.json_response(test_data)

    monkeypatch.setattr(ot2serverlib.endpoints, 'restart', mock_restart)

    app = init(loop)
    cli = await loop.create_task(test_client(app))

    expected = json.dumps(test_data)
    resp = await cli.post('/server/restart')
    text = await resp.text()
    assert resp.status == 200
    assert text == expected
Exemplo n.º 15
0
async def test_wifi_status(
        virtual_smoothie_env, loop, test_client, monkeypatch):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    def mock_subprocess(cmd):
        # Command: `nmcli networking connectivity`
        res = "full"
        return res, ''

    monkeypatch.setattr(wifi, '_subprocess', mock_subprocess)

    expected = json.dumps({'status': 'full'})
    resp = await cli.get('/wifi/status')
    text = await resp.text()
    assert resp.status == 200
    assert text == expected
Exemplo n.º 16
0
async def test_get_modules(virtual_smoothie_env, loop, test_client,
                           monkeypatch):
    test_module = modules.MagDeck(port="/dev/modules/tty1_magdeck")

    def stub_discover_modules():
        return [test_module]

    monkeypatch.setattr(modules, "discover_and_connect", stub_discover_modules)

    app = init(loop)
    cli = await loop.create_task(test_client(app))

    expected = {"modules": [test_module.to_dict()]}

    resp = await cli.get('/modules')
    body = await resp.json()
    assert resp.status == 200
    assert body == expected
Exemplo n.º 17
0
async def test_wifi_configure(
        virtual_smoothie_env, loop, test_client, monkeypatch):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    msg = "Device 'wlan0' successfully activated with '076aa998-0275-4aa0-bf85-e9629021e267'."  # noqa

    def mock_subprocess(cmd):
        # Command: nmcli device wifi connect "{ssid}" password "{psk}"
        return msg, ''

    monkeypatch.setattr(wifi, '_subprocess', mock_subprocess)

    expected = {'ssid': 'Opentrons', 'message': msg}

    resp = await cli.post(
        '/wifi/configure', json={'ssid': 'Opentrons', 'psk': 'scrt sqrl'})
    body = await resp.json()
    assert resp.status == 201
    assert body == expected
Exemplo n.º 18
0
async def test_move_and_home_existing_pipette(virtual_smoothie_env, loop,
                                              test_client):
    from opentrons import instruments
    app = init(loop)
    cli = await loop.create_task(test_client(app))
    robot.reset()
    robot.home()
    instruments.P300_Single(mount='right')
    move_data = {
        'target': 'pipette',
        'point': [100, 200, 50],
        'mount': 'right',
        'model': 'p300_single_v1'
    }
    res = await cli.post('/robot/move', json=move_data)
    assert res.status == 200

    move_data = {'target': 'pipette', 'mount': 'right'}
    res1 = await cli.post('/robot/home', json=move_data)
    assert res1.status == 200
Exemplo n.º 19
0
async def test_update(virtual_smoothie_env, monkeypatch, loop, test_client):
    msg = "success"
    whl_name = "testy.whl"
    serverlib_name = "testylib.whl"
    fw_name = "testy.fw"
    tmpdir = tempfile.mkdtemp("files")
    for filename in [whl_name, serverlib_name, fw_name]:
        with open(os.path.join(tmpdir, filename), 'w') as fd:
            fd.write("test")

    async def mock_install(filename, loop):
        return msg

    monkeypatch.setattr(ot2serverlib, '_install', mock_install)
    monkeypatch.setattr(update, '_update_firmware', mock_install)

    app = init(loop)
    cli = await loop.create_task(test_client(app))

    data = {
        'whl': open(os.path.join(tmpdir, whl_name)),
        'serverlib': open(os.path.join(tmpdir, serverlib_name)),
        'fw': open(os.path.join(tmpdir, fw_name))
    }

    # Note: hits API server update endpoint--this test covers backward
    # compatibility until the update server is universally available
    resp = await cli.post('/server/update', data=data)

    expected = json.dumps({
        'message': [msg, msg, msg],
        'filename': [whl_name, serverlib_name, fw_name]
    })
    text = await resp.text()
    assert resp.status == 200
    assert text == expected
Exemplo n.º 20
0
async def test_move_bad_request(virtual_smoothie_env, loop, test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    data0 = {'target': 'other'}
    res = await cli.post('/robot/move', json=data0)
    assert res.status == 400

    data1 = {'target': 'mount', 'point': (1, 2, 3, 4)}
    res = await cli.post('/robot/move', json=data1)
    assert res.status == 400

    data2 = {'target': 'mount', 'point': (1, 2, 3), 'mount': 'middle'}
    res = await cli.post('/robot/move', json=data2)
    assert res.status == 400

    data3 = {
        'target': 'pipette',
        'point': (1, 2, 3),
        'mount': 'left',
        'model': 'p9000+'
    }
    res = await cli.post('/robot/move', json=data3)
    assert res.status == 400
Exemplo n.º 21
0
async def test_log_endpoints(virtual_smoothie_env, loop, test_client):
    app = init(loop)
    cli = await loop.create_task(test_client(app))

    # # Test that values are set correctly
    serial_name = "serial.log"
    serial_file = os.path.join(main.log_file_path, serial_name)
    data1 = {'serial': 'No, CEREAL!'}
    with open(serial_file, 'w') as data_file:
        json.dump(data1, data_file)

    s1 = await cli.get('/logs/serial.log')
    s1body = await s1.text()
    assert json.loads(s1body) == data1

    api_name = "api.log"
    api_file = os.path.join(main.log_file_path, api_name)
    data2 = {'api': 'application program interface'}
    with open(api_file, 'w') as data_file:
        json.dump(data2, data_file)

    a1 = await cli.get('/logs/api.log')
    a1body = await a1.text()
    assert json.loads(a1body) == data2