1
0
mirror of https://github.com/b4tman/sync_ics2gcal synced 2025-01-21 23:38:58 +00:00

test_converter rewrite using pytest

event start/end tests united, using pytest.fixture
This commit is contained in:
Dmitry Belyaev 2018-04-17 16:01:21 +03:00
parent ec45665a4c
commit 7aa3e754ea
Signed by: b4tman
GPG Key ID: 014E87EC54B77673

View File

@ -1,4 +1,5 @@
import unittest import pytest
from gcal_sync import CalendarConverter from gcal_sync import CalendarConverter
ics_empty = """BEGIN:VCALENDAR ics_empty = """BEGIN:VCALENDAR
@ -32,20 +33,20 @@ END:VEVENT
END:VCALENDAR END:VCALENDAR
""" """
ics_event_datetime_utc_val = """BEGIN:VCALENDAR
BEGIN:VEVENT
UID:uisgtr8tre93wewe0yr8wqy@test.com
DTSTART;VALUE=DATE-TIME:20180319T092001Z
DTEND:20180319T102001Z
END:VEVENT
END:VCALENDAR
"""
ics_event_date_duration = """BEGIN:VCALENDAR ics_event_date_duration = """BEGIN:VCALENDAR
BEGIN:VEVENT BEGIN:VEVENT
UID:uisgtr8tre93wewe0yr8wqy@test.com UID:uisgtr8tre93wewe0yr8wqy@test.com
DTSTART;VALUE=DATE:20180215 DTSTART;VALUE=DATE:20180215
DURATION:P3D DURATION:P2D
END:VEVENT
END:VCALENDAR
"""
ics_event_datetime_utc_val = """BEGIN:VCALENDAR
BEGIN:VEVENT
UID:uisgtr8tre93wewe0yr8wqy@test.com
DTSTART;VALUE=DATE-TIME:20180319T092001Z
DTEND:20180321T102501Z
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR
""" """
@ -71,86 +72,55 @@ END:VCALENDAR
""" """
class TestCalendarConverter(unittest.TestCase): def test_empty_calendar():
def test_empty_calendar(self):
converter = CalendarConverter() converter = CalendarConverter()
converter.loads(ics_empty) converter.loads(ics_empty)
evnts = converter.events_to_gcal() evnts = converter.events_to_gcal()
self.assertEqual(len(evnts), 0) assert evnts == []
def test_empty_event(self):
def test_empty_event():
converter = CalendarConverter() converter = CalendarConverter()
converter.loads(ics_empty_event) converter.loads(ics_empty_event)
with self.assertRaises(KeyError): with pytest.raises(KeyError):
converter.events_to_gcal() converter.events_to_gcal()
def test_event_no_end(self):
def test_event_no_end():
converter = CalendarConverter() converter = CalendarConverter()
converter.loads(ics_event_no_end) converter.loads(ics_event_no_end)
with self.assertRaises(ValueError): with pytest.raises(ValueError):
converter.events_to_gcal() converter.events_to_gcal()
def test_event_date_values(self): @pytest.fixture(params=[
converter = CalendarConverter() ("date", ics_event_date_val, '2018-02-15', '2018-02-17'),
converter.loads(ics_event_date_val) ("date", ics_event_date_duration, '2018-02-15', '2018-02-17'),
events = converter.events_to_gcal() ("dateTime", ics_event_datetime_utc_val, '2018-03-19T09:20:01.000001Z', '2018-03-21T10:25:01.000001Z'),
self.assertEqual(len(events), 1) ("dateTime", ics_event_datetime_utc_duration, '2018-03-19T09:20:01.000001Z', '2018-03-21T10:25:01.000001Z')],
event = events[0] ids=['date values', 'date duration', 'datetime utc values', 'datetime utc duration']
self.assertEqual(event['start'], { )
'date': '2018-02-15' def param_events_start_end(request):
}) return request.param
self.assertEqual(event['end'], {
'date': '2018-02-17'
})
def test_event_datetime_utc_values(self): def test_event_start_end(param_events_start_end):
(date_type, ics_str, start, end) = param_events_start_end
converter = CalendarConverter() converter = CalendarConverter()
converter.loads(ics_event_datetime_utc_val) converter.loads(ics_str)
events = converter.events_to_gcal() events = converter.events_to_gcal()
self.assertEqual(len(events), 1) assert len(events) == 1
event = events[0] event = events[0]
self.assertEqual(event['start'], { assert event['start'] == {
'dateTime': '2018-03-19T09:20:01.000001Z' date_type: start
}) }
self.assertEqual(event['end'], { assert event['end'] == {
'dateTime': '2018-03-19T10:20:01.000001Z' date_type: end
}) }
def test_event_date_duration(self): def test_event_created_updated():
converter = CalendarConverter()
converter.loads(ics_event_date_duration)
events = converter.events_to_gcal()
self.assertEqual(len(events), 1)
event = events[0]
self.assertEqual(event['start'], {
'date': '2018-02-15'
})
self.assertEqual(event['end'], {
'date': '2018-02-18'
})
def test_event_datetime_utc_duration(self):
converter = CalendarConverter()
converter.loads(ics_event_datetime_utc_duration)
events = converter.events_to_gcal()
self.assertEqual(len(events), 1)
event = events[0]
self.assertEqual(event['start'], {
'dateTime': '2018-03-19T09:20:01.000001Z'
})
self.assertEqual(event['end'], {
'dateTime': '2018-03-21T10:25:01.000001Z'
})
def test_event_created_updated(self):
converter = CalendarConverter() converter = CalendarConverter()
converter.loads(ics_event_created_updated) converter.loads(ics_event_created_updated)
events = converter.events_to_gcal() events = converter.events_to_gcal()
self.assertEqual(len(events), 1) assert len(events) == 1
event = events[0] event = events[0]
self.assertEqual(event['created'], '2018-03-20T07:11:55.000001Z') assert event['created'] == '2018-03-20T07:11:55.000001Z'
self.assertEqual(event['updated'], '2018-03-26T12:02:35.000001Z') assert event['updated'] == '2018-03-26T12:02:35.000001Z'
if __name__ == '__main__':
unittest.main()