def test_export_sessions_none_csv(self): """Method to check sessions data export with no abstract""" with self.app.test_request_context(): test_session = SessionFactory() test_session.long_abstract = None test_session.level = None self._test_export_session_csv(test_session)
def test_export_sessions_with_details_csv(self): """Method to check that sessions details are correct""" with self.app.test_request_context(): test_session = SessionFactory( short_abstract='short_abstract', long_abstract='long_abstract', comments='comment', level='level', created_at=common.date_, ) db.session.commit() field_data = export_sessions_csv([test_session]) session_row = field_data[1] self.assertEqual(session_row[0], 'example (accepted)') self.assertEqual(session_row[1], '') self.assertEqual(session_row[2], common.string_) self.assertEqual(session_row[3], 'short_abstract') self.assertEqual(session_row[4], 'long_abstract') self.assertEqual(session_row[5], 'comment') self.assertEqual(session_row[6], common.date_.astimezone()) self.assertEqual(session_row[7], 'Yes') self.assertEqual(session_row[8], 'level') self.assertEqual(session_row[9], 'accepted') self.assertEqual(session_row[10], common.string_) self.assertEqual(session_row[11], '00:30') self.assertEqual(session_row[12], 'English') self.assertEqual(session_row[13], common.url_) self.assertEqual(session_row[14], common.url_) self.assertEqual(session_row[15], common.url_)
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_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 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_session_csv(self, test_session=None): with self.app.test_request_context(): if not test_session: test_session = SessionFactory() field_data = export_sessions_csv([test_session]) session_row = field_data[1] self.assertEqual(session_row[0], 'example (accepted)') self.assertEqual(session_row[9], 'accepted')
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_date_db_populate(self): """ Sessions Validate Date - Tests if validation works on values stored in db and not given in 'data' :return: """ with self.app.test_request_context(): schema = SessionSchema() SessionFactory() original_data = {'data': {'id': 1}} data = {} SessionSchema.validate_fields(schema, data, original_data)
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', )
def session(db): return SessionFactory()