Beispiel #1
0
 def test_validate_employee_name(self):
     with patch('builtins.input', side_effect=["Test Employee"]):
         expected_name = "Test Employee"
         fake_list = []
         result = validate_employee_name("Not In Database", fake_list)
         self.assertEqual(expected_name, result)
         test = Employee.get(Employee.name == result)
         test.delete_instance()
def get_employee():
    """Gets employee name for purpose of creating time entry.

    Asks user for employee name, determines whether name already exists,
    returns employee name as a string.
    """

    employee_name = input("Employee Name \n" +
                          "Please enter employee's name: ").strip()
    try:
        employee = Employee.create(name=employee_name)
    except IntegrityError:
        employee = Employee.get(Employee.name == employee_name)

    return employee
def validate_employee_name(employee_name, matching_names):
    """Confirms that employee name has entries associated with it.

    Takes employee name as input and either returns the employee name or
    informs user that the requested employee is not recognized.
    """
    matching_names = matching_names
    employee_name.strip()
    while True:
        try:
            employee = Employee.get(Employee.name == employee_name)
            break
        except DoesNotExist:
            clear_screen()
            print("The name you entered is not recognized.")
            for employee in matching_names:
                print("\t {}".format(employee.name))
            employee_name = input("Please re-enter the name of the person " +
                                  "whose entries you would like to view. > ")
            employee_name.strip()
    return employee_name
def run_options_loop(matching_entries):
    """Allows user to view and perform operations on matching entries.

    matching_entries and non_matching_entries are lists of time entry objects.
    """

    total_results = len(matching_entries)
    count = 0
    while True:
        display_sr(matching_entries, count, total_results)
        option = input("> ")
        if option.upper() == "N":
            try:
                count += 1
                matching_entries[count]
            except IndexError:
                count -= 1
                clear_screen()
            clear_screen()
        elif option.upper() == "P":
            count -= 1
            if count < 0:
                count += 1
            clear_screen()
        elif option.upper() == "E":
            clear_screen()
            while True:
                print("What field would you like to edit?")
                print("Please type \"date\", \"title\", \"time spent\", or " +
                      "\"notes\".")
                print("")
                edit_selection = input("> ")
                clear_screen()
                edit_selection.lower().strip()
                if edit_selection == "date":
                    print("Enter a new date.")
                    print("Please use DD/MM/YYYY format.")
                    new_date = input("> ").strip()
                    new_date = validate_date(new_date)
                    matching_entries[count].date = new_date
                    matching_entries[count].save()
                    clear_screen()
                    print("New Date Saved!")
                    dummy = input("Press Enter to Continue.")
                    clear_screen()
                    break
                elif edit_selection == "title":
                    new_title = input("Enter a new title. > ").strip()
                    matching_entries[count].title = new_title
                    matching_entries[count].save()
                    clear_screen()
                    print("New Title Saved!")
                    dummy = input("Press Enter to Continue.")
                    clear_screen()
                    break
                elif edit_selection == "time spent":
                    new_time_spent = input("Enter new time spent. > ").strip()
                    new_time_spent = validate_time_spent(new_time_spent)
                    matching_entries[count].time_spent = new_time_spent
                    matching_entries[count].save()
                    clear_screen()
                    print("New Amount of Time Saved!")
                    dummy = input("Press Enter to Continue.")
                    clear_screen()
                    break
                elif edit_selection == "notes":
                    new_notes = get_notes()
                    matching_entries[count].notes = new_notes
                    matching_entries[count].save()
                    clear_screen()
                    print("New Notes Saved!")
                    dummy = input("Press Enter to Continue.")
                    clear_screen()
                    break
                else:
                    print("The field you entered is not recognized.")
                    dummy = input("Press enter to try again.")
                    clear_screen()
        elif option.upper() == "D":
            clear_screen()
            print("WARNING: This will delete the selected entry.")
            answer = input("Are you sure you want to proceed (Y/N)? > ")
            if answer.strip().lower() == "y":
                name = matching_entries[count].employee_name.name
                matching_entries[count].delete_instance()
                number_of_entries = remaining_entries(name)
                if number_of_entries == 0:
                    employee = Employee.get(Employee.name == name)
                    employee.delete_instance(recursive=True)
                else:
                    pass
                clear_screen()
                print("Entry Deleted.")
                dummy = input("Press Enter to Continue.")
                clear_screen()
                break
            else:
                print()
            pass
        elif option.upper() == "R":
            break
        else:
            clear_screen()
            print("Command not recognized. \n Please enter N, P, E, D, or R.")
            dummy = input("Press enter to continue viewing search results.")
            clear_screen()