def _data(self): """Return birthdays sorted by day an fullname.""" if HAS_PERSON: birthdays = self.get_birthdays_from_persons() else: birthdays = self.get_birthdays_from_users() return sort_birthdays(birthdays)
def test_sort_birthdays(self): birthdays = [ dict(birthday='19/07', fullname='FFF'), dict(birthday='19/07', fullname='EEE'), dict(birthday='01/01', fullname='DDD'), dict(birthday='28/01', fullname='CCC'), dict(birthday='01/01', fullname='BBB'), dict(birthday='28/01', fullname='AAA'), ] sorted_birthdays = sort_birthdays(birthdays) days = [day for day in sorted_birthdays] # we have 3 different dates: 01/01, 28/01 and 19/07 self.assertEqual(len(days), 3) # we test each date do see if it is sorted self.assertEqual( sorted_birthdays[days[0]], [ {'fullname': 'BBB', 'birthday': '01/01'}, {'fullname': 'DDD', 'birthday': '01/01'} ] ) self.assertEqual( sorted_birthdays[days[1]], [ {'fullname': 'AAA', 'birthday': '28/01'}, {'fullname': 'CCC', 'birthday': '28/01'}, ] ) self.assertEqual( sorted_birthdays[days[2]], [ {'fullname': 'EEE', 'birthday': '19/07'}, {'fullname': 'FFF', 'birthday': '19/07'}, ] )
def test_long_period(self): render = self.renderer(assignment=birthdayportlet.Assignment(365)) self.assertFalse(render.available) birthday1 = datetime.date(datetime.now()) birthday2 = datetime.date(datetime.now() + timedelta(days=364)) self.portal.invokeFactory('Person', 'name1', birthday=birthday1) self.portal.invokeFactory('Person', 'name2', birthday=birthday2) self.pw.doActionFor(self.portal['name1'], 'publish') self.pw.doActionFor(self.portal['name2'], 'publish') birthdays = render.get_birthdays_from_persons() birthdays = sort_birthdays(birthdays) self.assertEqual(2, len(birthdays))