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)
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
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
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
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
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')
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')
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)
def create_entry(self): Entry.create(name='Redha Achour', title='Project 4', date='2017-12-17', time='45', notes='work log using database')
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!'
def test_obtain_task_time(self): with patch("builtins.input", return_value=30): assert Entry().obtain_task_time() == 30
def test_obtain_task_name(self): with patch("builtins.input", return_value='Python'): assert Entry().obtain_task_name() == 'Python'
def test_obtain_user_name(self): with patch("builtins.input", return_value='Taylor'): assert Entry().obtain_user_name() == 'Taylor'