Decode stored calendar documents under Python 3
Debian Trixie package bundle / packages (push) Failing after 10m20s
Debian Trixie package bundle / packages (push) Failing after 10m20s
This commit is contained in:
@@ -77,6 +77,8 @@ def open_store(user, store_cookie):
|
||||
|
||||
def json_to_ical(document):
|
||||
from libbongo._calendar import bongojson, cal
|
||||
if isinstance(document, bytes):
|
||||
document = document.decode("utf-8", "strict")
|
||||
value = bongojson.ParseString(document.strip())
|
||||
if not value:
|
||||
raise CalendarNotFound("invalid stored calendar object")
|
||||
|
||||
@@ -20,11 +20,13 @@
|
||||
# ****************************************************************************/
|
||||
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest import mock
|
||||
|
||||
from bongo_web.calendar_store import (CalendarNotFound, CalendarPathError,
|
||||
PreconditionFailed, delete_event,
|
||||
etag_matches, event_href, event_to_dict,
|
||||
ical_to_json, make_event,
|
||||
ical_to_json, json_to_ical, make_event,
|
||||
list_calendar_events, list_calendars,
|
||||
list_events, make_etag,
|
||||
parse_calendar_path, write_event)
|
||||
@@ -117,6 +119,17 @@ class CalendarPathTests(unittest.TestCase):
|
||||
with self.subTest(data=data), self.assertRaises(ValueError):
|
||||
ical_to_json(data)
|
||||
|
||||
def test_stored_json_bytes_are_accepted(self):
|
||||
parsed = []
|
||||
calendar_module = SimpleNamespace(
|
||||
bongojson=SimpleNamespace(
|
||||
ParseString=lambda value: parsed.append(value) or object()),
|
||||
cal=SimpleNamespace(JsonToIcal=lambda value: "ICAL"))
|
||||
with mock.patch.dict(
|
||||
"sys.modules", {"libbongo._calendar": calendar_module}):
|
||||
self.assertEqual(json_to_ical(b' {"event": "bytes"} '), b"ICAL")
|
||||
self.assertEqual(parsed, ['{"event": "bytes"}'])
|
||||
|
||||
|
||||
class CalendarMutationTests(unittest.TestCase):
|
||||
def factory(self, store):
|
||||
|
||||
Reference in New Issue
Block a user