Skip to content

Commit

Permalink
fix: allow string_content to be a str
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Feb 4, 2025
1 parent 301bde0 commit 0659836
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
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

0 comments on commit 0659836

Please sign in to comment.