def test_update_employee_email(self, mock_validation, mock_db, mock_print, mock_input, mock_table_menu, mock_menu): mock_db().worker_table_fields.return_value = [] mock_menu().draw_menu.return_value = 'email' admin = Admin() admin.update_employee() mock_db().update_member.assert_called_once() mock_db().commit_data.assert_called_once()
def test_accident_complains_wip_remove_no_member(self, mock_db, mock_print, mock_input, mock_table_menu, mock_menu, mock_remove_supervisor, mock_add_supervisor): mock_menu().draw_menu.side_effect = ['WIP', 'REMOVE_SUPERVISOR'] mock_table_menu.side_effect = ['', None] admin = Admin() admin.accident_complains() self.assertEqual(2, mock_table_menu.call_count)
def test_remove_supervisor(self, mock_db): mock_db().check_supervisor_accident.return_value = False admin = Admin() admin.remove_supervisor(1, 1) mock_db().remove_supervisor_accident.assert_called_once() mock_db().check_supervisor_accident.assert_called_once() mock_db().remove_supervisor_role.assert_called_once()
def test_show_table_menu_inout_out_of_index(self, mock_input, mock_raw_table): cursor = MockCursor() admin = Admin() mock_input.return_value = '2' result = admin.show_table_menu(cursor, [1], [2]) self.assertEqual(None, result) mock_raw_table.assert_called_once()
def test_accident_complains_wip_remove(self, mock_db, mock_print, mock_input, mock_table_menu, mock_menu, mock_remove_supervisor, mock_add_supervisor): mock_menu().draw_menu.side_effect = ['WIP', 'REMOVE_SUPERVISOR'] mock_table_menu.side_effect = ['', 'None'] admin = Admin() admin.accident_complains() mock_remove_supervisor.assert_called_once()
def test_accident_complains_back(self, mock_db, mock_print, mock_input, mock_table_menu, mock_menu, mock_remove_supervisor, mock_add_supervisor): mock_menu().draw_menu.return_value = 'BACK' admin = Admin() admin.accident_complains() mock_input.assert_called_once() mock_menu().draw_menu.assert_called_once()
def test_manage_supervisor_reports_resolved(self, mock_choose_employee, mock_show_table, mock_menu, mock_raw_table, mock_db, mock_print, mock_input): mock_menu().draw_menu.return_value = 'RESOLVED' admin = Admin() admin.manage_supervisor_reports() mock_menu().draw_menu.assert_called_once() mock_raw_table.assert_called_once()
def test_delete_employee_exception(self, mock_print, mock_table_menu, mock_db): mock_db().commit_data.side_effect = Exception admin = Admin() admin.delete_employee() mock_db().delete_member.assert_called_once() mock_db().delete_user_all_roles.assert_called_once() mock_db().rollback_data.assert_called_once()
def test_update_employee_back_button(self, mock_db, mock_print, mock_input, mock_table_menu, mock_menu): mock_db().worker_table_fields.return_value = [] mock_menu().draw_menu.return_value = 'BACK' admin = Admin() admin.update_employee() mock_print.assert_called_once() mock_input.assert_called_once()
def test_create_employee_exception(self, mock_validation, mock_db, mock_print, mock_input): mock_db().commit_data.side_effect = Exception admin = Admin() admin.create_employee() self.assertEqual(1, mock_print.call_count) self.assertEqual(1, mock_db().create_employee.call_count) mock_db().rollback_data.assert_called_once()
def test_update_employee_sqlite_exception(self, mock_validation, mock_db, mock_print, mock_input, mock_table_menu, mock_menu): mock_db().worker_table_fields.return_value = [] mock_menu().draw_menu.return_value = 'email' mock_db().commit_data.side_effect = sqlite3.IntegrityError admin = Admin() admin.update_employee() mock_db().update_member.assert_called_once()
def test_manage_supervisor_reports_wip_no_accident(self, mock_choose_employee, mock_show_table, mock_menu, mock_raw_table, mock_db, mock_print, mock_input): mock_menu().draw_menu.return_value = 'WIP' mock_show_table.return_value = None admin = Admin() admin.manage_supervisor_reports() mock_menu().draw_menu.assert_called_once() mock_db().show_status_accident_report.assert_called_once()
def test_manage_supervisor_reports_wip(self, mock_choose_employee, mock_show_table, mock_menu, mock_raw_table, mock_db, mock_print, mock_input): mock_menu().draw_menu.return_value = 'WIP' mock_choose_employee.return_value = ['1', '2'] admin = Admin() admin.manage_supervisor_reports() mock_menu().draw_menu.assert_called_once() mock_db().commit_data.assert_called_once() mock_db().insert_finalize_report.assert_called_once() mock_db().close_accident_cases.assert_called_once()
def test_admin_features(self, mock_print, mock_menu, mock_os, mock_input, mock_getattr, accident_complains): admin = Admin() mock_getattr.side_effect = [accident_complains, SystemExit] self.assertRaises(SystemExit, admin.admin_features) self.assertEqual(mock_menu().draw_menu.call_count, 2) self.assertEqual(mock_getattr.call_count, 2) self.assertEqual(mock_input.call_count, 3) mock_os.system.assert_any_call('clear') mock_print.assert_any_call("choose feature :\n")
def show_accident_complain(self): """ this method is used to show supervisor accident complain. """ cursor = self.conn.show_supervisor_accidents(self.supervisor_id) admin = Admin() temp_dict = dict() print('choose accident to send report') temp_dict['accident_id'] = admin.show_table_menu(cursor) if temp_dict['accident_id'] is None: return cursor = self.conn.show_members() print('choose eye witness') temp_dict['eye_witness'] = admin.show_table_menu(cursor) print('choose victims') victims = admin.choose_multiple_employee() print('choose culprit') temp_dict['victims'] = '' temp_dict['culprit'] = '' culprit = admin.choose_multiple_employee() if culprit != [] and culprit != None: temp_dict['culprit'] = ','.join(culprit) if victims != [] and victims != None: temp_dict['victims'] = ','.join(victims) temp_dict['submitted_by'] = self.supervisor_id temp_dict['reason'] = input('enter reason ') temp_dict['timing'] = input('enter accident timing ') temp_dict['submission_time'] = d.datetime.now() temp_dict['location'] = input('enter location of accident ') temp_dict['action_to_resolve'] = input('enter action to resolve ' ) try: self.conn.register_supervisor_report(temp_dict) self.conn.commit_data() print('report submitted successfully.') except Exception as e: print('some error occured') print(e) self.conn.rollback_data()
def test_update_employee_no_emp(self, mock_db, mock_table_menu): mock_table_menu.return_value = None admin = Admin() admin.update_employee() mock_table_menu.assert_called_once()
def test_remove_supervisor_exception(self, mock_db): mock_db().remove_supervisor_accident.side_effect = Exception admin = Admin() admin.remove_supervisor(1, 1) mock_db().remove_supervisor_accident.assert_called_once() mock_db().rollback_data.assert_called_once()
def test_delete_employee(self, mock_print, mock_table_menu, mock_db): admin = Admin() admin.delete_employee() mock_db().delete_member.assert_called_once() mock_db().delete_user_all_roles.assert_called_once() mock_db().commit_data.assert_called_once()
def test_create_employee(self, mock_validation, mock_db, mock_print, mock_input): mock_db().commit_data.side_effect = [sqlite3.IntegrityError, ''] admin = Admin() admin.create_employee() self.assertEqual(2, mock_print.call_count) self.assertEqual(2, mock_db().create_employee.call_count)
def test_choose_multiple_employee_exception(self, mock_input, mock_raw_table, mock_db): mock_db().show_members().fetchall.return_value = [[1, 2, 3]] mock_input.return_value = 'asd,1,2' admin = Admin() result = admin.choose_multiple_employee() self.assertEqual(result, None)
def test_delete_employee_no_emp(self, mock_print, mock_table_menu, mock_db): mock_table_menu.return_value = None admin = Admin() admin.delete_employee() mock_db().show_members.assert_called_once() mock_table_menu.assert_called_once()
def test_choose_multiple_employee(self, mock_input, mock_raw_table, mock_db): mock_db().show_members().fetchall.return_value = [[1, 2, 3]] mock_input.return_value = '0,1,2' admin = Admin() result = admin.choose_multiple_employee() assert result, [1]
def test_show_final_reports(self, mock_db, mock_print_table): mock_db().show_final_reports().fetchall.return_value = [[1, 2, 3, '4', 5, '6']] admin = Admin() admin.show_final_reports() mock_print_table.assert_called_once() mock_db().show_final_reports.assert_called_once
def test_admin_features_exception(self, mock_print, mock_menu, mock_sys): admin = Admin() admin.admin_features() mock_sys.exit.assert_called_once() self.assertEqual(mock_print.call_count, 2)
def test_add_supervisor_third_exception(self, mock_db): mock_db().change_accident_to_wip.side_effect = Exception admin = Admin() admin.add_supervisor(1, 1) mock_db().rollback_data.assert_called_once()
def test_add_supervisor_second_exception(self, mock_db): mock_db().commit_data.side_effect = ['', '', sqlite3.IntegrityError] admin = Admin() admin.add_supervisor(1, 1) self.assertEqual(3, mock_db().commit_data.call_count)
def test_add_supervisor(self, mock_db): admin = Admin() admin.add_supervisor(1, 1) self.assertEqual(3, mock_db().commit_data.call_count)
def main(): """ this method is used to call main menu for login """ conn = ConnectDb() try: os.system('clear') # select role for login print("login as:\n") menu = Menu() roles = [x.name for x in Role] roles.extend([str(BackButton.EXIT.name)]) role = menu.draw_menu(roles) role_id = Role[role].value input() # get user name and password for login user_name = input("enter user name: ") password = getpass() # check user authentication result = conn.get_user_info(user_name) flag = True auth_flag = True if result is not None: os.system('clear') actual_pass = decrypt_pass(result[1].encode()) if actual_pass == password: flag = False if role_id == int(Role.EMPLOYEE.value): auth_flag = False emp = Employee() emp.employee_id = result[0] emp.employee_features() else: user_role = conn.get_user_role(result[0], role_id) if user_role is not None: auth_flag = False if role_id == int(Role.SUPERVISOR.value): pass supervisor = Supervisor() supervisor.supervisor_id = result[0] supervisor.supervisor_features() elif role_id == int(Role.ADMIN.value): pass member = Admin() member.admin_id = result[0] member.admin_features() if flag: print(Color.F_Red + 'wrong credentials' + Base.END) input() main() if auth_flag: print(Color.F_Red + 'you are not authorized' + Base.END) input() main() except Exception as e: print(e) sys.exit() finally: conn.close_conn()