File: test_generator.py

package info (click to toggle)
librouteros 3.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 376 kB
  • sloc: python: 1,579; makefile: 141; sh: 4
file content (40 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (3)
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
37
38
39
40
import pytest


def test_generator_ditch(routeros_api):
    """
    Assert that after ditching generator, new one will yield actual results.
    """
    routeros_api(
        "/ip/address/add",
        address="1.1.1.1/32",
        interface="ether1",
    )
    ips = routeros_api.path("ip", "address")
    for ip in ips:
        break

    interfaces = tuple(routeros_api.path("interface"))
    assert len(interfaces) == 1
    assert "mtu" in interfaces[0].keys()
    assert "mac-address" in interfaces[0].keys()


@pytest.mark.asyncio
async def test_generator_ditch_async(routeros_api_async):
    """
    Assert that after ditching generator, new one will yield actual results.
    """
    routeros_api_async(
        "/ip/address/add",
        address="1.1.1.1/32",
        interface="ether1",
    )
    ips = routeros_api_async.path("ip", "address")
    async for ip in ips:
        break

    interfaces = [r async for r in routeros_api_async.path("interface")]
    assert len(interfaces) == 1
    assert "mtu" in interfaces[0].keys()
    assert "mac-address" in interfaces[0].keys()