feat: Update endpoint Outliners
This commit is contained in:
parent
9dc2f054ed
commit
176d46797a
@ -1,19 +1,23 @@
|
||||
let jsonData = pm.response.json();
|
||||
from typing import Optional
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from models import User
|
||||
from schemas import UserSchema
|
||||
from database import get_db
|
||||
from utils import verify_password, create_access_token
|
||||
|
||||
pm.test("Status code is 200", function () {
|
||||
pm.response.to.have.status(200);
|
||||
});
|
||||
router = APIRouter()
|
||||
|
||||
pm.test("Response contains carts array", function () {
|
||||
pm.expect(jsonData).to.have.property("carts");
|
||||
pm.expect(jsonData.carts).to.be.an("array");
|
||||
});
|
||||
|
||||
pm.test("Each cart has required properties", function () {
|
||||
jsonData.carts.forEach(cart => {
|
||||
pm.expect(cart).to.have.property("id");
|
||||
pm.expect(cart).to.have.property("total");
|
||||
pm.expect(cart).to.have.property("products");
|
||||
pm.expect(cart.products).to.be.an("array");
|
||||
});
|
||||
});
|
||||
@router.post("/request-access", response_model=UserSchema)
|
||||
async def request_access(user_data: UserSchema, db: Session = Depends(get_db)):
|
||||
"""
|
||||
Request access for a user by providing email and password.
|
||||
Returns the user data along with an access token if successful.
|
||||
"""
|
||||
user = db.query(User).filter(User.email == user_data.email).first()
|
||||
if not user:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
if not verify_password(user_data.password, user.hashed_password):
|
||||
raise HTTPException(status_code=401, detail="Incorrect password")
|
||||
access_token = create_access_token(user.id)
|
||||
return {**user_data.dict(), "access_token": access_token}
|
Loading…
x
Reference in New Issue
Block a user