def create_from_ics(namespace, db_session, ics_str): try: events = events_from_ics(namespace, ics_str) except MalformedEventError: return None db_session.add_all(events) db_session.commit() return events
def test_handle_missing_sequence_number(db, default_account): with open(absolute_path(FIXTURES + "event_without_sequence.ics")) as fd: data = fd.read() events = events_from_ics(default_account.namespace, default_account.emailed_events_calendar, data) events = events["invites"] assert len(events) == 1 ev = events[0] assert ev.sequence_number == 0
def test_multiple_summaries(db, default_account): data = None with open(absolute_path(FIXTURES + "multiple_summaries.ics")) as fd: data = fd.read() events = events_from_ics(default_account.namespace, default_account.emailed_events_calendar, data) events = events["invites"] assert len(events) == 1 assert events[0].title == "The Strokes - Is this it?"
def create_from_ics(namespace, db_session, ics_str): account = db_session.query(Account).filter( Account.id == namespace.account_id).one() try: events = events_from_ics(namespace, account.default_calendar, ics_str) except MalformedEventError: return None db_session.add_all(events) db_session.commit() return events
def test_event_no_participants(db, default_account): data = None with open(absolute_path(FIXTURES + 'event_with_no_participants.ics')) as fd: data = fd.read() events = events_from_ics(default_account.namespace, default_account.emailed_events_calendar, data) assert len(events) == 1, "There should be only one event in the test file" ev = events[0] assert len(ev.participants) == 0
def test_iphone_through_exchange(db, default_account): data = None with open(absolute_path(FIXTURES + 'iphone_through_exchange.ics')) as fd: data = fd.read() events = events_from_ics(default_account.namespace, default_account.emailed_events_calendar, data) assert len(events) == 1, "There should be only one event in the test file" ev = events[0] assert ev.start == arrow.get(2014, 12, 27, 15, 0) assert ev.end == arrow.get(2014, 12, 27, 16, 0)
def test_multiple_events(db, default_account): data = None with open(absolute_path(FIXTURES + 'multiple_events.ics')) as fd: data = fd.read() events = events_from_ics(default_account.namespace, default_account.emailed_events_calendar, data) assert len(events) == 2 ev0 = events[0] ev1 = events[1] assert len(ev0.participants) == 0 assert len(ev1.participants) == 0 assert ev1.start == arrow.get(2015, 03, 17, 0, 0)
def test_windows_tz_ical(db, default_account): data = None with open(absolute_path(FIXTURES + 'windows_event.ics')) as fd: data = fd.read() events = events_from_ics(default_account.namespace, default_account.emailed_events_calendar, data) assert len(events) == 1, "There should be only one event in the test file" ev = events[0] assert ev.start == arrow.get(2015, 2, 20, 8, 30) assert ev.end == arrow.get(2015, 2, 20, 9, 0) assert ev.title == "Pommes" assert len(ev.participants) == 1 assert ev.participants[0]['email'] == '*****@*****.**'
def test_icloud_allday_event(db, default_account): data = None with open(absolute_path(FIXTURES + 'icloud_oneday_event.ics')) as fd: data = fd.read() events = events_from_ics(default_account.namespace, default_account.emailed_events_calendar, data) assert len(events) == 1, "There should be only one event in the test file" ev = events[0] assert ev.all_day is True assert ev.start == arrow.get(2015, 3, 16, 0, 0) assert ev.end == arrow.get(2015, 3, 17, 0, 0) assert len(ev.participants) == 2 assert ev.participants[0]['email'] == '*****@*****.**'
def test_invalid_ical(db): with pytest.raises(MalformedEventError): account = db.session.query(Account).filter_by(id=ACCOUNT_ID).first() events_from_ics(account.namespace, account.default_calendar, "asdf")
def test_invalid_ical(db, default_account): with pytest.raises(MalformedEventError): events_from_ics(default_account.namespace, default_account.emailed_events_calendar, "asdf")