Esempio n. 1
0
def test_device_parse():
    d1 = 'eth0    ethernet  connected  Default'
    assert Device.parse(d1) == \
        Device('eth0', 'ethernet', 'connected', 'Default')
    d2 = 'lo      loopback  unmanaged  --'
    assert Device.parse(d2) == \
        Device('lo', 'loopback', 'unmanaged', None)
Esempio n. 2
0
def test_device_to_json():
    device = 'eth0'
    device_type = 'ethernet'
    state = 'connected'
    connection = 'Home'
    d = Device(device, device_type, state, connection)
    assert d.to_json() == {
        'device': device,
        'device_type': device_type,
        'state': state,
        'connection': connection
    }
Esempio n. 3
0
def test_status():
    with open(device_data_file, encoding='utf-8') as f:
        buf = f.read()
    s = DummySystemCommand(buf)
    device = DeviceControl(s)
    r = device.status()
    assert len(r) == 4
    assert r == [
        Device('eth0', 'ethernet', 'connected', 'Wired connection 1'),
        Device('wlan0', 'wifi', 'disconnected', None),
        Device('p2p-dev-wlan0', 'wifi-p2p', 'disconnected', None),
        Device('lo', 'loopback', 'unmanaged', None)
    ]
    assert s.passed_parameters == ['device', 'status']
Esempio n. 4
0
def test_device():
    s = DummySystemCommand('''DEVICE  TYPE      STATE      CONNECTION
eth0    ethernet  connected  Default
wlan0   wifi      connected  MyWifi
lo      loopback  unmanaged  --''')
    device = DeviceControl(s)
    r = device()
    assert len(r) == 3
    assert r == [
        Device('eth0', 'ethernet', 'connected', 'Default'),
        Device('wlan0', 'wifi', 'connected', 'MyWifi'),
        Device('lo', 'loopback', 'unmanaged', None)
    ]
    assert s.passed_parameters == ['device', 'status']
Esempio n. 5
0
def test_call():
    result_call = [Device('eth0', 'ethernet', 'connected,', 'MyNet')]
    c = DummyDeviceControl(result_call)
    assert c() == result_call
Esempio n. 6
0
def test_device_parse_when_failed():
    with pytest.raises(ValueError) as e:
        Device.parse('invalid')
    assert str(e.value) == 'Parse failed [invalid]'