def test_view_logs_loop_and_edit_all(self, input): from work_logs_sqlite import view_logs_loop logs = Log.select() view_logs_loop(logs) logs = Log.select() self.assertEqual(logs[0].date, '03/03/3000') self.assertEqual(logs[0].employee_name, 'Gamma') self.assertEqual(logs[0].task_name, 'Task Three') self.assertEqual(logs[0].time_spent, 3) self.assertEqual(logs[0].note, 'Thryee')
def get_distinct_names(search_term=None): """Returns a list of distinct employee names in the db.""" if search_term: query = Log.select(Log.employee_name).distinct().where( Log.employee_name.contains(search_term)).order_by( Log.employee_name) else: query = Log.select(Log.employee_name).distinct().order_by( Log.employee_name) return [log.employee_name for log in query]
def test_main_menu_add_log(self, input): from work_logs_sqlite import main_menu_loop main_menu_loop() logs = Log.select() self.assertEqual(len(logs), 3) self.assertEqual(logs[2].date, '03/03/3000') self.assertEqual(logs[2].employee_name, 'Gamma') self.assertEqual(logs[2].task_name, 'Task Three') self.assertEqual(logs[2].time_spent, 3) self.assertEqual(logs[2].note, 'Thryee')
def find_by_date_range(start, end): """Searches for work logs by dates within a specified range""" start_date = datetime.datetime.strptime(start, '%m/%d/%Y') end_date = datetime.datetime.strptime(end, '%m/%d/%Y') # Create a timedelta with a value of 0 (for the range's minimum) and # calculate a timedelta that represents the maximum value allowed # by the search (end_date - start_date) range_start = datetime.timedelta(0) range_max = end_date - start_date # Return a list of logs that have dates falling within the search # range. logs = Log.select() search_results = [] for log in logs: date = end_date - datetime.datetime.strptime(log.date, "%m/%d/%Y") if date >= range_start and date <= range_max: search_results.append(log) return search_results
def find_by_string(search_term): """Find by search term.""" logs = Log.select() return (logs.where(Log.task_name.contains(search_term)) or logs.where(Log.note.contains(search_term)))
def find_by_time_spent(search_time): """Find by time spent.""" return Log.select().where(Log.time_spent == int(search_time))
def find_by_name(search_term): """Find by name.""" names = get_distinct_names(search_term) print("Matches for search: ") chosen_name = menu(names) return Log.select().where(Log.employee_name == chosen_name)
def find_by_employee(): """Search by a list of employees.""" chosen_name = menu(get_distinct_names()) return Log.select().where(Log.employee_name == chosen_name)
def find_by_date(dates): """Find by date""" chosen_date = menu(dates) return Log.select().where(Log.date == chosen_date)
def get_distinct_dates(): """Returns a list of distinct dates in the db.""" query = Log.select(Log.date).distinct() dates = [log.date for log in query] return sorted(dates, key=sorting)
def test_view_logs_loop_and_edit_note(self, input): from work_logs_sqlite import view_logs_loop logs = Log.select() view_logs_loop(logs) self.assertEqual(Log.select()[0].note, 'Thryee')
def test_view_logs_loop_and_edit_time_spent(self, input): from work_logs_sqlite import view_logs_loop logs = Log.select() view_logs_loop(logs) self.assertEqual(Log.select()[0].time_spent, 3)
def test_view_logs_loop_and_edit_task_name(self, input): from work_logs_sqlite import view_logs_loop logs = Log.select() view_logs_loop(logs) self.assertEqual(Log.select()[0].task_name, 'Task Three')
def test_view_logs_loop_and_edit_employee_name(self, input): from work_logs_sqlite import view_logs_loop logs = Log.select() view_logs_loop(logs) self.assertEqual(Log.select()[0].employee_name, 'Gamma')
def test_view_logs_loop_and_edit_date(self, input): from work_logs_sqlite import view_logs_loop logs = Log.select() view_logs_loop(logs) self.assertEqual(Log.select()[0].date, '03/03/3000')
def test_view_logs_loop_delete_disconfirm(self, input): from work_logs_sqlite import view_logs_loop logs = Log.select() view_logs_loop(logs) assert len(Log.select()) == 2