caldav: change CATEGORIES parameter handling (#88089)
Allowing only a single category
This commit is contained in:
parent
5d26332646
commit
8986d35915
|
@ -53,6 +53,7 @@ EVENT_SCHEMA_PART = {
|
|||
'type': 'string',
|
||||
'description': 'RFC 5545 3.8.1.7',
|
||||
},
|
||||
'CATEGORY': {'type': 'string'},
|
||||
'TRANSP': {
|
||||
'type': 'boolean',
|
||||
'description': 'Transparent if true else opaque (RFC 5545 3.8.2.7)',
|
||||
|
@ -291,6 +292,9 @@ class CalDAV(BaseResource):
|
|||
if 'TRANSP' in data:
|
||||
data['TRANSP'] = 'TRANSPARENT' if data['TRANSP'] else 'OPAQUE'
|
||||
|
||||
if 'CATEGORY' in data:
|
||||
data['CATEGORIES'] = [data.pop('CATEGORY')]
|
||||
|
||||
for dt_field in ('DTSTART', 'DTEND'):
|
||||
value = data[dt_field]
|
||||
try:
|
||||
|
|
|
@ -227,6 +227,30 @@ def test_caldav_event_create_allday_ok(app, caldav_conn):
|
|||
cal_mock.save_event.assert_called_once_with(**event_conv)
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_caldav_event_categories(app, caldav_conn):
|
||||
url = tests.utils.generic_endpoint_url('caldav', 'event/create')
|
||||
username = 'foo'
|
||||
evt_id = 42
|
||||
evt_path = get_event_path(caldav_conn, username, evt_id)
|
||||
cal_mock = get_calendar_mock(evt_path, evt_id)
|
||||
|
||||
event = {'DTSTART': '2020-02-20', 'DTEND': '2020-03-30', 'SUMMARY': 'foobar', 'CATEGORY': 'foobar'}
|
||||
qs_params = {'username': username}
|
||||
|
||||
with patch('caldav.Calendar', return_value=cal_mock):
|
||||
resp = app_post(app, url, qs_params, event)
|
||||
assert resp.json['err'] == 0
|
||||
assert resp.json['data']['event_id'] == evt_id
|
||||
|
||||
event_conv = {
|
||||
k: v if k not in ('DTSTART', 'DTEND') else datetime.date.fromisoformat(v)
|
||||
for k, v in event.items()
|
||||
}
|
||||
event_conv['CATEGORIES'] = [event_conv.pop('CATEGORY')]
|
||||
cal_mock.save_event.assert_called_once_with(**event_conv)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'event',
|
||||
SOME_EVENTS,
|
||||
|
|
Loading…
Reference in New Issue