def export_xcal_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 = "xcal.xcs" file_path = os.path.join(filedir, filename) with open(file_path, "w") as temp_file: temp_file.write(str(XCalExporter.export(event_id), 'utf-8')) xcal_file = UploadedFile(file_path=file_path, filename=filename) if temp: xcal_url = upload(xcal_file, UPLOAD_PATHS['exports-temp']['xcal'].format(event_id=event_id)) else: xcal_url = upload(xcal_file, UPLOAD_PATHS['exports']['xcal'].format(event_id=event_id)) result = { 'download_url': xcal_url } if not temp: event.xcal_url = xcal_url save_to_db(event) except Exception as e: print(traceback.format_exc()) result = {'__error': True, 'result': str(e)} return result
def test_export(self): """Test to check event contents in xCal format""" with self.app.test_request_context(): test_event = EventFactoryBasic() save_to_db(test_event) xcal = XCalExporter() xcal_string = xcal.export(test_event.id) xcal_original = fromstring(xcal_string) assert fromstring(tostring(xcal_original))[0][3].text == "example" assert fromstring(tostring(xcal_original))[0][2].text == \ "Schedule for sessions at example"