mirror of
				https://github.com/b4tman/sync_ics2gcal
				synced 2025-11-03 20:28:29 +00:00 
			
		
		
		
	min data in test_converter
This commit is contained in:
		@@ -2,106 +2,72 @@ import pytest
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from gcal_sync import CalendarConverter
 | 
					from gcal_sync import CalendarConverter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ics_empty = """BEGIN:VCALENDAR
 | 
					uid = "UID:uisgtr8tre93wewe0yr8wqy@test.com"
 | 
				
			||||||
VERSION:2.0
 | 
					only_start_date = uid + """
 | 
				
			||||||
PRODID:-//test//test//ES
 | 
					 | 
				
			||||||
CALSCALE:GREGORIAN
 | 
					 | 
				
			||||||
METHOD:PUBLISH
 | 
					 | 
				
			||||||
END:VCALENDAR
 | 
					 | 
				
			||||||
"""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ics_empty_event = """BEGIN:VCALENDAR
 | 
					 | 
				
			||||||
BEGIN:VEVENT
 | 
					 | 
				
			||||||
END:VEVENT
 | 
					 | 
				
			||||||
END:VCALENDAR
 | 
					 | 
				
			||||||
"""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ics_event_no_end = """BEGIN:VCALENDAR
 | 
					 | 
				
			||||||
BEGIN:VEVENT
 | 
					 | 
				
			||||||
UID:uisgtr8tre93wewe0yr8wqy@test.com
 | 
					 | 
				
			||||||
DTSTART;VALUE=DATE:20180215
 | 
					DTSTART;VALUE=DATE:20180215
 | 
				
			||||||
END:VEVENT
 | 
					 | 
				
			||||||
END:VCALENDAR
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					date_val = only_start_date + """
 | 
				
			||||||
ics_event_date_val = """BEGIN:VCALENDAR
 | 
					 | 
				
			||||||
BEGIN:VEVENT
 | 
					 | 
				
			||||||
UID:uisgtr8tre93wewe0yr8wqy@test.com
 | 
					 | 
				
			||||||
DTSTART;VALUE=DATE:20180215
 | 
					 | 
				
			||||||
DTEND;VALUE=DATE:20180217
 | 
					DTEND;VALUE=DATE:20180217
 | 
				
			||||||
END:VEVENT
 | 
					 | 
				
			||||||
END:VCALENDAR
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					date_duration = only_start_date + """
 | 
				
			||||||
ics_event_date_duration = """BEGIN:VCALENDAR
 | 
					 | 
				
			||||||
BEGIN:VEVENT
 | 
					 | 
				
			||||||
UID:uisgtr8tre93wewe0yr8wqy@test.com
 | 
					 | 
				
			||||||
DTSTART;VALUE=DATE:20180215
 | 
					 | 
				
			||||||
DURATION:P2D
 | 
					DURATION:P2D
 | 
				
			||||||
END:VEVENT
 | 
					 | 
				
			||||||
END:VCALENDAR
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					datetime_utc_val = uid + """
 | 
				
			||||||
ics_event_datetime_utc_val = """BEGIN:VCALENDAR
 | 
					 | 
				
			||||||
BEGIN:VEVENT
 | 
					 | 
				
			||||||
UID:uisgtr8tre93wewe0yr8wqy@test.com
 | 
					 | 
				
			||||||
DTSTART;VALUE=DATE-TIME:20180319T092001Z
 | 
					DTSTART;VALUE=DATE-TIME:20180319T092001Z
 | 
				
			||||||
DTEND:20180321T102501Z
 | 
					DTEND:20180321T102501Z
 | 
				
			||||||
END:VEVENT
 | 
					 | 
				
			||||||
END:VCALENDAR
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					datetime_utc_duration = uid + """
 | 
				
			||||||
ics_event_datetime_utc_duration = """BEGIN:VCALENDAR
 | 
					 | 
				
			||||||
BEGIN:VEVENT
 | 
					 | 
				
			||||||
UID:uisgtr8tre93wewe0yr8wqy@test.com
 | 
					 | 
				
			||||||
DTSTART;VALUE=DATE-TIME:20180319T092001Z
 | 
					DTSTART;VALUE=DATE-TIME:20180319T092001Z
 | 
				
			||||||
DURATION:P2DT1H5M
 | 
					DURATION:P2DT1H5M
 | 
				
			||||||
END:VEVENT
 | 
					 | 
				
			||||||
END:VCALENDAR
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					created_updated = date_val + """
 | 
				
			||||||
ics_event_created_updated = """BEGIN:VCALENDAR
 | 
					 | 
				
			||||||
BEGIN:VEVENT
 | 
					 | 
				
			||||||
UID:uisgtr8tre93wewe0yr8wqy@test.com
 | 
					 | 
				
			||||||
DTSTART:20180215
 | 
					 | 
				
			||||||
DTEND:20180217
 | 
					 | 
				
			||||||
CREATED:20180320T071155Z
 | 
					CREATED:20180320T071155Z
 | 
				
			||||||
LAST-MODIFIED:20180326T120235Z
 | 
					LAST-MODIFIED:20180326T120235Z
 | 
				
			||||||
END:VEVENT
 | 
					 | 
				
			||||||
END:VCALENDAR
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def ics_test_cal(content):
 | 
				
			||||||
 | 
					    return "BEGIN:VCALENDAR\r\n{}END:VCALENDAR\r\n".format(content)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def ics_test_event(content):
 | 
				
			||||||
 | 
					    return ics_test_cal("BEGIN:VEVENT\r\n{}END:VEVENT\r\n".format(content))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_empty_calendar():
 | 
					def test_empty_calendar():
 | 
				
			||||||
    converter = CalendarConverter()
 | 
					    converter = CalendarConverter()
 | 
				
			||||||
    converter.loads(ics_empty)
 | 
					    converter.loads(ics_test_cal(""))
 | 
				
			||||||
    evnts = converter.events_to_gcal()
 | 
					    evnts = converter.events_to_gcal()
 | 
				
			||||||
    assert evnts == []
 | 
					    assert evnts == []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_empty_event():
 | 
					def test_empty_event():
 | 
				
			||||||
    converter = CalendarConverter()
 | 
					    converter = CalendarConverter()
 | 
				
			||||||
    converter.loads(ics_empty_event)
 | 
					    converter.loads(ics_test_event(""))
 | 
				
			||||||
    with pytest.raises(KeyError):
 | 
					    with pytest.raises(KeyError):
 | 
				
			||||||
        converter.events_to_gcal()
 | 
					        converter.events_to_gcal()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_event_no_end():
 | 
					def test_event_no_end():
 | 
				
			||||||
    converter = CalendarConverter()
 | 
					    converter = CalendarConverter()
 | 
				
			||||||
    converter.loads(ics_event_no_end)
 | 
					    converter.loads(ics_test_event(only_start_date))
 | 
				
			||||||
    with pytest.raises(ValueError):
 | 
					    with pytest.raises(ValueError):
 | 
				
			||||||
        converter.events_to_gcal()
 | 
					        converter.events_to_gcal()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.fixture(params=[
 | 
					@pytest.fixture(params=[
 | 
				
			||||||
("date", ics_event_date_val, '2018-02-15', '2018-02-17'),
 | 
					    ("date", ics_test_event(date_val), '2018-02-15', '2018-02-17'),
 | 
				
			||||||
("date", ics_event_date_duration, '2018-02-15', '2018-02-17'),
 | 
					    ("date", ics_test_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_test_event(datetime_utc_val),
 | 
				
			||||||
("dateTime", ics_event_datetime_utc_duration, '2018-03-19T09:20:01.000001Z', '2018-03-21T10:25:01.000001Z')],
 | 
					     '2018-03-19T09:20:01.000001Z', '2018-03-21T10:25:01.000001Z'),
 | 
				
			||||||
ids=['date values', 'date duration', 'datetime utc values', 'datetime utc duration']
 | 
					    ("dateTime", ics_test_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):
 | 
					def param_events_start_end(request):
 | 
				
			||||||
    return request.param
 | 
					    return request.param
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_event_start_end(param_events_start_end):
 | 
					def test_event_start_end(param_events_start_end):
 | 
				
			||||||
    (date_type, ics_str, start, end) = param_events_start_end
 | 
					    (date_type, ics_str, start, end) = param_events_start_end
 | 
				
			||||||
    converter = CalendarConverter()
 | 
					    converter = CalendarConverter()
 | 
				
			||||||
@@ -116,9 +82,10 @@ def test_event_start_end(param_events_start_end):
 | 
				
			|||||||
        date_type: end
 | 
					        date_type: end
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_event_created_updated():
 | 
					def test_event_created_updated():
 | 
				
			||||||
    converter = CalendarConverter()
 | 
					    converter = CalendarConverter()
 | 
				
			||||||
    converter.loads(ics_event_created_updated)
 | 
					    converter.loads(ics_test_event(created_updated))
 | 
				
			||||||
    events = converter.events_to_gcal()
 | 
					    events = converter.events_to_gcal()
 | 
				
			||||||
    assert len(events) == 1
 | 
					    assert len(events) == 1
 | 
				
			||||||
    event = events[0]
 | 
					    event = events[0]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user