def test_59_event_cancellation(tmpdir):
    """
    VEN, EiEvent Service, oadrDistributeEvent Payload
    If the VTN sends an oadrEvent with the eventStatus set to cancelled and
    has an eventID that the VEN is aware of then the VEN should cancel the
    existing event and delete it from its list of known events.
    """
    test_event = AdrEvent(
        id="FooEvent",
        start=datetime.utcnow() + timedelta(seconds=60),
        signals=[dict(index=0, duration=timedelta(minutes=10), level=1.0)],
        status=AdrEventStatus.PENDING, mod_number=1
    )

    event_handler = event.EventHandler("VEN_ID", db_path=TEST_DB_ADDR % tmpdir)
    event_controller = controller.EventController(event_handler)

    event_handler.handle_payload(generate_payload([test_event]))

    active_event = event_handler.get_active_events()[0]
    assert active_event == test_event.to_obj()

    with freeze_time():
        test_event.status = AdrEventStatus.CANCELLED
        test_event.mod_number += 1
        test_event.end = datetime.utcnow()

        event_handler.handle_payload(generate_payload([test_event]))

        active_event = event_handler.get_active_events()[0]
        assert active_event == test_event.to_obj()

    signal_level, evt_id, remove_events = event_controller._calculate_current_event_status([test_event.to_obj()])
    assert (signal_level, evt_id, remove_events) == (0, None, ["FooEvent"])
示例#2
0
def test_explicite_cancellation(tmpdir):
    test_event = AdrEvent(
        id="FooEvent",
        start=datetime.utcnow()-timedelta(seconds=60),
        signals=[dict(index=0, duration=timedelta(minutes=10), level=2.0)],
        status=AdrEventStatus.ACTIVE,
    )

    event_handler = event.EventHandler("VEN_ID", db_path=TEST_DB_ADDR % tmpdir)

    event_handler.handle_payload(generate_payload([test_event]))

    active_events = event_handler.get_active_events()

    assert [test_event.to_obj()] == active_events

    with freeze_time():
        test_event.mod_number += 1
        test_event.status = AdrEventStatus.CANCELLED
        test_event.end = datetime.utcnow()

        event_handler.handle_payload(generate_payload([test_event]))
        active_events = event_handler.get_active_events()

        assert [test_event.to_obj()] == active_events

        # test second cancellation
        event_handler.handle_payload(generate_payload([test_event]))
        active_events = event_handler.get_active_events()

        assert [test_event.to_obj()] == active_events

    # test subsequent cancellation
    event_handler.handle_payload(generate_payload([test_event]))
    active_events = event_handler.get_active_events()

    assert [test_event.to_obj()] == active_events