-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
✨ Add private, local only, API for usage in E2E tests #1429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
560904a
Add a local only private API
patrick91 73daefa
Rename type
patrick91 7a9f945
Rename type
patrick91 c003281
✨ Autogenerate frontend client
invalid-email-address 21d1c9e
Add prefix to type
patrick91 40c7ecf
✨ Autogenerate frontend client
invalid-email-address ca35292
Update environment settings
patrick91 2221ce0
Add secret key
patrick91 499d05d
Add missing env
patrick91 dfbebb4
✨ Autogenerate frontend client
invalid-email-address d6df2fa
Update playwright
patrick91 3500d8d
Test
patrick91 8c1a8d6
Fix yaml
patrick91 245e62a
Fix environment
patrick91 3cb25ed
Fix
patrick91 609a8e0
Ignore tests when building
patrick91 8ccd117
Remove unused exclude
patrick91 67372b4
Move tags and prefix to the private router instead
patrick91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,10 @@ jobs: | |
- run: uv run bash scripts/generate-client.sh | ||
env: | ||
VIRTUAL_ENV: backend/.venv | ||
ENVIRONMENT: production | ||
SECRET_KEY: just-for-generating-client | ||
POSTGRES_PASSWORD: just-for-generating-client | ||
FIRST_SUPERUSER_PASSWORD: just-for-generating-client | ||
- name: Add changes to git | ||
run: | | ||
git config --local user.email "[email protected]" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.api.routes import items, login, users, utils | ||
from app.api.routes import items, login, private, users, utils | ||
from app.core.config import settings | ||
|
||
api_router = APIRouter() | ||
api_router.include_router(login.router, tags=["login"]) | ||
api_router.include_router(users.router, prefix="/users", tags=["users"]) | ||
api_router.include_router(utils.router, prefix="/utils", tags=["utils"]) | ||
api_router.include_router(items.router, prefix="/items", tags=["items"]) | ||
|
||
|
||
if settings.ENVIRONMENT == "local": | ||
api_router.include_router(private.router) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Any | ||
|
||
from fastapi import APIRouter | ||
from pydantic import BaseModel | ||
|
||
from app.api.deps import SessionDep | ||
from app.core.security import get_password_hash | ||
from app.models import ( | ||
User, | ||
UserPublic, | ||
) | ||
|
||
router = APIRouter(tags=["private"], prefix="/private") | ||
|
||
|
||
class PrivateUserCreate(BaseModel): | ||
email: str | ||
password: str | ||
full_name: str | ||
is_verified: bool = False | ||
|
||
|
||
@router.post("/users/", response_model=UserPublic) | ||
def create_user(user_in: PrivateUserCreate, session: SessionDep) -> Any: | ||
""" | ||
Create a new user. | ||
""" | ||
|
||
user = User( | ||
email=user_in.email, | ||
full_name=user_in.full_name, | ||
hashed_password=get_password_hash(user_in.password), | ||
) | ||
|
||
session.add(user) | ||
session.commit() | ||
|
||
return user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from fastapi.testclient import TestClient | ||
from sqlmodel import Session, select | ||
|
||
from app.core.config import settings | ||
from app.models import User | ||
|
||
|
||
def test_create_user(client: TestClient, db: Session) -> None: | ||
r = client.post( | ||
f"{settings.API_V1_STR}/private/users/", | ||
json={ | ||
"email": "[email protected]", | ||
"password": "password123", | ||
"full_name": "Pollo Listo", | ||
}, | ||
) | ||
|
||
assert r.status_code == 200 | ||
|
||
data = r.json() | ||
|
||
user = db.exec(select(User).where(User.id == data["id"])).first() | ||
|
||
assert user | ||
assert user.email == "[email protected]" | ||
assert user.full_name == "Pollo Listo" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Note: the `PrivateService` is only available when generating the client | ||
// for local environments | ||
import { OpenAPI, PrivateService } from "../../src/client" | ||
|
||
OpenAPI.BASE = `${process.env.VITE_API_URL}` | ||
|
||
export const createUser = async ({ | ||
email, | ||
password, | ||
}: { | ||
email: string | ||
password: string | ||
}) => { | ||
return await PrivateService.createUser({ | ||
requestBody: { | ||
email, | ||
password, | ||
is_verified: true, | ||
full_name: "Test User", | ||
}, | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["tests/**/*.ts"] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣 🐔