# Path: librouteros/query.py
# class Key:
# 
#     def __init__(self, name: str):
#         self.name = name
# 
#     def __eq__(self, other):
#         yield f'?={self}={cast_to_api(other)}'
# 
#     def __ne__(self, other):
#         yield from self == other
#         yield '?#!'
# 
#     def __lt__(self, other):
#         yield f'?<{self}={cast_to_api(other)}'
# 
#     def __gt__(self, other):
#         yield f'?>{self}={cast_to_api(other)}'
# 
#     def __str__(self) -> str:
#         return str(self.name)
# 
#     # pylint: disable=invalid-name
#     def In(self, one, *elems):
#         yield from self == one
#         yield from chain.from_iterable(self == str(elem) for elem in elems)
#         yield from ('?#|', ) * len(elems)


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))


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')

# Path: librouteros/query.py
# class Key:
# 
#     def __init__(self, name: str):
#         self.name = name
# 
#     def __eq__(self, other):
#         yield f'?={self}={cast_to_api(other)}'
# 
#     def __ne__(self, other):
#         yield from self == other
#         yield '?#!'
# 
#     def __lt__(self, other):
#         yield f'?<{self}={cast_to_api(other)}'
# 
#     def __gt__(self, other):
#         yield f'?>{self}={cast_to_api(other)}'
# 
#     def __str__(self) -> str:
#         return str(self.name)
# 
#     # pylint: disable=invalid-name
#     def In(self, one, *elems):
#         yield from self == one
#         yield from chain.from_iterable(self == str(elem) for elem in elems)
#         yield from ('?#|', ) * len(elems)


# Path: tests/integration/test_path.py
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))


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'