Ejemplo n.º 1
0
 def run(self):
     while True:
         self.print_menu()
         option = self.get_option()
         if option == 'a':
             from work_log import WorkLog
             WorkLog.add_task()
         if option == 'b':
             SearchMenu().run()
         if option == 'c':
             break
Ejemplo n.º 2
0
    def run(self):
        from work_log import WorkLog
        while True:
            self.print_menu()
            option = self.get_option()
            if option == 'p':
                self.index -= 1
            if option == 'n':
                self.index += 1
            if option == 'e':
                self.index = WorkLog.edit_task(self.index, self.tasks)
            if option == 'd':
                self.index = WorkLog.delete_task(self.index, self.tasks)
            if option == 'r':
                break

            self.__init__(self.index, self.tasks)
Ejemplo n.º 3
0
 def setUp(self):
     self.log = WorkLog('log.csv')
     self.tasks = self.log.TASKS
Ejemplo n.º 4
0
 def test_side_run(self, fake_run):
     self.menu.side_run(result=[])
     self.assertTrue(fake_run.called)
     self.assertTrue(fake_run.called_with(WorkLog(), 0, []))
Ejemplo n.º 5
0
 def setUp(self):
     self.menu = SearchMenu(WorkLog())
Ejemplo n.º 6
0
 def setUp(self):
     self.menu = MainMenu(WorkLog())
Ejemplo n.º 7
0
 def setUp(self):
     option = MenuOption('a', 'First Option', WorkLog(), 'add_task')
     self.menu = Menu()
     self.menu.options.append(option)
Ejemplo n.º 8
0
 def test_init_and_str(self):
     option = MenuOption('a', 'First Option', WorkLog(), 'add_task')
     self.assertEqual(str(option), "a) First Option")
Ejemplo n.º 9
0
 def test_init_file_not_found(self):
     log = WorkLog('nofile')
     self.assertEqual(log.TASKS, [])
Ejemplo n.º 10
0
 def test_init_no_file(self):
     log = WorkLog()
     self.assertEqual(log.TASKS, [])
Ejemplo n.º 11
0
 def setUp(self):
     self.log = WorkLog('log.csv')
Ejemplo n.º 12
0
class WorkLogTests(unittest.TestCase):
    def setUp(self):
        self.log = WorkLog('log.csv')

    def test_init_no_file(self):
        log = WorkLog()
        self.assertEqual(log.TASKS, [])

    def test_init_file_not_found(self):
        log = WorkLog('nofile')
        self.assertEqual(log.TASKS, [])

    @mock.patch('task.Task.edit')
    @mock.patch('work_log.WorkLog.save_log')
    def test_edit_task(self, fake_save, fake_edit):
        index = self.log.edit_task(4, self.log.TASKS)
        self.assertEqual(index, 4)
        self.assertEqual(fake_edit.call_count, 1)
        self.assertEqual(fake_save.call_count, 1)

    @mock.patch('builtins.input')
    @mock.patch('work_log.WorkLog.save_log')
    def test_delete_task(self, fake_save, fake_input):
        fake_input.return_value = 'y'

        tasks = [task for task in self.log.TASKS]
        len_tasks = len(tasks)
        len_TASKS = len(self.log.TASKS)

        entry = tasks[4]
        index = self.log.delete_task(4, tasks)

        self.assertEqual(index, 3)
        self.assertEqual(len(tasks), len_tasks - 1)
        self.assertEqual(len(self.log.TASKS), len_TASKS - 1)
        self.assertNotIn(entry, tasks)
        self.assertNotIn(entry, self.log.TASKS)
        self.assertEqual(fake_save.call_count, 1)

    @mock.patch('builtins.input')
    @mock.patch('work_log.WorkLog.save_log')
    def test_delete_no_deletion(self, fake_save, fake_input):
        fake_input.return_value = 'n'
        index = self.log.delete_task(6, self.log.TASKS)
        self.assertEqual(index, 6)
        self.assertFalse(fake_save.called)

    @mock.patch('builtins.input')
    @mock.patch('builtins.print')
    def test_add_task_and_sort_tasks(self, fake_print, fake_input):
        fake_input.side_effect = [
            'Test WorkLog class', '08/10/1000', '3141592', 'Test notes', ''
        ]
        self.log.add_task()
        self.assertEqual(fake_input.call_count, 5)
        self.assertEqual(fake_print.call_count, 6)

    @mock.patch('builtins.input')
    def test_delete_task_index_0(self, fake_input):
        fake_input.return_value = 'y'

        tasks = [task for task in self.log.TASKS]
        len_tasks = len(tasks)
        len_TASKS = len(self.log.TASKS)

        index = self.log.delete_task(0, tasks)
        self.assertEqual(index, 0)
        self.assertEqual(len(tasks), len_tasks - 1)
        self.assertEqual(len(self.log.TASKS), len_TASKS - 1)
Ejemplo n.º 13
0
    if len(sys.argv) > 2:
        log = EntryLog(sys.argv[1])
    else:
        log = EntryLog()

    init_vars = {
        'main_menu': config.MAIN_MENU,
        'search_menu': config.SEARCH_MENU,
        'date_menu': config.DATE_SEARCH_MENU,
        'duration_menu': config.DURATION_SEARCH_MENU,
        'task_menu' : config.TASK_MENU,
        'edit_menu' : config.EDIT_MENU,
        'log': log
    }
    
    work_log = WorkLog(**init_vars)

    while True:

        if work_log.action in ('main', 'search', 'date', 'duration', 'edit'):

            

            if work_log.action != 'edit':
                work_log.entry_to_display = None

            work_log.menu()

        elif work_log.action == 'create':

            work_log.create_new_entry()