| 1 | """This tests generating the right sequence number for event editing. |
| 2 | |
| 3 | A computed, recurring event of a UID taking an event with a higher sequence in account, |
| 4 | will be of that sequence. |
| 5 | |
| 6 | See https://github.com/niccokunzmann/python-recurring-ical-events/issues/223 |
| 7 | """ |
| 8 | |
| 9 | from typing import TYPE_CHECKING |
| 10 | |
| 11 | import pytest |
| 12 | |
| 13 | if TYPE_CHECKING: |
| 14 | from icalendar import Event |
| 15 | |
| 16 | |
| 17 | def test_sequence_number_is_not_set_for_single_events(calendars): |
| 18 | """If we have singe events, they should not need a sequence number.""" |
| 19 | assert "SEQUENCE" not in calendars.one_event.first |
| 20 | |
| 21 | |
| 22 | @pytest.mark.parametrize(("date", "sequence"), [("20190305", 1), ("20190304", 0)]) |
| 23 | def test_sequence_is_not_deleted(calendars, date, sequence): |
| 24 | """We do not delete the sequence if it is 0.""" |
| 25 | events: list[Event] = calendars.issue_223_one_event_with_sequence.at(date) |
| 26 | assert len(events) == 1 |
| 27 | event = events[0] |
| 28 | assert event["SEQUENCE"] == sequence, "sequence remains in here" |
| 29 | |
| 30 | |
| 31 | def test_sequence_number_is_not_set_for_recurrence(calendars): |
| 32 | """If we do not use sequences at all, we should not set them.""" |
| 33 | events = calendars.one_day_event_repeat_every_day.at("20190308") |
| 34 | assert len(events) == 1 |
| 35 | event = events[0] |
| 36 | assert "SEQUENCE" not in event, "is not set if not needed" |
| 37 | |
| 38 | |
| 39 | def test_sequence_number_is_highest_for_edited_event(calendars): |
| 40 | """If an event was edited, it uses this sequence number.""" |
| 41 | events: list[Event] = calendars.issue_223_thunderbird.at("20250424") |
| 42 | assert len(events) == 1 |
| 43 | event = events[0] |
| 44 | assert event["SEQUENCE"] == 3, "2 -> 3" |
| 45 | |
| 46 | |
| 47 | def test_sequence_number_is_highest_for_base_event(calendars): |
| 48 | """The base event with no modification has the highest sequence number.""" |
| 49 | events: list[Event] = calendars.issue_223_thunderbird.at("20250423") |
| 50 | assert len(events) == 1 |
| 51 | event = events[0] |
| 52 | assert event["SEQUENCE"] == 3, "1 -> 3" |
| 53 | |
| 54 | |
| 55 | def test_sequence_number_is_highest_for_last_event(calendars): |
| 56 | """The last edited event keeps its sequence number.""" |
| 57 | events: list[Event] = calendars.issue_223_thunderbird.at("20250425") |
| 58 | assert len(events) == 1 |
| 59 | event = events[0] |
| 60 | assert event["SEQUENCE"] == 3, "3 -> 3" |