-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from Plonq/keep-recurrence-attributes-option
Add ability to keep recurrence attributes on event copies
- Loading branch information
Showing
3 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""This file tests the `keep_recurrence_attributes` argument of `of` works as expected.""" | ||
import os | ||
|
||
from datetime import datetime | ||
from recurring_ical_events import of | ||
from icalendar import Calendar | ||
|
||
HERE = os.path.dirname(__name__) or "test" | ||
CALENDARS_FOLDER = os.path.join(HERE, "calendars") | ||
calendar_path = os.path.join(CALENDARS_FOLDER, "rdate.ics") | ||
|
||
|
||
def test_keep_recurrence_attributes_default(calendars): | ||
with open(calendar_path, "rb") as file: | ||
content = file.read() | ||
|
||
calendar = Calendar.from_ical(content) | ||
today = datetime.today() | ||
one_year_ahead = today.replace(year=today.year + 1) | ||
|
||
events = of(calendar).between(today, one_year_ahead) | ||
for event in events: | ||
assert event.get("RRULE", False) is False | ||
assert event.get("RDATE", False) is False | ||
assert event.get("EXDATE", False) is False | ||
|
||
|
||
def test_keep_recurrence_attributes_false(calendars): | ||
with open(calendar_path, "rb") as file: | ||
content = file.read() | ||
|
||
calendar = Calendar.from_ical(content) | ||
today = datetime.today() | ||
one_year_ahead = today.replace(year=today.year + 1) | ||
|
||
events = of(calendar, keep_recurrence_attributes=False).between(today, one_year_ahead) | ||
for event in events: | ||
assert event.get("RRULE", False) is False | ||
assert event.get("RDATE", False) is False | ||
assert event.get("EXDATE", False) is False | ||
|
||
|
||
def test_keep_recurrence_attributes_true(calendars): | ||
with open(calendar_path, "rb") as file: | ||
content = file.read() | ||
|
||
calendar = Calendar.from_ical(content) | ||
today = datetime.today() | ||
one_year_ahead = today.replace(year=today.year + 1) | ||
|
||
events = of(calendar, keep_recurrence_attributes=True).between(today, one_year_ahead) | ||
for event in events: | ||
assert event.get("RRULE", False) is not False | ||
assert event.get("RDATE", False) is not False | ||
assert event.get("EXDATE", False) is not False |