|
16 | 16 | from zino.state import ZinoState |
17 | 17 | from zino.statemodels import Event, EventState, ReachabilityEvent |
18 | 18 |
|
| 19 | +DEVICE_NAME = "example-gw.example.org" |
| 20 | + |
19 | 21 |
|
20 | 22 | class TestZino1BaseServerProtocol: |
21 | 23 | def test_should_init_without_error(self): |
@@ -696,6 +698,55 @@ def _read_multiline(self): |
696 | 698 | assert b"200 ok" in buffered_fake_transport.data_buffer.getvalue() |
697 | 699 |
|
698 | 700 |
|
| 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 | + |
699 | 750 | def test_requires_authentication_should_set_function_attribute(): |
700 | 751 | @requires_authentication |
701 | 752 | def throwaway(): |
|
0 commit comments