def get_by_api_key(api_key: str): try: user = User.get_user_from_api_key(api_key, get_db_session()) except NoResultFound: raise UserNotFoundException('API Key is wrong, please go to our account https://app.seamlesscloud.io/account,' ' copy the API Key field and run "smls init <api key>"') return user
def test_user_init(): uid, name, email = str(uuid4()), "TestUser", "*****@*****.**" user = User(uid=uid, name=name, email=email) assert isinstance(user, BaseUser) assert user.uid == uid assert user.name == name assert user.email == email
def test_user_from_dict(): data = {"uid": str(uuid4()), "name": "TestUser", "email": "*****@*****.**"} user = User.from_dict(data) assert isinstance(user, BaseUser) assert user.uid == data["uid"] assert user.name == data["name"] assert user.email == data["email"]
async def create(self, **user_dict) -> dict: """Создание клиента в приложении :param user_dict: :return: """ user = User.from_dict(user_dict) return await self._storage.create(**user.to_dict())
def get_user_info(): email = session['profile']['email'] try: user = User.get_user_from_email(email, get_db_session()) if user: return jsonify({'email': user.email, 'api_key': user.api_key}), 200 return jsonify({'message': 'Unable to find a user'}), 404 except Exception as e: logging.exception(e) logging.exception(request.data.decode('utf-8')) return jsonify({'message': 'Unable to get an api key'}), 500
def create(email: str, api_key: str = None): session = get_db_session() user = User(email=email, api_key=api_key or generate_api_key()) session.add(user) db_commit() workspace = Workspace(owner_id=user.id) session.add(workspace) db_commit() return user.id
def test_users(): users = [User(email=f"{i}@loadtest.com", api_key=generate_api_key()) for i in range(NUMBER_OF_TEST_USERS)] for user in users: db_session.add(user) db_session.commit() yield [row2dict(user) for user in users] for user in users: db_session.delete(user) db_session.commit()
def get_by_id(user_id: str): try: user = User.get_user_from_id(user_id, get_db_session()) except NoResultFound: raise UserNotFoundException(f'Cannot find a user with id: {user_id}') return user