Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow string_content to be a str #162

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion icalevents/icaldownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def decode(content, encoding="utf-8", apple_fix=False):
:param apple_fix: fix Apple txdata bug
:return: decoded (and fixed) content
"""
content = content.decode(encoding)
if isinstance(content, bytes):
content = content.decode(encoding)
content = content.replace("\r", "")

if apple_fix:
Expand Down
44 changes: 25 additions & 19 deletions test/test_icalevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,26 +348,32 @@ def test_request_data(self):

def test_string_data(self):
ical = "test/test_data/basic.ics"

with open(ical, mode="rb") as f:
string_content = f.read()

start = date(2017, 5, 18)
end = date(2017, 5, 19)
key = "basic"

icalevents.request_data(
key,
url=None,
file=None,
string_content=string_content,
start=start,
end=end,
fix_apple=False,
)

self.assertTrue(icalevents.all_done(key), "request is finished")
self.assertEqual(len(icalevents.latest_events(key)), 2, "two events are found")
raw_data = f.read()

for stest, string_content in [
("as bytes", raw_data),
("as str", raw_data.decode()),
]:
with self.subTest(stest):
start = date(2017, 5, 18)
end = date(2017, 5, 19)
key = "basic"

icalevents.request_data(
key,
url=None,
file=None,
string_content=string_content,
start=start,
end=end,
fix_apple=False,
)

self.assertTrue(icalevents.all_done(key), "request is finished")
self.assertEqual(
len(icalevents.latest_events(key)), 2, "two events are found"
)

def test_events_no_description(self):
ical = "test/test_data/no_description.ics"
Expand Down