def post(self): username = request.json.get('username', None) password = request.json.get('password', None) result, user = user_crud.create_user(username, password) if result: return user else: return None
def test_create_user_basic(): user_crud.create_user("ronaldo", "fenomeno123") user = user_crud.get_user_by_username("ronaldo") assert user == User("ronaldo", "fenomeno123")
def test_create_user_ids(): user_crud.create_user("ronaldinho", "j0g4muit0") user1 = user_crud.get_user_by_id(1) user2 = user_crud.get_user_by_id(2) assert user1 == User("ronaldo", "fenomeno123") assert user2 == User("ronaldinho", "j0g4muit0")
def test_create_user_repeated_username(): user_crud.create_user("ronaldo", "fenomeno123") user_crud.create_user("ronaldo", "fenomeno123") user = user_crud.get_user_by_id(2) assert user is None
def create(user: schemas.UserCreate, db: Session = Depends(get_db)): db_user = user_crud.get_user_by_email(db, user.email) if db_user: raise HTTPException(status_code=400, detail="Email already registered.") return user_crud.create_user(db=db, user=user)