Ejemplo n.º 1
0
def search_choice(user_choice):
    """Launch search method based on user's choice"""
    while True:
        try:
            if user_choice.upper() == "A":
                date_search()
            elif user_choice.upper() == "B":
                date_counter()
            elif user_choice.upper() == "C":
                time_search()
            elif user_choice.upper() == "D":
                exact_search()
            elif user_choice.upper() == "E":
                pattern_search()
            elif user_choice.upper() == "F":
                work_log.main_menu()
            elif user_choice.upper() == "G":
                utils.quit_program()
            else:
                raise ValueError
        except ValueError:
            logger.warning("Exception. User typed {} for a search method."
                           .format(user_choice))
            print("\nYou entered an invalid option")
        repeat = input("Press 'any key' to try again or type QUIT to leave: ")
        if repeat.upper() == "QUIT":
            utils.clear_screen()
            utils.quit_program()
        else:
            utils.clear_screen()
            search_options()
        logger.info("User selected {} to fix search error.".format(repeat))
Ejemplo n.º 2
0
def delete_row(row_to_del):
    """Deletes a row from the csv log based on user's request"""
    filename = "tasklogs.csv"
    temp_file = "task_temp.csv"
    with open(filename) as csvin, open(temp_file, "w") as csvout:
        reader = csv.DictReader(csvin)
        fieldnames = ["Task Name", "Task Date", "Task Date UTC",
                      "Task Time", "Task Note", "Task Timestamp"]
        writer = csv.DictWriter(csvout, fieldnames=fieldnames)
        writer.writeheader()
        for row in reader:
            if row == row_to_del:
                break
            else:
                writer.writerow(row)
        writer.writerows(reader)
    os.remove(filename)
    os.rename(temp_file, filename)
    utils.clear_screen()
    print("=========  Log Has Been Deleted  =========\n\n")
    print("[M]ain Menu [A]dd log [S]earch log [Q]uit program\n")
    get_choice = input("Choose an option: ")
    if get_choice.upper() == "M":
        work_log.main_menu()
    elif get_choice.upper() == "A":
        add_task.Task()
    elif get_choice.upper() == "S":
        search_options()
    elif get_choice.upper() == "Q":
        utils.quit_program()
Ejemplo n.º 3
0
    def add_entry(self):
        """Add the entry to task.csv."""
        fieldnames = [
            'task_id', 'task_date', 'task_name', 'task_time', 'task_notes'
        ]

        file_exists = os.path.isfile('tasks.csv')
        # check whether file exists
        # ref: https://tinyurl.com/y67yexqj

        with open('tasks.csv', 'a') as csvfile:
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            if not file_exists:
                writer.writeheader()
            writer.writerow({
                'task_id': uuid.uuid1(),
                'task_date': self.date,
                'task_name': self.name,
                'task_time': self.time,
                'task_notes': self.notes
            })
        self.print_output()
        input("The above entry has been added. "
              "Press ENTER to return to the main menu.")
        from work_log import main_menu
        main_menu()
Ejemplo n.º 4
0
    def test_main_menu(self):
        """Adds a test entry + tests all Value Errors"""
        self.assertEqual(log.main_menu(input_menue='a', access=False),
                         'test_successful')
        self.assertEqual(log.main_menu(input_menue='c', access=False),
                         'test_successful')

        log.add_entry(self.employee_name,
                      self.raw_date,
                      self.task,
                      self.time,
                      self.notes,
                      decision='Y',
                      access=False)

        self.assertEqual(log.main_menu(input_menue='b', access=False),
                         'test_successful')

        with self.assertRaises(ValueError):
            log.main_menu(input_menue='b', entry=False, access=False)

        for value in self.search_solution:
            value.delete_instance()

        with self.assertRaises(ValueError):
            log.main_menu(input_menue='e', access=False)
Ejemplo n.º 5
0
def success_search(result):
    """Shows all worklogs found & gives user ability to scroll through them"""
    utils.clear_screen()
    total_results = len(result)
    display_result(result[0])
    index = 0

    while True:
        try:
            # Show worklog results found in the format 1 of 2.
            if 0 <= index <= (total_results-1):
                position_index = index + 1
            elif index > total_results:
                position_index = total_results
            print("Result {} of {}".format(position_index, total_results))

            # Take user input to scroll through tasks or leave view
            choice = input("\n[N]ext [P]revious [E]dit [D]elete [M]ain Menu: ")
            if choice.upper() == "N":
                try:
                    utils.clear_screen()
                    index += 1
                    display_result(result[index])
                except IndexError:
                    print("There are no more worklogs to view.")
            elif choice.upper() == "P":
                if index == 0:
                    utils.clear_screen()
                    print("There are no more worklogs to view")
                else:
                    utils.clear_screen()
                    index -= 1
                    display_result(result[index])
            elif choice.upper() == "E":
                edit_log(result[index])
            elif choice.upper() == "D":
                delete_row(result[index])
            elif choice.upper() == "M":
                work_log.main_menu()
            else:
                raise ValueError
        except ValueError:
            utils.clear_screen()
            print("Please enter a valid option")
Ejemplo n.º 6
0
 def test_main_menu(self, mock_input, mock_add, mock_search):
     work_log.main_menu()
     self.assertTrue(mock_add.called)
     work_log.main_menu()
     self.assertTrue(mock_search.called)
     with self.assertRaises(SystemExit):
         work_log.main_menu()
Ejemplo n.º 7
0
def footer_menu():
    """Displays the footer menu"""
    print("Choose An Option Below\n")
    while True:
        try:
            wrap_up = input("[M]ain Menu, [A]dd log, [S]earch logs, [Q]uit: ")
            if wrap_up.upper() == "M":
                work_log.main_menu()
            elif wrap_up.upper() == "A":
                add_task.Task()
            elif wrap_up.upper() == "S":
                find_task.search_options()
            elif wrap_up.upper() == "Q":
                clear_screen()
                quit_program()
            else:
                raise ValueError
        except ValueError:
            clear_screen()
            print("\n***PLEASE ENTER A VALID OPTION***\n")
        else:
            clear_screen()
            break
Ejemplo n.º 8
0
 def test_menu_search(self, search_entry_mock):
     with patch('builtins.input', side_effect='q'):
         work_log.main_menu()
     search_entry_mock.called_with('s')
Ejemplo n.º 9
0
 def test_menu_add(self, add_entry_mock):
     with patch('builtins.input', side_effect='q'):
         work_log.main_menu()
     add_entry_mock.called_with('a')
Ejemplo n.º 10
0
 def test_menu_invalid(self, main_mock):
     with patch('builtins.input', return_value='x', side_effect='q'):
         work_log.main_menu()
     main_mock.called_once()
Ejemplo n.º 11
0
 def test_menu_quit(self, main_mock):
     with patch('builtins.input', return_value='q'):
         work_log.main_menu()
     main_mock.called_once()