mirror of
https://github.com/b4tman/sync_ics2gcal
synced 2025-01-21 07:28:24 +00:00
Merge pull request #81 from b4tman/filter_no-updated
overwrite events without updated field (#80)
This commit is contained in:
commit
e6cc7ad336
@ -72,6 +72,8 @@ class CalendarSync:
|
||||
|
||||
def filter_updated(event_tuple: EventTuple) -> bool:
|
||||
new, old = event_tuple
|
||||
if 'updated' not in new or 'updated' not in old:
|
||||
return True
|
||||
new_date = dateutil.parser.parse(new['updated'])
|
||||
old_date = dateutil.parser.parse(old['updated'])
|
||||
return new_date > old_date
|
||||
|
@ -178,3 +178,30 @@ def test_filter_events_to_update():
|
||||
|
||||
assert len(sync1.to_update) == count
|
||||
assert sync2.to_update == []
|
||||
|
||||
|
||||
def test_filter_events_no_updated():
|
||||
"""
|
||||
test filtering events that not have 'updated' field
|
||||
such events should always pass the filter
|
||||
"""
|
||||
now = datetime.datetime.utcnow()
|
||||
yesterday = now - datetime.timedelta(days=-1)
|
||||
|
||||
count = 10
|
||||
events_old = gen_events(1, 1 + count, now)
|
||||
events_new = gen_events(1, 1 + count, now)
|
||||
|
||||
# 1/2 updated=yesterday, 1/2 no updated field
|
||||
i = 0
|
||||
for event in events_new:
|
||||
if 0 == i % 2:
|
||||
event['updated'] = yesterday.isoformat() + 'Z'
|
||||
else:
|
||||
del event['updated']
|
||||
i += 1
|
||||
|
||||
sync = CalendarSync(None, None)
|
||||
sync.to_update = list(zip(events_old, events_new))
|
||||
sync._filter_events_to_update()
|
||||
assert len(sync.to_update) == count // 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user