def test_export_basic(self): """Test to export ical format event""" with self.app.test_request_context(): test_session = SessionFactory() icalexport_object = ICalExporter() test_cal_str = icalexport_object.export(test_session.event_id) test_cal = icalendar.Calendar.from_ical(test_cal_str) self.assertEqual(test_cal['x-wr-calname'], 'example') self.assertEqual(test_cal['x-wr-caldesc'], 'Schedule for sessions at example')
def export_ical_task(self, event_id, temp=True): event = safe_query(db, Event, 'id', event_id, 'event_id') try: if temp: filedir = os.path.join(current_app.config.get('BASE_DIR'), 'static/uploads/temp/' + event_id + '/') else: filedir = os.path.join(current_app.config.get('BASE_DIR'), 'static/uploads/' + event_id + '/') if not os.path.isdir(filedir): os.makedirs(filedir) filename = "ical.ics" file_path = os.path.join(filedir, filename) with open(file_path, "w") as temp_file: temp_file.write(str(ICalExporter.export(event_id), 'utf-8')) ical_file = UploadedFile(file_path=file_path, filename=filename) if temp: ical_url = upload(ical_file, UPLOAD_PATHS['exports-temp']['ical'].format(event_id=event_id)) else: ical_url = upload(ical_file, UPLOAD_PATHS['exports']['ical'].format(event_id=event_id)) result = { 'download_url': ical_url } if not temp: event.ical_url = ical_url save_to_db(event) except Exception as e: print(traceback.format_exc()) result = {'__error': True, 'result': str(e)} return result
def test_export_basic(db): test_event = EventFactoryBasic(identifier='asdfgh', name='Hoopa Loopa', location_name='Narnia', timezone='Asia/Kolkata') test_microlocation = MicrolocationSubFactory( name='online', event=test_event, ) test_session = SessionFactory( title='Gooseberry Muffin', event=test_event, microlocation=test_microlocation, ) db.session.commit() test_cal_str = to_ical(test_session.event, include_sessions=True) test_cal = icalendar.Calendar.from_ical(test_cal_str) event = test_cal.subcomponents[0] assert event['summary'] == 'Hoopa Loopa' assert event['url'] == 'http://eventyay.com/e/asdfgh' assert event['location'] == 'Narnia' timezone = test_cal.subcomponents[1] assert timezone['TZID'] == 'Asia/Kolkata' session = test_cal.subcomponents[2] assert session['summary'] == 'Gooseberry Muffin' assert session[ 'url'] == f'http://eventyay.com/e/asdfgh/session/{test_session.id}' assert (session['location'] == f'online') assert ICalExporter.export(test_session.event_id) == test_cal_str
def test_export_subcomponents(self): """Test to check presence of subcomponents""" with self.app.test_request_context(): test_session = SessionFactory() speaker = SpeakerFactory(name="xyz", email="*****@*****.**", user_id=1) test_session.speakers = [speaker] test_cal = icalendar.Calendar.from_ical(ICalExporter().export( test_session.event_id)) cal_content_lines = test_cal.content_lines() self.assertIn( 'URL:http://localhost/v1/events?identifier={}'.format( test_session.event.identifier), cal_content_lines) self.assertIn('LOCATION:example', cal_content_lines) self.assertIn('ATTENDEE;CN=xyz:MAILTO:[email protected]', cal_content_lines)
def test_export_basic(db): test_session = SessionSubFactory( title='Gooseberry Muffin', event__name='Hoopa Loopa', event__identifier='asdfgh', event__location_name='Narnia', ) db.session.commit() test_cal_str = to_ical(test_session.event, include_sessions=True) test_cal = icalendar.Calendar.from_ical(test_cal_str) event = test_cal.subcomponents[0] assert event['summary'] == 'Hoopa Loopa' assert event['url'] == 'http://eventyay.com/e/asdfgh' assert event['location'] == 'Narnia' session = test_cal.subcomponents[1] assert session['summary'] == 'Gooseberry Muffin' assert session['url'] == f'http://eventyay.com/e/asdfgh/session/{test_session.id}' assert ICalExporter.export(test_session.event_id) == test_cal_str