示例#1
0
    def update_employee(self):
        """
        this method is used to update employee details.
        """
        cursor = self.conn.show_members()
        emp_id = self.show_table_menu(cursor)
        if emp_id is None:
            return
        columns = self.conn.worker_table_fields()
        print("choose attribute :\n")
        menu = Menu()
        columns.extend([str(BackButton.BACK.name), str(BackButton.EXIT.name)])
        column = menu.draw_menu(columns)
        input()
        user_input = ''
        if column == str(BackButton.BACK.name):
            return
        elif column == str(MemberUpdateColumns.password.name):
            user_input = encrypt_pass(input_validation("enter new value: ", Validation.password, 'Weak password'))
        elif column == str(MemberUpdateColumns.email.name):
            user_input = input_validation("enter new value: ", Validation.is_email, 'Invalid Email')
        elif column == str(MemberUpdateColumns.phone_number.name) and not Validation.is_phone(user_input):
            user_input = input_validation("enter new value: ", Validation.is_phone, "Invalid Phone Number")
        else:
            user_input = input("enter new value: ")
        try:
            self.conn.update_member(emp_id, column, user_input)
            self.conn.commit_data()
            print(Color.F_Red, 'Record Updated', Base.END)

        except sqlite3.IntegrityError:
            print(Color.F_Red, 'user_name already taken', Base.END)
        except Exception:
            print(Color.F_Red, 'some internal error occurred', Base.END)
示例#2
0
 def test_is_phone(self):
     inputs = ['4534342312', '200', 'invalid_number', '123123qw12']
     self.assertEqual(True, Validation.is_phone(inputs[0]))
     self.assertEqual(False, Validation.is_phone(inputs[1]))
     self.assertEqual(False, Validation.is_phone(inputs[2]))
     self.assertEqual(False, Validation.is_phone(inputs[3]))