def get_current_user(self) -> Union[User, None]: if ctx.envtype == 'development': username = os.getenv("DEV_USER") if username is not None: return User.get(username) user = self._get_user_from_x_api_auth_token( ) or self._get_user_from_session() return user
def create_users(self): ctx.log.info("creating fixture users") self.users = [] data = requests.get(f"https://randomuser.me/api/?results={USERS_COUNT}").json() i = 1 for user_data in data["results"]: username = f"fx_test_user_{i}" user = User.get(username) if not user: user = User.create( username=username, ext_id=username, first_name=user_data["name"]["first"], last_name=user_data["name"]["last"], avatar_url=user_data["picture"]["thumbnail"], email=user_data["email"] ) user.save() self.users.append(user) i += 1
def users_unsubscribe(user_id): current: User = get_user_from_app_context() user = User.get(user_id, "user not found") current.unsubscribe_from_user(user) return users_subscription()
def _get_user_from_session() -> Union[User, None]: user_id = session.get("user_id") if user_id: user = User.get(user_id) return user return None