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 test_csv_default_parameters_multiple_tasks(self, mock_writer, mock_reader, mock_today): mock_today.return_value = '2020-10-25' mock_reader.return_value = [ WdcTask(id='c411c941', date='2020-10-25', start='0930', end='1000', tags='home', description='test description', timestamp='1595423306302'), WdcTask(id='c411c942', date='2020-10-25', start='0930', end='1000', tags='home', description='test description1', timestamp='1595423306303') ] expected_dump = """c411c941;2020-10-25;0930;1000;home;test description;1595423306302 c411c942;2020-10-25;0930;1000;home;test description1;1595423306303""" result = export_tasks(export_to=ExportType.CSV) self.assertIn(expected_dump, mock_writer.call_args.args[0]) self.assertIn('export_202010.CSV', mock_writer.call_args.args[1]) self.assertIn(expected_dump, result)
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_valid_descending(self): test_object = [ WdcTask(id='1', date='2020-10-25', start='0800', end='0900', tags='t1', description='description', timestamp='11'), WdcTask(id='2', date='2020-10-25', start='1000', end='1100', tags='t1', description='description', timestamp='2'), WdcTask(id='3', date='2020-10-25', start='0900', end='1000', tags='t1', description='description', timestamp='33') ] result = sort_by_time(test_object, descending=True) self.assertEqual('2', result[0].id) self.assertEqual('3', result[1].id) self.assertEqual('1', result[2].id)
def test_default_parameters(self, mock_writer, mock_reader, mock_today): mock_today.return_value = '2020-10-25' mock_reader.return_value = [ WdcTask(id='c411c941', date='2020-10-25', start='0930', end='1000', tags='home', description='test description', timestamp='1595423306302') ] expected_dump = """[ { "id": "c411c941", "timestamp": "1595423306302", "tags": "home", "start": "0930", "end": "1000", "message": "test description" } ]""" result = export_tasks() self.assertIn(expected_dump, mock_writer.call_args.args[0]) self.assertIn('export_202010.JSON', mock_writer.call_args.args[1]) self.assertIn(expected_dump, result)
def test_fully_qualified_parameters(self, mock_writer, mock_reader, mock_today): mock_today.return_value = '2020-10-25' mock_reader.return_value = [ WdcTask(id='c411c941', date='2020-10-25', start='0930', end='1000', tags='home', description='test description', timestamp='1595423306302') ] expected_dump = """[ { "id": "c411c941", "timestamp": "1595423306302", "tags": "home", "start": "0930", "end": "1000", "message": "test description" } ]""" result = export_tasks('2020-08-18', 'myexport.json', ExportType.JSON) self.assertEqual('2020-08-18', mock_reader.call_args.args[0]) mock_today.assert_not_called() self.assertIn(expected_dump, mock_writer.call_args.args[0]) self.assertIn('myexport.json', mock_writer.call_args.args[1]) self.assertIn(expected_dump, result)
def test_replace_all(self, mock_writer, mock_reader): mock_reader.return_value = WdcTaskInfo([ WdcTask(id='c411c941', date='2020-10-25', start='0930', end='1000', tags='home', description='test description', timestamp='1595423306302') ]) amend_task('c411c941', tags=['t1', 't2'], start='1000', end='1130', message='test message', date='2020-08-18') mock_writer.assert_called() call_args = mock_writer.call_args.args[0] self.assertEqual('c411c941', call_args.id) self.assertEqual('t1,t2', call_args.tags) self.assertEqual('1000', call_args.start) self.assertEqual('1130', call_args.end) self.assertEqual('test message', call_args.description) self.assertEqual('2020-08-18', call_args.date)
def test_equality_different_id_invalid(self): test_object = WdcTask(id='test_id1', date='2020-10-25', start='0800', end='0900', tags='t1', description='description', timestamp='11') test_object2 = WdcTask(id='test_id2', date='2020-10-25', start='0800', end='0900', tags='t1', description='description', timestamp='11') self.assertFalse(test_object == test_object2)
def test_with_history_valid(self, mock_controller): mock_controller.return_value = WdcTaskInfo([ WdcTask(id='testId', date='2020-10-25', start='0800', end='', tags='t1', description='testDescription', timestamp='11'), WdcTask(id='testId', date='2020-10-25', start='0800', end='1000', tags='t1', description='testDescription', timestamp='12'), WdcTask(id='testId', date='2020-10-25', start='0800', end='1000', tags='t1, t2', description='testDescription', timestamp='13') ]) result = self.cli_runner.invoke(cli, ['info', 'testId']) self.assertIn('id : testId', result.output) self.assertIn('description : testDescription', result.output) self.assertIn('timestamp : 13', result.output) self.assertIn('start : 0800', result.output) self.assertIn('end : 1000', result.output) self.assertIn('tags : t1, t2', result.output) self.assertIn( '│ 12 │ 2020-10-25 │ 08:00 │ 10:00 │ t1 │ testDescription │', result.output) self.assertIn( '│ 11 │ 2020-10-25 │ 08:00 │ │ t1 │ testDescription │', result.output)
def test_encode_list(self): test_object = [ WdcTask(id='c411c941', date='2020-10-25', start='0930', end='1000', tags='home', description='test description', timestamp='1595423306302'), WdcTask(id='c411c941', date='2020-10-25', start='0930', end='1000', tags='home', description='test description', timestamp='1595423306302') ] result = json.dumps(test_object, indent=4, cls=WdcTaskJsonEncoder) self.assertEqual( """[ { "id": "c411c941", "timestamp": "1595423306302", "tags": "home", "start": "0930", "end": "1000", "message": "test description" }, { "id": "c411c941", "timestamp": "1595423306302", "tags": "home", "start": "0930", "end": "1000", "message": "test description" } ]""", result)
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)
def test_valid(self): task = WdcTask(id='test_id', date='2020-10-25', start='0800', end='0900', tags='t1', description='description', timestamp='1603620000') result = to_array(task) self.assertSequenceEqual(result, [ 'test_id', '2020-10-25', '0800', '0900', 't1', 'description', '1603620000' ])
def test_ttask_to_printout_valid(self): test_object = WdcTask(id='testId', date='2020-10-25', start='0800', end='0900', tags='t1', description='testDescription', timestamp='11') result = task_to_printout(test_object) self.assertSequenceEqual( result, ['testId', '2020-10-25', '08:00', '09:00', 't1', 'testDescri..'])
def setUp(self) -> None: self._valid_task_info = WdcTaskInfo([ WdcTask(id='c411c941', date='2020-10-25', start='0930', end='', tags='home', description='', timestamp='1595423306302'), WdcTask(id='c411c941', date='2020-10-25', start='0930', end='1000', tags='home', description='', timestamp='1595423428554'), WdcTask(id='c411c941', date='2020-10-25', start='1045', end='1730', tags='home', description='', timestamp='1595430367883') ])
def test_minimal_task_valid(self, mock_controller): mock_controller.return_value = [ WdcTask(id='test_id', date='2020-10-25', start='0800', end='', tags='', description='', timestamp='11') ] result = self.cli_runner.invoke(cli, ['list']) self.assertIn( '│ test_id │ 2020-10-25 │ 08:00 │ │ │ │', result.output)
def start_work_task(start_time: str, end_time: str, tags: List[str], description: str, date: str): start = WdcTime(start_time) end = WdcTime(end_time) if end_time else None # If a date is provided then it has to be valid if not is_date_valid(date) and date != '': raise ValueError(f'{date} is not a valid date format') # When no date is provided then we assume "today" date = date if date else today() row_id = generate_hash(f'{start_time}{end_time}{description}') task_data = WdcTask(id=row_id, date=date, start=str(start), end=str(end) if end is not None else '', tags=array_to_tags_string(tags), description=description) write_task(task_data)
def test_no_history_valid(self, mock_controller): mock_controller.return_value = WdcTaskInfo([ WdcTask(id='testId', date='2020-10-25', start='0800', end='', tags='t1', description='testDescription', timestamp='11') ]) result = self.cli_runner.invoke(cli, ['info', 'testId']) self.assertIn('id : testId', result.output) self.assertIn('description : testDescription', result.output) self.assertIn('timestamp : 11', result.output) self.assertIn('start : 0800', result.output) self.assertIn('tags : t1', result.output) # If there is no history then the table is not displayed. # Check that the table header is not present in the output self.assertNotIn( '│ Timestamp │ Date │ Start │ End │ Tags │ Description │', result.output)