mirror of
https://github.com/b4tman/sync_ics2gcal
synced 2025-01-21 07:28:24 +00:00
test_converter rewrite using pytest
event start/end tests united, using pytest.fixture
This commit is contained in:
parent
ec45665a4c
commit
7aa3e754ea
@ -1,4 +1,5 @@
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
from gcal_sync import CalendarConverter
|
||||
|
||||
ics_empty = """BEGIN:VCALENDAR
|
||||
@ -32,20 +33,20 @@ END:VEVENT
|
||||
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
|
||||
BEGIN:VEVENT
|
||||
UID:uisgtr8tre93wewe0yr8wqy@test.com
|
||||
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:VCALENDAR
|
||||
"""
|
||||
@ -71,86 +72,55 @@ END:VCALENDAR
|
||||
"""
|
||||
|
||||
|
||||
class TestCalendarConverter(unittest.TestCase):
|
||||
def test_empty_calendar(self):
|
||||
def test_empty_calendar():
|
||||
converter = CalendarConverter()
|
||||
converter.loads(ics_empty)
|
||||
evnts = converter.events_to_gcal()
|
||||
self.assertEqual(len(evnts), 0)
|
||||
assert evnts == []
|
||||
|
||||
def test_empty_event(self):
|
||||
|
||||
def test_empty_event():
|
||||
converter = CalendarConverter()
|
||||
converter.loads(ics_empty_event)
|
||||
with self.assertRaises(KeyError):
|
||||
with pytest.raises(KeyError):
|
||||
converter.events_to_gcal()
|
||||
|
||||
def test_event_no_end(self):
|
||||
|
||||
def test_event_no_end():
|
||||
converter = CalendarConverter()
|
||||
converter.loads(ics_event_no_end)
|
||||
with self.assertRaises(ValueError):
|
||||
with pytest.raises(ValueError):
|
||||
converter.events_to_gcal()
|
||||
|
||||
def test_event_date_values(self):
|
||||
converter = CalendarConverter()
|
||||
converter.loads(ics_event_date_val)
|
||||
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-17'
|
||||
})
|
||||
@pytest.fixture(params=[
|
||||
("date", ics_event_date_val, '2018-02-15', '2018-02-17'),
|
||||
("date", ics_event_date_duration, '2018-02-15', '2018-02-17'),
|
||||
("dateTime", ics_event_datetime_utc_val, '2018-03-19T09:20:01.000001Z', '2018-03-21T10:25:01.000001Z'),
|
||||
("dateTime", ics_event_datetime_utc_duration, '2018-03-19T09:20:01.000001Z', '2018-03-21T10:25:01.000001Z')],
|
||||
ids=['date values', 'date duration', 'datetime utc values', 'datetime utc duration']
|
||||
)
|
||||
def param_events_start_end(request):
|
||||
return request.param
|
||||
|
||||
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.loads(ics_event_datetime_utc_val)
|
||||
converter.loads(ics_str)
|
||||
events = converter.events_to_gcal()
|
||||
self.assertEqual(len(events), 1)
|
||||
assert len(events) == 1
|
||||
event = events[0]
|
||||
self.assertEqual(event['start'], {
|
||||
'dateTime': '2018-03-19T09:20:01.000001Z'
|
||||
})
|
||||
self.assertEqual(event['end'], {
|
||||
'dateTime': '2018-03-19T10:20:01.000001Z'
|
||||
})
|
||||
assert event['start'] == {
|
||||
date_type: start
|
||||
}
|
||||
assert event['end'] == {
|
||||
date_type: end
|
||||
}
|
||||
|
||||
def test_event_date_duration(self):
|
||||
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):
|
||||
def test_event_created_updated():
|
||||
converter = CalendarConverter()
|
||||
converter.loads(ics_event_created_updated)
|
||||
events = converter.events_to_gcal()
|
||||
self.assertEqual(len(events), 1)
|
||||
assert len(events) == 1
|
||||
event = events[0]
|
||||
self.assertEqual(event['created'], '2018-03-20T07:11:55.000001Z')
|
||||
self.assertEqual(event['updated'], '2018-03-26T12:02:35.000001Z')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
assert event['created'] == '2018-03-20T07:11:55.000001Z'
|
||||
assert event['updated'] == '2018-03-26T12:02:35.000001Z'
|
||||
|
Loading…
x
Reference in New Issue
Block a user