Пример #1
0
def test_to_json():
    name = 'con'
    uuid = 'abcdef'
    conn_type = 'ethernet'
    device = 'eth0'
    c = Connection(name, uuid, conn_type, device)
    assert c.to_json() == {
        'name': name,
        'uuid': uuid,
        'conn_type': conn_type,
        'device': device
    }
Пример #2
0
def test_connection():
    s = DummySystemCommand('''NAME            UUID                                  TYPE      DEVICE
AP1  3eac760c-de77-4823-9ab8-773c276daca3  wifi      wlan0
Home            700f5b18-cbb3-4d38-9c61-e3bc3a3852b9  ethernet  eth0
Wired connection 1  700f5b18-cbb3-4d38-9c61-999999999999  ethernet  eth1
''')
    connection = ConnectionControl(s)
    r = connection()

    assert r == [
        Connection('AP1', '3eac760c-de77-4823-9ab8-773c276daca3', 'wifi', 'wlan0'),
        Connection('Home', '700f5b18-cbb3-4d38-9c61-e3bc3a3852b9', 'ethernet', 'eth0'),
        Connection('Wired connection 1', '700f5b18-cbb3-4d38-9c61-999999999999', 'ethernet', 'eth1')
    ]
    assert s.passed_parameters == 'connection'
Пример #3
0
def test_parse():
    d1 = 'AP1  3eac760c-de77-4823-9ab8-773c276daca3  wifi      wlan0'
    assert Connection.parse(d1) == \
        Connection('AP1', '3eac760c-de77-4823-9ab8-773c276daca3', 'wifi', 'wlan0')
    d2 = 'Home            700f5b18-cbb3-4d38-9c61-e3bc3a3852b9  ethernet  eth0'
    assert Connection.parse(d2) == \
        Connection('Home', '700f5b18-cbb3-4d38-9c61-e3bc3a3852b9', 'ethernet', 'eth0')
    d3 = 'Wired connection 1  700f5b18-cbb3-4d38-9c61-999999999999  ethernet  eth1'
    assert Connection.parse(d3) == \
        Connection('Wired connection 1', '700f5b18-cbb3-4d38-9c61-999999999999', 'ethernet', 'eth1')
Пример #4
0
def test_parse_when_failed():
    with pytest.raises(ValueError) as e:
        Connection.parse('invalid')
    assert str(e.value) == 'Parse failed [invalid]'
Пример #5
0
def test_call():
    result_call = [Connection('a', 'b', 'ethernet', 'eth0')]
    c = DummyConnectionControl(result_call)
    assert c() == result_call