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 () {
|
router = APIRouter()
|
||||||
pm.response.to.have.status(200);
|
|
||||||
});
|
|
||||||
|
|
||||||
pm.test("Response contains carts array", function () {
|
@router.post("/request-access", response_model=UserSchema)
|
||||||
pm.expect(jsonData).to.have.property("carts");
|
async def request_access(user_data: UserSchema, db: Session = Depends(get_db)):
|
||||||
pm.expect(jsonData.carts).to.be.an("array");
|
"""
|
||||||
});
|
Request access for a user by providing email and password.
|
||||||
|
Returns the user data along with an access token if successful.
|
||||||
pm.test("Each cart has required properties", function () {
|
"""
|
||||||
jsonData.carts.forEach(cart => {
|
user = db.query(User).filter(User.email == user_data.email).first()
|
||||||
pm.expect(cart).to.have.property("id");
|
if not user:
|
||||||
pm.expect(cart).to.have.property("total");
|
raise HTTPException(status_code=404, detail="User not found")
|
||||||
pm.expect(cart).to.have.property("products");
|
if not verify_password(user_data.password, user.hashed_password):
|
||||||
pm.expect(cart.products).to.be.an("array");
|
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