Пример #1
0
 def test_add_entry(self, mock_input, mock_main_menu):
     with test_database(test_db, [Entry]):
         work_log.add_entry()
         entry = Entry.get(Entry.id == 1)
         count = Entry.select().where((Entry.name == 'Redha Achour')
                                      & (Entry.title == 'Python')).count()
         self.assertEqual(entry.name, 'Redha Achour')
         self.assertFalse(entry.notes)
         self.assertTrue(entry.title)
         self.assertEqual(count, 1)
         self.assertTrue(mock_main_menu.called)
Пример #2
0
def search_exact():
    """Search database by an exact keyword"""
    search = input("Please select desired keyword: ")
    entries = Entry.select()

    results = []
    for entry in entries:
        if search.lower() in entry.task.lower():
            result = entry
            results.append(entry)
        elif search.lower() in entry.note.lower():
            result = entry
            results.append(entry)
        elif search.lower() != entry.task.lower() and results == []:
            result = None
        elif search.lower() != entry.note.lower() and results == []:
            result = None

    if result:
        print_entries(results)
    else:
        print(
            display.red_err("\nSorry, no keyword found. Please try again.\n"))

    return None
Пример #3
0
def search_employee():
    """Search database by employee name"""
    search = input("Please type desired employee: ")
    entries = Entry.select()

    results = []
    for entry in entries:
        if search == entry.user:
            result = entry
            results.append(entry)
        elif search != entry.user and results == []:
            result = None

    if result:
        list_entries(results)
    else:
        print(display.red_err("\nSorry, no match found. Please try again.\n"))

    return None
Пример #4
0
def search_time():
    """Search database by time in minutes"""
    search = input("Please select task time in minutes: ")
    entries = Entry.select()

    results = []
    for entry in entries:
        if str(search) == str(entry.time):
            result = entry
            results.append(entry)
        elif search != entry.time and results == []:
            result = None

    if result:
        print_entries(results)
    else:
        print(display.red_err("\nSorry, no match found. Please try again.\n"))

    return None
Пример #5
0
def search_date():
    """Search database by date"""
    search = input("\nPlease select desired date using YYYY-MM-DD format: ")
    search = (search + ' 00:00:00')
    entries = Entry.select()
    results = []

    for entry in entries:
        if str(search) == str(entry.date):
            result = entry
            results.append(entry)
        elif search != entry.date and results == []:
            result = None

    if result:
        list_entries(results)
    else:
        print(display.red_err("\nSorry, date not found. Please try again."))

    return None
Пример #6
0
 def test_edit_notes(self, mock_input):
     with test_database(test_db, [Entry]):
         self.create_entry()
         entry = Entry.get(Entry.id == 1)
         work_log.edit(entry)
         self.assertEqual(entry.notes, 'using peewee')
Пример #7
0
 def test_edit_date(self, mock_input):
     with test_database(test_db, [Entry]):
         self.create_entry()
         entry = Entry.get(Entry.id == 1)
         work_log.edit(entry)
         self.assertEqual(entry.date, '2017-12-10')
Пример #8
0
 def test_display(self, mock_input, mock_edit, mock_search_menu):
     with test_database(test_db, [Entry]):
         self.create_entry()
         work_log.display(Entry.select())
         self.assertTrue(mock_edit.called)
         self.assertTrue(mock_search_menu.called)
Пример #9
0
 def create_entry(self):
     Entry.create(name='Redha Achour',
                  title='Project 4',
                  date='2017-12-17',
                  time='45',
                  notes='work log using database')
Пример #10
0
 def test_obtain_notes(self):
     with patch("builtins.input", return_value='This is a lot of fun!'):
         assert Entry().obtain_notes() == 'This is a lot of fun!'
Пример #11
0
 def test_obtain_task_time(self):
     with patch("builtins.input", return_value=30):
         assert Entry().obtain_task_time() == 30
Пример #12
0
 def test_obtain_task_name(self):
     with patch("builtins.input", return_value='Python'):
         assert Entry().obtain_task_name() == 'Python'
Пример #13
0
 def test_obtain_user_name(self):
     with patch("builtins.input", return_value='Taylor'):
         assert Entry().obtain_user_name() == 'Taylor'