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_project(self): """ this method is used to create project for current bdo. """ try: print("choose gpm for project\n") gpm_list = self.get_gpm_list() menu = Menu() gpm_names = [x for x in gpm_list.keys()] gpm_names.extend([str(BackButton.EXIT.name)]) gpm_name = menu.draw_menu(gpm_names) input() gpm_id = gpm_list[gpm_name] print("choose project type:\n") menu2 = Menu() project_types = [x.name for x in ProjectType] project_types.extend([str(BackButton.EXIT.name)]) project_type = menu2.draw_menu(project_types) input() project_id = str(uuid.uuid4()) project_name = input("enter project name: ") labours = input("enter expected labours: ") if not Validation.is_int(labours): print("labours count is not valid") input() sys.exit() cost = input("enter estimated project cost: ") if not Validation.is_int(cost): print("cost is not valid") input() sys.exit() area = input("enter estimated project area: ") if not Validation.is_int(area): print("area is not valid") input() sys.exit() start_date = input("enter estimated start date: ") if not Validation.is_date(start_date): print("start date is not valid") input() sys.exit() end_date = input("enter estimated end date: ") if not Validation.is_date(end_date): print("end date is not valid") input() sys.exit() is_deleted = 'False' created_by = self.bdo_id self.conn.create_project(project_id, project_name, labours, cost, area, start_date, end_date, gpm_id, created_by, project_type, is_deleted) self.conn.commit_data() print("\n" + Color.F_Green + "project created" + Base.END) except Exception as e: print(e) self.conn.rollback_data()
def test_start_date(self): inputs = [ str(datetime.datetime.now().date()), '2000-01-01', '3421-14-23', 'invalid_date' ] self.assertEqual(True, Validation.start_date(inputs[0])) self.assertEqual(False, Validation.start_date(inputs[1])) self.assertEqual(False, Validation.start_date(inputs[2])) self.assertEqual(False, Validation.start_date(inputs[3]))
def update_members(self): """ this method is used to update member details of current gpm. """ members_list = self.get_members_list() menu = Menu() members_names = [x for x in members_list.keys()] members_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) members_name = menu.draw_menu(members_names) input() if str(BackButton.BACK.name) == members_name: return members_id = members_list[members_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] # validations if field == str(GpmUpdateFields.GENDER.name): if not Validation.gender(user_input): print("gender is not valid") input() sys.exit() if field == str(GpmUpdateFields.PINCODE.name): if not Validation.pincode(user_input): print("pincode is not valid") input() sys.exit() if field == str(GpmUpdateFields.AGE.name): if not Validation.is_int(user_input): print("age is not valid") input() sys.exit() # if field belong to user table if user_table_fields.count(GpmUpdateFields[field].value) == 1: self.conn.update_user(str(field), members_id, user_input) else: self.conn.update_personal_details(str(field), members_id, user_input) self.conn.commit_data() print("\n" + Color.F_Green + "record updated" + Base.END)
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)
def create_gpm(self): """ this method is used to create gpm for current bdo. """ try: name = input("enter gpm name ") id = str(uuid.uuid4()) password = input("enter password for gpm ") if not Validation.password(password): print("weak password") input() return user_name = input("enter user name for gpm ") role_id = int(Role.GPM.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("pin code is not valid") input() return age = input("enter age ") if not Validation.is_int(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.bdo_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_password(self): inputs = [ 'Monty@123sgahRma', '1231', 'invalid_pass', '@#$%^^', 'ASDFDFGDG', 'sdf sdSASf', 'asASASAS', 'ASasd123213', 'Monty@123sgahRma asd' ] self.assertEqual(True, Validation.password(inputs[0])) self.assertEqual(False, Validation.password(inputs[1])) self.assertEqual(False, Validation.password(inputs[2])) self.assertEqual(False, Validation.password(inputs[3])) self.assertEqual(False, Validation.password(inputs[4])) self.assertEqual(False, Validation.password(inputs[5])) self.assertEqual(False, Validation.password(inputs[6])) self.assertEqual(False, Validation.password(inputs[7])) self.assertEqual(False, Validation.password(inputs[8]))
def test_end_date(self): start_inputs = [ '2020-01-01', '2020-03-01', '2020-01-01', '3421-14-23', 'invalid_date' ] end_inputs = [ '2020-03-01', '2020-01-01', '2020-13-01', '2020-03-01', 'invalid_date' ] self.assertEqual(True, Validation.end_date(start_inputs[0], end_inputs[0])) self.assertEqual(False, Validation.end_date(start_inputs[1], end_inputs[1])) self.assertEqual(False, Validation.end_date(start_inputs[2], end_inputs[2])) self.assertEqual(False, Validation.end_date(start_inputs[3], end_inputs[3])) self.assertEqual(False, Validation.end_date(start_inputs[4], end_inputs[4]))
def show_requests(self): """ this method is used show request and resolve request of current gpm. """ try: projects = self.conn.get_requests(self.gpm_id) result = projects.fetchall() counter = 0 # getting columns for showing requests and adding index column at first in list projects_fields = (('index'),) + projects.description # request is empty then returning early with a message if len(result) == 0: print(Color.F_Red + "there is no pending request" + Base.END) return temp = result # converting list of tuples into list of list temp = [list(elem) for elem in temp] print("write index of request to manage:\n") for request in temp: request.insert(0, counter) counter += 1 table = PrettyTable() table.field_names = [column[0] for column in projects_fields[:-1]] for row in temp: table.add_row(row[:-1]) print(table) row_number = input("enter index number: ") if not Validation.is_int(row_number): print("row number is not valid") input() return menu = Menu() result_names = [x.name for x in RequestResult] result_names.extend([str(BackButton.EXIT.name)]) result_name = menu.draw_menu(result_names) input() status = "NULL" if str(result_name) == str(RequestResult.APPROVED.name): status = "'True'" elif str(result_name) == str(RequestResult.REJECTED.name): status = "'False'" self.conn.resolve_request(status, result[int(row_number)][4]) self.conn.commit_data() print(Color.F_Green + "Request completed successfully" + 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]))
def test_is_email(self): inputs = ['*****@*****.**', '2020', 'invalid_id', 'asd.com'] self.assertEqual(True, Validation.is_email(inputs[0])) self.assertEqual(False, Validation.is_email(inputs[1])) self.assertEqual(False, Validation.is_email(inputs[2])) self.assertEqual(False, Validation.is_email(inputs[3]))
def test_is_int(self): inputs = ['2020', 'invalid_int', '-34'] self.assertEqual(True, Validation.is_int(inputs[0])) self.assertEqual(False, Validation.is_int(inputs[1])) self.assertEqual(False, Validation.is_int(inputs[2]))
def test_pincode(self): inputs = ['452323', '2020', 'invalid_piincode', '-23234'] self.assertEqual(True, Validation.pincode(inputs[0])) self.assertEqual(False, Validation.pincode(inputs[1])) self.assertEqual(False, Validation.pincode(inputs[2])) self.assertEqual(False, Validation.pincode(inputs[3]))
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]))
def update_project(self): """ this method is used to update project for current bdo. """ print("choose project") project_list = self.get_project_list() menu = Menu() project_names = [x for x in project_list.keys()] project_names.extend( [str(BackButton.EXIT.name), str(BackButton.BACK.name)]) project_name = menu.draw_menu(project_names) input() if str(BackButton.BACK.name) == project_name: return project_id = project_list[project_name] print("select the field to update: \n") menu2 = Menu() details = [x.name for x in ProjectsUpdateFields] details.extend([str(BackButton.EXIT.name)]) field = menu2.draw_menu(details) input() user_input = "" if ProjectsUpdateFields[ field].value == ProjectsUpdateFields.PROJECT_TYPE.value: print("choose project type: \n") menu3 = Menu() project_types = [x.name for x in ProjectType] project_types.extend([str(BackButton.EXIT.name)]) user_input = menu3.draw_menu(project_types) input() else: user_input = input("enter new value for " + str(field) + " ") # validations if field == str(ProjectsUpdateFields.AREA_OF_PROJECT.name): if not Validation.is_int(user_input): print("area is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.TOTAL_LABOUR_REQUIRED.name): if not Validation.is_int(user_input): print("labour required is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.ESTIMATED_START_DATE.name): if not Validation.is_date(user_input): print("start date is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.ESTIMATED_END_DATE.name): if not Validation.is_date(user_input): print("end date is not valid") input() sys.exit() if field == str(ProjectsUpdateFields.ESTIMATED_COST.name): if not Validation.is_int(user_input): print("cost is not valid") input() sys.exit() self.conn.update_project(field, user_input, project_id) self.conn.commit_data() print("\n" + Color.F_Green + "record updated" + Base.END)
def show_requests(self): """ this method is used to show and resolve all requests for current bdo. """ try: projects = self.conn.get_requests(self.bdo_id) # adding index column to given result projects_fields = (('index'), ) + projects.description result = projects.fetchall() counter = 0 # request is empty then returning early with a message if len(result) == 0: print(Color.F_Red + "there is no pending request" + Base.END) return print("write index of request to manage:\n") temp = result # converting list of tuples into list of list temp = [list(elem) for elem in temp] for request in temp: if str(RequestType.APPROVAL.name) == str(request[0]): temp2 = str(request[2]).split('|') request[2] = temp2[0] + " request for " + temp2[ 4] + " project for " + temp2[1] + " member" # inserting data for index column request.insert(0, counter) counter += 1 table = PrettyTable() # assigning field names to pretty table object and removing request id column table.field_names = [column[0] for column in projects_fields[:-1]] for row in temp: # removing request id from temp list and adding to table row table.add_row(row[:-1]) print(table) row_number = input("enter index number: ") if not Validation.is_int(row_number): print("index number is not valid") input() sys.exit() menu = Menu() result_names = [x.name for x in RequestResult] result_names.extend([str(BackButton.EXIT.name)]) result_name = menu.draw_menu(result_names) input() status = "NULL" if str(RequestType.APPROVAL.name) == str( result[int(row_number)][0]): temp = str(result[int(row_number)][2]).split('|') req_type = str(temp[0]) self.project_id = str(temp[3]) self.member_id = str(temp[2]) if req_type == str( ApprovalType.WAGE.name) and str(result_name) == str( RequestResult.APPROVED.name): self.delete_project_members() status = "'True'" elif req_type == str( ApprovalType.MEMBER.name) and str(result_name) == str( RequestResult.APPROVED.name): project_members_id = self.conn.get_project_members( self.project_id) members_required = self.conn.get_project_members_required( self.project_id) # checking if total number of members in given project are less then actual project requirement if members_required[0] <= len(project_members_id): print( Color.F_Red + "project members limit exceeded can't accept request" + Base.END) return self.conn.assign_project_members(self.project_id, self.member_id) status = "'True'" elif str(result_name) == str(RequestResult.REJECTED.name): status = "'False'" else: if str(result_name) == str(RequestResult.APPROVED.name): status = "'True'" elif str(result_name) == str(RequestResult.REJECTED.name): status = "'False'" self.conn.resolve_request(status, result[int(row_number)][4]) self.conn.commit_data() print(Color.F_Green + "Request completed successfully" + Base.END) except Exception as e: print(e) self.conn.rollback_data()
def test_gender(self): inputs = ['M', 'F', 'invalid_gender'] self.assertEqual(True, Validation.gender(inputs[0])) self.assertEqual(True, Validation.gender(inputs[1])) self.assertEqual(False, Validation.gender(inputs[2]))