def test_duplicates_on_end(self, mock_reader): mock_reader.return_value = [ WdcTask(id='a2254a3', date='2020-10-25', start='0930', end='', tags='home', description='', timestamp='1595423306302'), WdcTask(id='c411c941', date='2020-10-25', start='1045', end='', tags='home', description='', timestamp='1595423428554'), WdcTask(id='c411c941', date='2020-10-25', start='1045', end='1730', tags='home', description='', timestamp='1595430367883') ] results = list_tasks('2020-10-25', False) self.assertEqual(2, len(results)) self.assertEqual('a2254a3', results[0].id) self.assertEqual('c411c941', results[1].id) self.assertEqual('1730', results[1].end)
def test_duplicates_on_beginning(self, mock_reader): mock_reader.return_value = [ WdcTask(id='task', date='2020-10-25', start='0800', end='0900', tags='t1', description='test_description1', timestamp='11'), WdcTask(id='task', date='2020-10-25', start='0800', end='1000', tags='t1', description='test_description1', timestamp='22'), WdcTask(id='task2', date='2020-10-25', start='10000', end='1130', tags='t2', description='test_description1', timestamp='33') ] results = list_tasks('2020-10-25', False) self.assertEqual(2, len(results)) self.assertEqual('task', results[0].id) self.assertEqual('1000', results[0].end) self.assertEqual('22', results[0].timestamp) self.assertEqual('task2', results[1].id) self.assertEqual('33', results[1].timestamp)
def export_tasks(date: str = '', file_path: str = '', export_to: ExportType = ExportType.JSON, export_all: bool = False) -> str: if date == '': date = today() assert_date(date) if file_path == '': file_path = f'./export_{to_date_no_day(date)}.{export_to.name}' tasks = list_tasks(date, export_all) task_dump = '' if export_to == ExportType.JSON: task_dump = json.dumps(tasks, indent=4, cls=WdcTaskJsonEncoder) elif export_to == ExportType.CSV: for task in tasks: task_dump += ';'.join(to_array(task)) + '\n' write_file(task_dump, file_path) return task_dump
def list_all(ctx, date, all): tasks = list_tasks(date, all) tasks_to_print = [] for task in tasks: tasks_to_print.append(task_to_printout(task)) if not tasks: print_warning('No tasks found') ctx.exit() tt.print(tasks_to_print, header=['Id', 'Date', 'Start', 'End', 'Tags', 'Description'], style=tt.styles.thin_thick)
def test_filter_duplicate_tasks(self, mock_reader): mock_reader.return_value = [ WdcTask(id='task', date='2020-10-25', start='0800', end='0900', tags='t1', description='test_description1', timestamp='11'), WdcTask(id='task', date='2020-10-25', start='0800', end='1000', tags='t1', description='test_description1', timestamp='22') ] results = list_tasks('2020-10-25', False) self.assertEqual(1, len(results)) self.assertEqual('1000', results[0].end)
def test_return_tasks_for_given_day(self, mock_reader): mock_reader.return_value = [ WdcTask(id='task1', date='2020-10-25', start='0800', end='0900', tags='t1', description='test_description1', timestamp='11'), WdcTask(id='task2', date='2020-10-26', start='0800', end='0900', tags='t2', description='test_description2', timestamp='22') ] results = list_tasks('2020-10-25', True) self.assertEqual(1, len(results)) self.assertEqual('task1', results[0].id)