File: test_path.py

package info (click to toggle)
librouteros 3.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 376 kB
  • sloc: python: 1,579; makefile: 141; sh: 4
file content (36 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pytest
from librouteros.query import Key


def test_add_then_remove(routeros_api):
    ips = routeros_api.path("ip", "address")
    new_id = ips.add(interface="ether1", address="192.168.1.1/24")
    ips.remove(new_id)
    _id = Key(".id")
    assert tuple() == tuple(ips.select(_id).where(_id == new_id))


@pytest.mark.asyncio
async def test_add_then_remove_async(routeros_api_async):
    ips = routeros_api_async.path("ip", "address")
    new_id = await ips.add(interface="ether1", address="192.168.1.1/24")
    await ips.remove(new_id)
    _id = Key(".id")
    assert tuple() == tuple([r async for r in ips.select(_id).where(_id == new_id)])


def test_add_then_update(routeros_api):
    ips = routeros_api.path("ip", "address")
    new_id = ips.add(interface="ether1", address="192.168.1.1/24")
    ips.update(**{".id": new_id, "address": "172.16.1.1/24"})
    address = Key("address")
    assert tuple(ips.select(address).where(Key(".id") == new_id))[0]["address"] == "172.16.1.1/24"


@pytest.mark.asyncio
async def test_add_then_update_async(routeros_api_async):
    ips = routeros_api_async.path("ip", "address")
    new_id = await ips.add(interface="ether1", address="192.168.1.1/24")
    await ips.update(**{".id": new_id, "address": "172.16.1.1/24"})
    address = Key("address")
    assert [r async for r in ips.select(address).where(Key(".id") == new_id)][0]["address"] == "172.16.1.1/24"