File: test_list.py

package info (click to toggle)
python-ical 12.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,776 kB
  • sloc: python: 15,157; sh: 9; makefile: 5
file content (107 lines) | stat: -rw-r--r-- 3,265 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""Tests for list view of todo items."""

import datetime

import freezegun
import pytest

from ical.list import todo_list_view
from ical.todo import Todo
from ical.types.recur import Recur


def test_empty_list() -> None:
    """Test an empty list."""
    view = todo_list_view([])
    assert list(view) == []


@pytest.mark.parametrize(
    ("status"),
    [
        ("NEEDS-ACTION"),
        ("IN-PROCESS"),
    ],
)
def test_daily_recurring_item_due_today_incomplete(status: str) -> None:
    """Test a daily recurring item that is due today ."""
    with freezegun.freeze_time("2024-01-10T10:05:00-05:00"):
        todo = Todo(
            dtstart=datetime.date.today() - datetime.timedelta(days=1),
            summary="Daily incomplete",
            due=datetime.date.today(),
            rrule=Recur.from_rrule("FREQ=DAILY"),
            status=status,
        )
        view = list(todo_list_view([todo]))

    assert len(view) == 1
    assert view[0].summary == todo.summary
    assert view[0].dtstart == datetime.date(2024, 1, 10)
    assert view[0].due == datetime.date(2024, 1, 11)
    assert view[0].recurrence_id == "20240110"


@pytest.mark.parametrize(
    ("status"),
    [
        ("NEEDS-ACTION"),
        ("IN-PROCESS"),
    ],
)
def test_daily_recurring_item_due_tomorrow(status: str) -> None:
    """Test a daily recurring item that is due tomorrow."""
    with freezegun.freeze_time("2024-01-10T10:05:00-05:00"):
        todo = Todo(
            dtstart=datetime.date.today(),
            summary="Daily incomplete",
            due=datetime.date.today() + datetime.timedelta(days=1),
            rrule=Recur.from_rrule("FREQ=DAILY"),
            status=status,
        )
        view = list(todo_list_view([todo]))

    assert len(view) == 1
    assert view[0].summary == todo.summary
    assert view[0].dtstart == datetime.date(2024, 1, 10)
    assert view[0].due == datetime.date(2024, 1, 11)
    assert view[0].recurrence_id == "20240110"


@pytest.mark.parametrize(
    ("status"),
    [
        ("NEEDS-ACTION"),
        ("IN-PROCESS"),
    ],
)
def test_daily_recurring_item_due_yesterday(status: str) -> None:
    """Test a daily recurring item that is due yesterday ."""

    with freezegun.freeze_time("2024-01-10T10:05:00-05:00"):
        todo = Todo(
            dtstart=datetime.date.today() - datetime.timedelta(days=1),
            summary="Daily incomplete",
            due=datetime.date.today(),
            rrule=Recur.from_rrule("FREQ=DAILY"),
            status=status,
        )
        view = list(todo_list_view([todo]))

    # The item should be returned with a recurrence_id of today
    assert len(view) == 1
    assert view[0].summary == todo.summary
    assert view[0].dtstart == datetime.date(2024, 1, 10)
    assert view[0].due == datetime.date(2024, 1, 11)
    assert view[0].recurrence_id == "20240110"
    assert view[0].status == status

    with freezegun.freeze_time("2024-01-11T08:05:00-05:00"):
        view = list(todo_list_view([todo]))

    assert len(view) == 1
    assert view[0].summary == todo.summary
    assert view[0].dtstart == datetime.date(2024, 1, 11)
    assert view[0].due == datetime.date(2024, 1, 12)
    assert view[0].recurrence_id == "20240111"
    assert view[0].status == status