Skip to content

Commit 0e81afa

Browse files
Add tests for delete event API command
1 parent d9adbfb commit 0e81afa

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/api/legacy_test.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from zino.state import ZinoState
1717
from zino.statemodels import Event, EventState, ReachabilityEvent
1818

19+
DEVICE_NAME = "example-gw.example.org"
20+
1921

2022
class TestZino1BaseServerProtocol:
2123
def test_should_init_without_error(self):
@@ -696,6 +698,55 @@ def _read_multiline(self):
696698
assert b"200 ok" in buffered_fake_transport.data_buffer.getvalue()
697699

698700

701+
class TestZino1TestProtocolDeleteEventCommand:
702+
@pytest.mark.asyncio
703+
async def test_should_delete_open_event(self):
704+
protocol = ZinoTestProtocol()
705+
fake_transport = Mock()
706+
protocol.connection_made(fake_transport)
707+
protocol.user = "foo"
708+
fake_transport.write = Mock()
709+
710+
event = ReachabilityEvent(router=DEVICE_NAME, state=EventState.OPEN)
711+
protocol._state.events.commit(event=event)
712+
713+
command = f"DELETEEVENT {event.id}"
714+
await protocol.message_received(command)
715+
716+
assert fake_transport.write.called
717+
response = fake_transport.write.call_args[0][0].decode("utf-8")
718+
assert response.startswith("200 ")
719+
assert event.id not in protocol._state.events.events.keys()
720+
assert not protocol._state.events.get(device_name=DEVICE_NAME, subindex=None, event_class=ReachabilityEvent)
721+
assert not protocol._state.events.get_closed_event(
722+
device_name=DEVICE_NAME, subindex=None, event_class=ReachabilityEvent
723+
)
724+
725+
@pytest.mark.asyncio
726+
async def test_should_delete_closed_event(self):
727+
protocol = ZinoTestProtocol()
728+
fake_transport = Mock()
729+
protocol.connection_made(fake_transport)
730+
protocol.user = "foo"
731+
fake_transport.write = Mock()
732+
733+
event = ReachabilityEvent(router=DEVICE_NAME, state=EventState.CLOSED)
734+
protocol._state.events.commit(event=event)
735+
736+
command = f"DELETEEVENT {event.id}"
737+
await protocol.message_received(command)
738+
739+
assert fake_transport.write.called
740+
response = fake_transport.write.call_args[0][0].decode("utf-8")
741+
assert response.startswith("200 ")
742+
assert response.startswith("200 ")
743+
assert event.id not in protocol._state.events.events.keys()
744+
assert not protocol._state.events.get(device_name=DEVICE_NAME, subindex=None, event_class=ReachabilityEvent)
745+
assert not protocol._state.events.get_closed_event(
746+
device_name=DEVICE_NAME, subindex=None, event_class=ReachabilityEvent
747+
)
748+
749+
699750
def test_requires_authentication_should_set_function_attribute():
700751
@requires_authentication
701752
def throwaway():

0 commit comments

Comments
 (0)