mirror of
https://github.com/fastapi/full-stack-fastapi-template.git
synced 2026-11-03 20:36:27 +00:00
✨ Add Items (crud, models, endpoints), utils, refactor (#14)
* Update CRUD utils to use types better. * Simplify Pydantic model names, from `UserInCreate` to `UserCreate`, etc. * Upgrade packages. * Add new generic "Items" models, crud utils, endpoints, and tests. To facilitate re-using them to create new functionality. As they are simple and generic (not like Users), it's easier to copy-paste and adapt them to each use case. * Update endpoints/*path operations* to simplify code and use new utilities, prefix and tags in `include_router`. * Update testing utils. * Update linting rules, relax vulture to reduce false positives. * Update migrations to include new Items. * Update project README.md with tips about how to start with backend.
This commit is contained in:
committed by
GitHub
parent
1fe4908b0a
commit
ecd634e497
@@ -0,0 +1,17 @@
|
||||
from app import crud
|
||||
from app.db.session import db_session
|
||||
from app.models.item import ItemCreate
|
||||
from app.tests.utils.user import create_random_user
|
||||
from app.tests.utils.utils import random_lower_string
|
||||
|
||||
|
||||
def create_random_item(owner_id: int = None):
|
||||
if owner_id is None:
|
||||
user = create_random_user()
|
||||
owner_id = user.id
|
||||
title = random_lower_string()
|
||||
description = random_lower_string()
|
||||
item_in = ItemCreate(title=title, description=description, id=id)
|
||||
return crud.item.create(
|
||||
db_session=db_session, item_in=item_in, owner_id=owner_id
|
||||
)
|
||||
@@ -1,6 +1,10 @@
|
||||
import requests
|
||||
|
||||
from app import crud
|
||||
from app.core import config
|
||||
from app.db.session import db_session
|
||||
from app.models.user import UserCreate
|
||||
from app.tests.utils.utils import random_lower_string
|
||||
|
||||
|
||||
def user_authentication_headers(server_api, email, password):
|
||||
@@ -11,3 +15,11 @@ def user_authentication_headers(server_api, email, password):
|
||||
auth_token = response["access_token"]
|
||||
headers = {"Authorization": f"Bearer {auth_token}"}
|
||||
return headers
|
||||
|
||||
|
||||
def create_random_user():
|
||||
email = random_lower_string()
|
||||
password = random_lower_string()
|
||||
user_in = UserCreate(username=email, email=email, password=password)
|
||||
user = crud.user.create(db_session=db_session, user_in=user_in)
|
||||
return user
|
||||
|
||||
Reference in New Issue
Block a user