mirror of
https://github.com/b4tman/sync_ics2gcal
synced 2024-10-31 18:56:54 +00:00
parametrize test_filter_events_by_date
This commit is contained in:
parent
c38a3afe00
commit
94edbf1849
@ -18,6 +18,7 @@ def sha1(string):
|
|||||||
h.update(string)
|
h.update(string)
|
||||||
return h.hexdigest()
|
return h.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def gen_events(start, stop, start_time, no_time=False):
|
def gen_events(start, stop, start_time, no_time=False):
|
||||||
if no_time:
|
if no_time:
|
||||||
start_time = datetime.date(
|
start_time = datetime.date(
|
||||||
@ -56,12 +57,14 @@ def gen_events(start, stop, start_time, no_time=False):
|
|||||||
result.append(event)
|
result.append(event)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def gen_list_to_compare(start, stop):
|
def gen_list_to_compare(start, stop):
|
||||||
result = []
|
result = []
|
||||||
for i in range(start, stop):
|
for i in range(start, stop):
|
||||||
result.append({'iCalUID': 'test{:06d}'.format(i)})
|
result.append({'iCalUID': 'test{:06d}'.format(i)})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_start_date(event):
|
def get_start_date(event):
|
||||||
event_start = event['start']
|
event_start = event['start']
|
||||||
start_date = None
|
start_date = None
|
||||||
@ -78,6 +81,7 @@ def get_start_date(event):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def test_compare():
|
def test_compare():
|
||||||
part_len = 20
|
part_len = 20
|
||||||
# [1..2n]
|
# [1..2n]
|
||||||
@ -95,19 +99,21 @@ def test_compare():
|
|||||||
to_ins, to_upd, to_del = CalendarSync._events_list_compare(
|
to_ins, to_upd, to_del = CalendarSync._events_list_compare(
|
||||||
lst_src_rnd, lst_dst_rnd)
|
lst_src_rnd, lst_dst_rnd)
|
||||||
|
|
||||||
assert len(to_ins) == part_len
|
assert len(to_ins) == part_len
|
||||||
assert len(to_upd) == part_len
|
assert len(to_upd) == part_len
|
||||||
assert len(to_del) == part_len
|
assert len(to_del) == part_len
|
||||||
|
|
||||||
assert sorted(to_ins, key=lambda x: x['iCalUID']) == lst_src[:part_len]
|
assert sorted(to_ins, key=lambda x: x['iCalUID']) == lst_src[:part_len]
|
||||||
assert sorted(to_del, key=lambda x: x['iCalUID']) == lst_dst[part_len:]
|
assert sorted(to_del, key=lambda x: x['iCalUID']) == lst_dst[part_len:]
|
||||||
|
|
||||||
to_upd_ok = list(zip(lst_src[part_len:], lst_dst[:part_len]))
|
to_upd_ok = list(zip(lst_src[part_len:], lst_dst[:part_len]))
|
||||||
assert len(to_upd) == len(to_upd_ok)
|
assert len(to_upd) == len(to_upd_ok)
|
||||||
for item in to_upd_ok:
|
for item in to_upd_ok:
|
||||||
assert item in to_upd
|
assert item in to_upd
|
||||||
|
|
||||||
def test_filter_events_by_date(no_time=False):
|
|
||||||
|
@pytest.mark.parametrize("no_time", [True, False], ids=['date', 'dateTime'])
|
||||||
|
def test_filter_events_by_date(no_time):
|
||||||
msk = timezone('Europe/Moscow')
|
msk = timezone('Europe/Moscow')
|
||||||
now = utc.localize(datetime.datetime.utcnow())
|
now = utc.localize(datetime.datetime.utcnow())
|
||||||
msk_now = msk.normalize(now.astimezone(msk))
|
msk_now = msk.normalize(now.astimezone(msk))
|
||||||
@ -136,8 +142,8 @@ def test_filter_events_by_date(no_time=False):
|
|||||||
events_past = CalendarSync._filter_events_by_date(
|
events_past = CalendarSync._filter_events_by_date(
|
||||||
events, date_cmp, operator.lt)
|
events, date_cmp, operator.lt)
|
||||||
|
|
||||||
assert len(events_pending) == 1 + part_len
|
assert len(events_pending) == 1 + part_len
|
||||||
assert len(events_past) == part_len - 1
|
assert len(events_past) == part_len - 1
|
||||||
|
|
||||||
for event in events_pending:
|
for event in events_pending:
|
||||||
assert get_start_date(event) >= date_cmp
|
assert get_start_date(event) >= date_cmp
|
||||||
@ -145,8 +151,6 @@ def test_filter_events_by_date(no_time=False):
|
|||||||
for event in events_past:
|
for event in events_past:
|
||||||
assert get_start_date(event) < date_cmp
|
assert get_start_date(event) < date_cmp
|
||||||
|
|
||||||
def test_filter_events_by_date_no_time():
|
|
||||||
test_filter_events_by_date(no_time=True)
|
|
||||||
|
|
||||||
def test_filter_events_to_update():
|
def test_filter_events_to_update():
|
||||||
msk = timezone('Europe/Moscow')
|
msk = timezone('Europe/Moscow')
|
||||||
@ -169,5 +173,5 @@ def test_filter_events_to_update():
|
|||||||
sync2.to_update = list(zip(events_old, events_new))
|
sync2.to_update = list(zip(events_old, events_new))
|
||||||
sync2._filter_events_to_update()
|
sync2._filter_events_to_update()
|
||||||
|
|
||||||
assert len(sync1.to_update) == count
|
assert len(sync1.to_update) == count
|
||||||
assert sync2.to_update == []
|
assert sync2.to_update == []
|
||||||
|
Loading…
Reference in New Issue
Block a user