def get_or_create_user(auth_user): user = User() # Returns None or List[User] objects - could be more than one users = user.get_user_by_username(str(auth_user.username)) if users is None: user.set_user_id(str(uuid.uuid4())) user.set_user_name(auth_user.name) user.set_lf_email(auth_user.email.lower()) user.set_lf_username(auth_user.username) user.set_lf_sub(auth_user.sub) user.save() event_data = f'CLA user added for {auth_user.username}' Event.create_event( event_data=event_data, event_type=EventType.CreateUser, contains_pii=True, ) return user # Just return the first matching record return users[0]
def test_get_user_email(self): user = User() user.set_lf_email(None) user.set_user_emails([]) assert user.get_user_email() is None user.set_lf_email("*****@*****.**") assert user.get_user_email() == "*****@*****.**" user = User(user_email="*****@*****.**") assert user.get_user_email() == "*****@*****.**" user = User(user_email="*****@*****.**", preferred_email="*****@*****.**") assert user.get_user_email() == "*****@*****.**" user.set_user_emails(["*****@*****.**", "*****@*****.**"]) user.set_lf_email("*****@*****.**") assert user.get_user_email() == "*****@*****.**" # the scenario where have multiple emails user = User(preferred_email="*****@*****.**") user.set_user_emails(["*****@*****.**", "*****@*****.**", "*****@*****.**"]) assert user.get_user_email() == "*****@*****.**" assert user.get_user_email(preferred_email="*****@*****.**") == "*****@*****.**" assert user.get_user_email(preferred_email="*****@*****.**") != "*****@*****.**" user.set_lf_email("*****@*****.**") assert user.get_user_email() == "*****@*****.**" assert user.get_user_email(preferred_email="*****@*****.**") == "*****@*****.**" assert user.get_user_email(preferred_email="*****@*****.**") == "*****@*****.**" assert user.get_user_email(preferred_email="*****@*****.**") == "*****@*****.**"
def get_or_create_user(auth_user): user = User() existing_user = user.get_user_by_username(str(auth_user.username)) if existing_user is None: user.set_user_id(str(uuid.uuid4())) user.set_user_name(auth_user.name) user.set_lf_email(auth_user.email.lower()) user.set_lf_username(auth_user.username) user.set_lf_sub(auth_user.sub) user.save() return user return existing_user
def get_or_create_user(auth_user): user = User() # Returns None or List[User] objects - could be more than one users = user.get_user_by_username(str(auth_user.username)) if users is None: user.set_user_id(str(uuid.uuid4())) user.set_user_name(auth_user.name) user.set_lf_email(auth_user.email.lower()) user.set_lf_username(auth_user.username) user.set_lf_sub(auth_user.sub) user.save() return user # Just return the first matching record return users[0]
def mock_get_managers(): u1 = User() u1.set_lf_email('*****@*****.**') u2 = User() u2.set_lf_email('*****@*****.**') return [u1, u2]