def create_admin_user(test_client, initialize_database, seed_system_data, create_master_organization): organization = create_master_organization user = User( given_names="John Doe", surname="Jane", email="*****@*****.**", signup_method=SignupMethod.WEB_SIGNUP, role_id=1, ) user.hash_password("password-123") user.bind_user_to_organization(organization) db.session.add(user) db.session.commit() return user
def create_client_user(test_client, initialize_database, seed_system_data, create_master_organization): organization = create_master_organization user = User( given_names="Jon Snow", surname="Stark", phone="+254712345678", signup_method=SignupMethod.MOBILE_SIGNUP, role_id=2, ) user.set_identification_details(id_type="NATIONAL_ID", id_value="12345678") user.hash_password("password-123") db.session.add(user) user.bind_user_to_organization(organization) db.session.commit() return user
def create_user( given_names=None, surname=None, email=None, phone=None, address=None, date_of_birth=None, id_type=None, id_value=None, password=None, role=None, signup_method=None, organization: Organization = None, ): """ :param role: The user's role :param organization: The organization the user belongs to :param signup_method: The channel through which teh user was signed up :param given_names: The collective first names the user identifies with :param surname: The user's surname :param email: The user's email address :param phone: The user's phone number :param address: The user's physical postal address :param date_of_birth: The user's date of birth :param id_type: The form of identification used by the user :param id_value: The value tied to that ID type :param password: Value of user's password :return: """ # create user user = User( given_names=given_names, surname=surname, email=email, phone=phone, date_of_birth=date_of_birth, address=address, signup_method=signup_method, ) user.is_activated = False # set identification information if id_value: user.set_identification_details(id_type=id_type, id_value=id_value) # hash password if password: user.hash_password(password=password) # unless special organization defined, default to master organization if not organization: organization = Organization.master_organisation() # bind user to organization user.bind_user_to_organization(organization) # set user role if role: user.set_role(role) # default to client role else: user.set_role("CLIENT") db.session.add(user) return user