def update_gpm(self): """ this method is used to update gpm for current bdo. """ try: gpm_list = self.get_gpm_list() menu = Menu() gpm_names = [x for x in gpm_list.keys()] gpm_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) gpm_name = menu.draw_menu(gpm_names) input() if str(BackButton.BACK.name) == gpm_name: return gpm_id = gpm_list[gpm_name] print("select the field to update: \n") menu = Menu() details = [x.name for x in GpmUpdateFields] details.extend([str(BackButton.EXIT.name)]) field = menu.draw_menu(details) input() user_input = input("enter new value for " + str(field) + " ") user_table_fields = [1, 2, 3] # validating field if field == str(GpmUpdateFields.PASSWORD.name): if not Validation.password(user_input): print("password is weak") input() return user_input = encrypt_pass(user_input) if field == str(GpmUpdateFields.AGE.name): if not Validation.age(user_input): print("age is not valid") input() return if field == str(GpmUpdateFields.PINCODE.name): if not Validation.pincode(user_input): print("pincode is not valid") input() return if field == str(GpmUpdateFields.GENDER.name): if not Validation.gender(user_input): print("gender is not valid") input() return query = "" # if field belong to user table if user_table_fields.count(GpmUpdateFields[field].value) == 1: self.conn.update_user(str(field), gpm_id, user_input) else: self.conn.update_personal_details(str(field), gpm_id, user_input) self.conn.commit_data() print("\n" + Color.F_Green + "record updated" + Base.END) except Exception as e: print(e) self.conn.rollback_data()
def create_members(self): """ this method is used to create member under current gpm. """ try: name = input("enter member name ") id = str(uuid.uuid4()) password = input("enter password for member ") if not Validation.password(password): print("password is weak") input() return user_name = input("enter user name for member ") role_id = int(Role.Member.value) created_at = datetime.datetime.now().date() updated_at = datetime.datetime.now().date() is_deleted = 'False' state = input("enter state ") district = input("enter district ") pincode = input("enter pincode ") if not Validation.pincode(pincode): print("pincode is not valid") input() return age = input("enter age ") if not Validation.age(age): print("age is not valid") input() return gender = input("enter gender ") if not Validation.gender(gender): print("gender is not valid") input() return created_by = self.gpm_id encrypted_pass = encrypt_pass(password) self.conn.add_user(id, encrypted_pass, user_name, role_id, created_at, updated_at, name, is_deleted) self.conn.add_personal_details(id, state, district, pincode, age, gender, created_by) self.conn.commit_data() print("\n" + Color.F_Green + "record inserted" + Base.END) except Exception as e: print(e) self.conn.rollback_data()
def test_age(self): inputs = ['45', '200', 'invalid_age'] self.assertEqual(True, Validation.age(inputs[0])) self.assertEqual(False, Validation.age(inputs[1])) self.assertEqual(False, Validation.age(inputs[2]))