def test_is_an_employee_listed_twice_for_a_shift(self): """This test checks if any employee is listed twice in the same shift""" run() for shift in self.all_shifts: self.assertEqual(len(shift.assigned_employees), len(list(set(shift.assigned_employees))))
def test_protools_limits_are_working(self): self.all_employees[0].employee_limits.append('Sunday Morning') run() self.assertNotEqual(str(all_shifts[1].assigned_names), str(['emp1'])) self.assertEqual(str(all_shifts[1].assigned_names), str(['PlaceHolder']))
def test_with_no_employees(self): """tests how the code behaves when there are not enough employees""" self.all_employees.clear() run() for shift in all_shifts: self.assertEqual(shift.assigned_employees, []) self.assertEqual(shift.assigned_names, [])
def test_did_any_employee_not_get_any_shifts(self): """This test will cycle through all the employees and make sure that each employee was assigned to at least 1 shift""" run() for employee in self.all_employees: if employee.name != 'PlaceHolder': if employee.contract_shift_amount > 0: self.assertGreater(len(employee.scheduled_shifts), 0)
def test_that_all_shifts_that_require_employees_have_assigned_employees( self): """This test will verify that each shift has assigned employees""" run() for shift in self.all_shifts: if shift.required_employees > 0: # print(shift.day_name, shift.shift_name, shift.required_employees, len(shift.assigned_employees), shift.assigned_names) self.assertGreater(len(shift.assigned_employees), 0)
def test_assign_supervisor(self): """This test will make sure that the employee assigned to a supervisor shift is indeed a supervisor""" self.supervisors = [['Supervisor1'], ['Supervisor2']] run() for shift in self.all_shifts: if shift.shift_name == 'Super Morning' or shift.shift_name == 'Super Evening': if shift.required_employees > 0: self.assertIn(shift.assigned_names, self.supervisors)
def test_is_employee_qualified_for_protools_shift(self): """This test will check whether or not the employee that was assigned is in the list of qualified employees for a protools shift """ run() for shift in self.all_shifts: if shift.shift_name == 'Protools': for employee in shift.assigned_employees: if employee.name != 'PlaceHolder': self.assertTrue(employee.is_protools_authorized)
def test_save_to_excel_with_employee_limit(self): self.all_employees[0].employee_limits.append('Sunday Morning') run() save_schedule_as_excel() self.workbook = xlrd.open_workbook('test.xls') self.worksheet = self.workbook.sheet_by_name('Sheet 1') self.cell_to_check1 = self.worksheet.cell_value(1, 1) self.assertEqual(self.cell_to_check1, str(['PlaceHolder']))
def test_a_shift_change_expected_result_and_test_again(self): """This test adds another employee to the list day1shift1.assigned_employees and then checks if the amount is correct - raising an AssertionError""" run() self.all_shifts[0].assigned_employees.append('1 too many') try: self.assertEqual(len(self.all_shifts[0].assigned_employees), 2) except AssertionError: pass
def test_check_wrongful_assignment(self): """This test will assign an employee against his limits and then check if the function check_wrongful_assignment caught it""" self.all_employees[6].employee_limits.append('Sunday Morning') self.all_shifts[0].assigned_employees.append(self.all_employees[6]) self.all_shifts[0].assigned_names.append(self.all_employees[6].name) run() check_wrongful_assignment() self.assertIn('PlaceHolder', self.all_shifts[0].assigned_names)
def test_that_all_shifts_have_assigned_employees_change_outcome_and_test_again( self): """This test removes all employees from day1shift1 and then verify that the shift has employees agssigned to it - raising an AssertionError""" run() self.all_shifts[0].assigned_employees.clear() try: self.assertGreater(len(self.all_shifts[0].assigned_employees), 0) except AssertionError: print('Goodness') pass
def test_save_to_excel(self): """How do i test for this??""" run() save_schedule_as_excel() self.workbook = xlrd.open_workbook('test.xls') self.worksheet = self.workbook.sheet_by_name('Sheet 1') self.cell_to_check1 = self.worksheet.cell_value(0, 0) self.cell_to_check2 = self.worksheet.cell_value(2, 1) self.cell_to_check3 = self.worksheet.cell_value(9, 1) self.assertEqual(str(self.cell_to_check1), str('SundayMorning')) self.assertEqual(str(self.cell_to_check2), str('[]')) self.assertEqual(str(self.cell_to_check3), str(['emp1']))
def test_assign_supervisor_change_outcome_test_again(self): """This test will make sure that the employee assigned to a supervisor shift is indeed a supervisor""" self.supervisors = [['Supervisor1'], ['Supervisor2']] run() self.all_shifts[6].assigned_employees.clear() self.all_shifts[6].assigned_names.clear() self.all_shifts[6].assigned_employees.append(all_employees[0]) self.all_shifts[6].assigned_names.append(all_employees[0].name) show_schedule() for shift in self.all_shifts: if shift.shift_name == 'Super Morning' or shift.shift_name == 'Super Evening': if shift.required_employees > 0: try: self.assertIn(shift.assigned_names, self.supervisors) except AssertionError: pass
def test_is_an_employee_listed_twice_change_outcome_and_test_again(self): """This test adds an employee twice to the same shift and then tests again, raising an assertion error""" run() self.all_shifts[0].assigned_names.append( self.all_shifts[0].assigned_names[0]) self.all_shifts[0].assigned_employees.append( self.all_shifts[0].assigned_employees[0]) show_schedule() try: self.assertEqual(len(self.all_shifts[0].assigned_names), len(list(set(self.all_shifts[0].assigned_names)))) self.assertEqual( len(self.all_shifts[0].assigned_employees), len(list(set(self.all_shifts[0].assigned_employees)))) except AssertionError: print('Passed') pass
def test_shift_is_correct_employee_amount(self): """This test checks if the function assign_employees() outputs the correct amount of employees for one specific shift""" run() self.assertEqual(len(all_shifts[0].assigned_employees), 2)