def _output(self, projects, users=None): # formated output print '' print 'Projects:' found_users = [] zebra_url = self.secret.get_zebra('url') for name, entries in projects: print '- %s' % name total = 0 template = " {time:<12} {username:<23} {description:<45} ({url:<15})" for entry in entries: d = dict() d['time'] = str(entry.time) + ' hours' d['username'] = entry.username if entry.username not in found_users: found_users.append(entry.username) d['description'] = entry.description[:44] d['url'] = ZebraHelper.get_activity_url(zebra_url, entry.id) print template.format(**d) total += entry.time print ' Total: %s' % (total) print '' if users is not None: if len(users) == len(found_users): print '(found entries for all users)' else: print 'Found entries for %d out of %d users (%s)' % \ (len(found_users), len(users), ','.join(found_users))
def get_start_and_end_date(self, dates): """ Get a tuple with start and end dates. Default is none for end date, and last week-day for start_date :param dates:list of dates :return:tuple (start,end) """ date_objects = [dateutil.parser.parse(d, dayfirst=True) for d in dates] # default values is None for end_date and last week-day for start_date start_date = None end_date = None if date_objects is None or len(date_objects) == 0: date_objects.append(DateHelper.get_last_week_day()) if len(date_objects) == 1: start_date = ZebraHelper.zebra_date(date_objects[0]) if len(date_objects) == 2: start_date = ZebraHelper.zebra_date(min(date_objects)) end_date = ZebraHelper.zebra_date(max(date_objects)) return (start_date, end_date)
def testStartAndEndDates(self): """should return a tuple with start and end dates as zebra dates""" base_command = BaseCommand() self.assertEquals( ('2013-05-22', None), base_command.get_start_and_end_date(['2013.05.22']), 'test input format 1' ) self.assertEquals( ('2013-05-22', None), base_command.get_start_and_end_date(['22.05.2013']), 'test input format 2' ) self.assertNotEquals( (None, None), base_command.get_start_and_end_date([]), 'if no date is specified, date_start should not be None' ) last_week_day = ZebraHelper.zebra_date(DateHelper.get_last_week_day()) self.assertEquals( (last_week_day, None), base_command.get_start_and_end_date([]), 'if no date is specified, date_start should be last week day' )
def testZebraDate(self): """date format is correct""" date = datetime.datetime.strptime('20130428', "%Y%m%d").date() self.assertEquals('2013-04-28', ZebraHelper.zebra_date(date))
def testGetActivityId(self): self.assertEquals('basepath/timesheet/123', ZebraHelper.get_activity_url('basepath', 123))