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)
def test_add_entry_ui(self): """Test add_entry in work_log.py - the ui""" # Testing add entry but not saving input_args = [ self.employee_name, # enter employee name '2019/3/20', # enter date self.task_name, # enter task name self.time_spent, # enter time spent self.optional_notes, # enter optional notes 'q', # invalid choice for save entry [Yn] '', # enter to continue 'n', # not saving entry '', # enter to continue ] with patch('builtins.input', side_effect=input_args) as mock: result = work_log.add_entry() # Assert that result equals {} self.assertEqual(result, {}) input_args = [ self.employee_name, # enter employee name '2019/3/20', # enter date self.task_name, # enter task name self.time_spent, # enter time spent self.optional_notes, # enter optional notes 'y', # to save '', # enter to continue ] with patch('builtins.input', side_effect=input_args) as mock: result = work_log.add_entry() self.assertEqual(result, self.log_entry)
def test_add_entry(self): work_log.add_entry(employee="Dave", name="Task", time=26, notes="Lots of notes") entry = work_log.Database(employee="Dave", time=26) self.assertEqual(entry.employee, "Dave")
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 test_add_entry(self): with unittest.mock.patch('builtins.input', side_effect=[ "2012-12-12", "Name", "Cleaning", 45, "Very Clean", "y", "" ], return_value=TEST): assert work_log.add_entry()["task_name"] == TEST["task_name"] with unittest.mock.patch('builtins.input', side_effect=[ "2018-12-23", "Name", "Cleaning", 45, "Very Clean", "n", "" ], return_value=TEST): assert work_log.add_entry() == None
def menu(): database.init_db() while True: clear() print('WORK LOG') print('What whould you like to do?') while True: answer = input(('1: Add new entry\n' '2: Search in existing entries\n' '3: Quit Program\n')) if answer in '123': break else: clear() print( f'Option {answer} is not in the menu. Please choose again.' ) continue clear() if answer == '1': input(work_log.add_entry()) if answer == '2': search_option = work_log.search_entries() if search_option == '1': work_log.display_entries(work_log.find_by_employee()) if search_option == '2': work_log.display_entries(work_log.find_by_date()) if search_option == '3': work_log.display_entries(work_log.find_by_time_spent()) if search_option == '4': work_log.display_entries(work_log.find_by_search_term()) if answer == '3': print('Thank you for using work log.') input() break
def test_not_valid_time_add_entry(self): inputs_to_pass = ['Job1', 'Daniel', 'not integer', 60, 'This is a test', 'n'] with patch('builtins.input', side_effect=inputs_to_pass): with patch('builtins.print', side_effect=print) as mock: result = work_log.add_entry() mock.assert_called_once_with( '\nValue must be a number. Please try again.')
def test_add_entry(self): with unittest.mock.patch('builtins.input', side_effect=[ "test name", "eating", "2016-11-06", 50, "nom nom nom", "y", "" ], return_value=TEST): assert work_log.add_entry()["name"] == TEST["name"]
def test_result_menue(self): """Adds a test entry and tests agains various inputs""" log.add_entry(self.employee_name, self.raw_date, self.task, self.time, self.notes, decision='Y', access=False) self.assertEqual( log.result_menue(self.search_solution, user_input='N', access=False), 'test_successful') self.assertEqual( log.result_menue(self.search_solution, user_input='N', page_count=True, access=False), 'test_successful') self.assertEqual( log.result_menue(self.search_solution, user_input='E', access=False), 'test_successful') self.assertEqual( log.result_menue(self.search_solution, user_input='D', user_input_2='Y', access=False), 'test_successful') self.assertEqual( log.result_menue(self.search_solution, user_input='D', user_input_2='N', access=False), 'test_successful') self.assertEqual( log.result_menue(self.search_solution, user_input='R', access=False), 'test_successful') self.assertEqual( log.result_menue(self.search_solution, user_input='G', access=False), 'test_successful') for value in self.search_solution: value.delete_instance()
def setUp(self): tst_db.bind([Entry], bind_refs=False, bind_backrefs=False) tst_db.connect() tst_db.create_tables([Entry]) work_log.add_entry('Ben', 'Task 1', '10', 'This is a generic note', '2012-01-21') work_log.add_entry('Drew', 'Task 2', '30', '', '2012-05-06') work_log.add_entry('Daniel', '3rd Task', '60', 'What a really cool and awesome note this is', '1999-05-30') work_log.add_entry('Sally', 'another task', '60', '', '1999-05-30')
def test_add_entry_success(self): user_input = [ # correct 'Miro 10', # correct 'task-10', # incorrect 'not allowed', # correct '500', # correct 'notes-10' ] with patch('builtins.input', side_effect=user_input): success = work_log.add_entry() self.assertEqual(success, 'Entry successfully added to the database') entries = database.search_by_name('Miro 10') for e in entries: self.assertEqual(e.name, 'Miro 10') self.assertEqual(e.task, 'task-10') self.assertEqual(e.time, 500) self.assertEqual(e.notes, 'notes-10')
def test_get_unique_dates(self): from work_log import get_unique_dates, add_entry test_entry = add_entry('Test Name', 'Test Title', '2', 'Test Notes') unique_dates = get_unique_dates() self.assertTrue(unique_dates) test_entry.delete_instance()
def test_valid_add_entry(self): inputs_to_pass = ['Job1', 'Daniel', 60, 'This is a test', 'y'] with patch('builtins.input', side_effect=inputs_to_pass): with patch('builtins.print', side_effect=print) as mock: result = work_log.add_entry() mock.assert_called_once_with('\nEntry saved successfully!')
def test_add(self, name_mock, task_mock, time_mock): with patch('builtins.input', return_value='unittest notes3'): work_log.add_entry() name_mock.called_with('name') task_mock.called_with('task') time_mock.called_with('time')
def test_search_entry(self): """Adds a test entry + tests all Value Errors""" log.add_entry(self.employee_name, self.raw_date, self.task, self.time, self.notes, decision='Y', access=False) self.assertEqual([ value.date for value in log.search_entry( input_search='a', raw_date_input=self.raw_date, access=False) ], [value.date for value in self.search_entry_date_solution]) self.assertEqual([ value.date for value in log.search_entry(input_search='b', raw_date1_input="11/12/2019", raw_date2_input="13/12/2019", access=False) ], [value.date for value in self.search_entry_date_solution]) self.assertEqual([ value.time for value in log.search_entry( input_search='c', input_user=self.time, access=False) ], [self.time]) self.assertEqual([ value.notes for value in log.search_entry( input_search='d', input_user=self.notes, access=False) ], [self.notes]) self.assertEqual([ value.employee_name for value in log.search_entry( input_search='e', input_user=self.employee_name, access=False) ], [self.employee_name]) for value in self.search_solution: value.delete_instance() self.assertEqual(log.search_entry(input_search='h', access=False), 'test_successful') with self.assertRaises(ValueError): log.search_entry(input_search='a', raw_date_input='32/02/2019', access=False) with self.assertRaises(ValueError): log.search_entry(input_search='a', raw_date_input='32/02/2019', user_input_2='R', access=False) with self.assertRaises(ValueError): log.search_entry(input_search='b', raw_date1_input="35-11-2019", raw_date2_input="36-12-2019", access=False) with self.assertRaises(ValueError): log.search_entry(input_search='b', raw_date1_input="35-11-2019", raw_date2_input="36-12-2019", user_input_2='R', access=False) with self.assertRaises(ValueError): log.search_entry(input_search='b', raw_date1_input="11/12/2019", raw_date2_input="36-12-2019", access=False) with self.assertRaises(ValueError): log.search_entry(input_search='b', raw_date1_input="11/12/2019", raw_date2_input="36-12-2019", user_input_2='R', access=False) with self.assertRaises(ValueError): log.search_entry(input_search='c', input_user='******', access=False) with self.assertRaises(ValueError): log.search_entry(input_search='d', input_user=None, access=False) with self.assertRaises(ValueError): log.search_entry(input_search='e', input_user=None, access=False)
def test_not_valid_save_add_entry(self): inputs_to_pass = ['Job1', 'Daniel', 60, 'This is a test', 'asdf', 'n'] with patch('builtins.input', side_effect=inputs_to_pass): with patch('builtins.print', side_effect=print) as mock: result = work_log.add_entry() mock.assert_called_once_with('\nYou must enter [Yn]')
def test_add_entry(self): from work_log import add_entry test_entry = add_entry('Test Name', 'Test Title', '2', 'Test Notes') self.assertEqual(test_entry.employee_name, 'Test Name') test_entry.delete_instance()
def test_check_for_entries(self): from work_log import check_for_entries, add_entry test_entry = add_entry('Test Name', 'Test Title', '2', 'Test Notes') self.assertTrue(check_for_entries) test_entry.delete_instance()
def test_add_entry(self): """Adds a test entry + tests all Value Errors""" log.add_entry(self.employee_name, self.raw_date, self.task, self.time, self.notes, decision='Y', access=False) self.assertEqual([value.notes for value in self.search_solution], [self.notes]) for value in self.search_solution: value.delete_instance() self.assertEqual( log.add_entry(self.employee_name, self.raw_date, self.task, self.time, self.notes, decision='N', access=False), 'test_successful') with self.assertRaises(ValueError): log.add_entry(employee_name=self.employee_name, raw_date='45', task=self.task, time=self.time, notes=self.notes, decision='N', access=False) with self.assertRaises(ValueError): log.add_entry(employee_name=None, raw_date=self.raw_date, task=self.task, time=self.time, notes=self.notes, decision='N', access=False) with self.assertRaises(ValueError): log.add_entry(employee_name=self.employee_name, raw_date=self.raw_date, task=None, time=self.time, notes=self.notes, decision='N', access=False) with self.assertRaises(ValueError): log.add_entry(employee_name=self.employee_name, raw_date=self.raw_date, task=self.task, time=-1, notes=self.notes, decision='N', access=False)