def testFirst(self): first_query = self.first_query session.query(Event).delete() session.commit() session.flush() e = Event(self.et) e.title = 'First event' e.time_start = datetime(1970, 1, 1, 0, 0) e.time_end = datetime(1970, 1, 1, 3, 0) e.description = 'First description' e.source_type = EventSourceType.EMPTY session.add(e) session.commit() all_first = first_query.all() self.assertEquals(len(all_first), 1) e = all_first[0] self.assertEquals(e.title, 'First event') self.assertEquals(e.time_start, datetime(1970, 1, 1, 0, 0)) self.assertEquals(e.time_end, datetime(1970, 1, 1, 3, 0)) self.assertEquals(e.description, 'First description') self.assertEquals(e.source_type, EventSourceType.EMPTY) self.assertEquals(e.event_type.name, 'first') all_date_empty = session.query(Event).filter( Event.time_start == date(1971, 1, 1)).all() self.assertEquals(len(all_date_empty), 0) all_date_fine = session.query(Event).filter( Event.time_start == date(1970, 1, 1)).all() self.assertEquals(len(all_date_fine), 1) session.delete(e) session.commit()
def testFirst(self): first_query = self.first_query session.query(Event).delete() session.commit() session.flush() e = Event(self.et) e.title = 'First event' e.time_start = datetime(1970, 1, 1, 0, 0) e.time_end = datetime(1970, 1, 1, 3, 0) e.description = 'First description' e.source_type = EventSourceType.EMPTY session.add(e) session.commit() all_first = first_query.all() self.assertEquals(len(all_first), 1) e = all_first[0] self.assertEquals(e.title, 'First event'); self.assertEquals(e.time_start, datetime(1970, 1, 1, 0, 0)) self.assertEquals(e.time_end, datetime(1970, 1, 1, 3, 0)) self.assertEquals(e.description, 'First description') self.assertEquals(e.source_type, EventSourceType.EMPTY) self.assertEquals(e.event_type.name, 'first') all_date_empty = session.query(Event).filter(Event.time_start == date(1971, 1, 1)).all() self.assertEquals(len(all_date_empty), 0) all_date_fine = session.query(Event).filter(Event.time_start == date(1970, 1, 1)).all() self.assertEquals(len(all_date_fine), 1) session.delete(e) session.commit()
def testSecond(self): session.query(Event).delete() session.query(Person).delete() session.query(Place).delete() session.commit() place = Place('First place') place.address = 'Address' place.phone = 'Phone' place.site_url = 'http://localhost' persons_list = [] persons_list.append(Person('First', Person.MUSICIAN)) persons_list.append(Person('Second', Person.MUSICIAN)) e = Event(self.et) e.place = place for p in persons_list: e.persons.append(p) session.add(e) session.commit() session.flush() first_query = self.first_query all_first = first_query.all() self.assertEquals(len(all_first), 1) e = all_first[0] place = e.place self.assertEquals(place.address, 'Address') self.assertEquals(place.phone, 'Phone') self.assertEquals(place.site_url, 'http://localhost') person_names = [] for p in e.persons: person_names.append(p.name) self.assert_('First' in person_names) self.assert_('Second' in person_names) e = Event(EventType.findByName(session, 'live'), 'Live event') e.addEventStatus(EventStatus(EventStatus.LIVE_WANT)) e.addEventStatus(EventStatus(EventStatus.LIVE_BE_HERE)) session.add(e) session.commit() session.flush() events = self.live_query.all() self.assertEquals(len(events), 1) e = events[0] self.assertEquals(len(e.event_status_list), 2) self.assertEquals(e.last_status, EventStatus.LIVE_BE_HERE)
def testSecond(self): session.query(Event).delete() session.query(Person).delete() session.query(Place).delete() session.commit() place = Place('First place') place.address = 'Address' place.phone = 'Phone' place.site_url = 'http://localhost'; persons_list = [] persons_list.append(Person('First', Person.MUSICIAN)) persons_list.append(Person('Second', Person.MUSICIAN)) e = Event(self.et) e.place = place for p in persons_list: e.persons.append(p) session.add(e) session.commit() session.flush() first_query = self.first_query all_first = first_query.all() self.assertEquals(len(all_first), 1) e = all_first[0] place = e.place self.assertEquals(place.address, 'Address') self.assertEquals(place.phone, 'Phone') self.assertEquals(place.site_url, 'http://localhost') person_names = [] for p in e.persons: person_names.append(p.name) self.assert_('First' in person_names) self.assert_('Second' in person_names) e = Event(EventType.findByName(session, 'live'), 'Live event') e.addEventStatus(EventStatus(EventStatus.LIVE_WANT)) e.addEventStatus(EventStatus(EventStatus.LIVE_BE_HERE)) session.add(e) session.commit() session.flush() events = self.live_query.all() self.assertEquals(len(events), 1); e = events[0] self.assertEquals(len(e.event_status_list), 2) self.assertEquals(e.last_status, EventStatus.LIVE_BE_HERE)