def test_export_with_none_starts(self): """Test to check event with session with none starts in pentabarfxml format""" with self.app.test_request_context(): session = SessionFactory(title='Cool Session', starts_at=None, ends_at=None) db.session.commit() pentabarf_export = PentabarfExporter() pentabarf_string = pentabarf_export.export(session.event.id) pentabarf_original = fromstring(pentabarf_string) self.assertEqual(pentabarf_original.find('day/room/event'), None)
def test_export(self): """Test to check event contents in pentabarfxml format""" with app.test_request_context(): test_event = EventFactoryBasic() save_to_db(test_event) pentabarf_export = PentabarfExporter() pentabarf_string = pentabarf_export.export(test_event.id) pentabarf_original = fromstring(pentabarf_string) self.assertEqual(fromstring(tostring(pentabarf_original))[0][0].text, "example") self.assertEqual(fromstring(tostring(pentabarf_original))[0][1].text, "2099-12-13")
def test_export(self): """Test to check event contents in pentabarfxml format""" with self.app.test_request_context(): test_event = EventFactoryBasic() save_to_db(test_event) pentabarf_export = PentabarfExporter() pentabarf_string = pentabarf_export.export(test_event.id) pentabarf_original = fromstring(pentabarf_string) self.assertEqual(pentabarf_original.find('conference/title').text, "example") self.assertEqual( pentabarf_original.find('conference/start').text, "2099-12-13" )
def export_pentabarf_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 = "pentabarf.xml" file_path = os.path.join(filedir, filename) with open(file_path, "w") as temp_file: temp_file.write(str(PentabarfExporter.export(event_id), 'utf-8')) pentabarf_file = UploadedFile(file_path=file_path, filename=filename) if temp: pentabarf_url = upload(pentabarf_file, UPLOAD_PATHS['exports-temp']['pentabarf'].format(event_id=event_id)) else: pentabarf_url = upload(pentabarf_file, UPLOAD_PATHS['exports']['pentabarf'].format(event_id=event_id)) result = { 'download_url': pentabarf_url } if not temp: event.pentabarf_url = pentabarf_url save_to_db(event) except Exception as e: print(traceback.format_exc()) result = {'__error': True, 'result': str(e)} return result
def test_export_with_multiple_sessions(self): """Test to check event with sessions in pentabarfxml format""" with self.app.test_request_context(): keynote = SessionFactory( title='Keynote', starts_at=datetime(2019, 10, 15, 10, 25, 46), ends_at=datetime(2019, 10, 15, 11, 10, 46), track__name='Amazing Track', microlocation__name='Great Hall', event__name='Awesome Conference', event__starts_at=datetime(2019, 10, 15), event__ends_at=datetime(2019, 10, 16, 13, 30, 00), ) UserFactory() mario = SpeakerFactoryBase.build(name='Mario Behling', user_id=1) keynote.speakers = [ mario, SpeakerFactoryBase.build(name='Hong Phuc Dang', user_id=1), ] SessionFactoryBase( title='Hot Session', starts_at=datetime(2019, 10, 15, 11, 30, 00), ends_at=datetime(2019, 10, 15, 12, 00, 54), ) future_session = SessionFactoryBase( title='Future Session', starts_at=datetime(2019, 10, 16, 9, 15, 30), ends_at=datetime(2019, 10, 16, 10, 30, 45), ) future_session.speakers = [ SpeakerFactoryBase.build(name='Pranav Mistry', user_id=1) ] MicrolocationFactoryBase(name='Assembly Hall') end_session = SessionFactoryBase( title='Bye Bye Session', starts_at=datetime(2019, 10, 16, 11, 30, 20), ends_at=datetime(2019, 10, 16, 13, 00, 30), microlocation_id=2, ) end_session.speakers = [mario] db.session.commit() pentabarf_export = PentabarfExporter() pentabarf_string = pentabarf_export.export(keynote.event.id) pentabarf_original = fromstring(pentabarf_string) self.assertEqual( pentabarf_original.find('conference/title').text, "Awesome Conference" ) self.assertEqual( pentabarf_original.find('conference/start').text, '2019-10-15' ) self.assertEqual(pentabarf_original.find('conference/end').text, '2019-10-16') self.assertEqual(pentabarf_original.find('conference/days').text, '1') self.assertEqual( pentabarf_original.find('day/room').attrib['name'], 'Great Hall' ) self.assertEqual( pentabarf_original.find('day/room/event/title').text, 'Keynote' ) self.assertEqual( pentabarf_original.find('day/room/event/track').text, 'Amazing Track' ) self.assertEqual( pentabarf_original.find('day/room/event/start').text, '10:25' ) self.assertEqual( pentabarf_original.find('day/room/event/duration').text, '00:45' ) self.assertEqual( pentabarf_original.find('day/room/event/persons/person[@id="2"]').text, 'Hong Phuc Dang', ) self.assertEqual( len(pentabarf_original.find('day/room/event/persons').getchildren()), 2 ) self.assertEqual( pentabarf_original.find('day/room/event[2]/title').text, 'Hot Session' ) self.assertEqual( pentabarf_original.find('day[2]/room/event/title').text, 'Future Session' ) self.assertEqual( pentabarf_original.find('day[2]/room/event/persons/person').text, 'Pranav Mistry', ) self.assertEqual( pentabarf_original.find('day[2]/room[2]').attrib['name'], 'Assembly Hall' ) self.assertEqual( pentabarf_original.find('day[2]/room[2]/event/title').text, 'Bye Bye Session', ) self.assertEqual( pentabarf_original.find('day[2]/room[2]/event/duration').text, '01:30' ) self.assertEqual( pentabarf_original.find('day[2]/room[2]/event/persons/person').text, 'Mario Behling', )