Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 16 for test_user (0.06 sec)

  1. tests/test_tutorial/test_python_types/test_tutorial012.py

    from docs_src.python_types.tutorial012_py39 import User
    
    
    def test_user():
        user = User(name="John Doe", age=30)
        assert user.name == "John Doe"
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Fri Dec 26 10:43:02 UTC 2025
    - 177 bytes
    - Viewed (0)
  2. tests/test_dependency_security_overrides.py

    from fastapi import Depends, FastAPI, Security
    from fastapi.security import SecurityScopes
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    
    def get_user(required_scopes: SecurityScopes):
        return "john", required_scopes.scopes
    
    
    def get_user_override(required_scopes: SecurityScopes):
        return "alice", required_scopes.scopes
    
    
    def get_data():
        return [1, 2, 3]
    
    
    def get_data_override():
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 21:25:59 UTC 2025
    - 1.4K bytes
    - Viewed (1)
  3. docs_src/security/tutorial004_py39.py

    
    def get_password_hash(password):
        return password_hash.hash(password)
    
    
    def get_user(db, username: str):
        if username in db:
            user_dict = db[username]
            return UserInDB(**user_dict)
    
    
    def authenticate_user(fake_db, username: str, password: str):
        user = get_user(fake_db, username)
        if not user:
            return False
        if not verify_password(password, user.hashed_password):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 4.1K bytes
    - Viewed (0)
  4. tests/test_security_scopes.py

        def get_db():
            call_counter["count"] += 1
            return f"db_{call_counter['count']}"
    
        def get_user(db: Annotated[str, Depends(get_db)]):
            return "user"
    
        app = FastAPI()
    
        @app.get("/")
        def endpoint(
            db: Annotated[str, Depends(get_db)],
            user: Annotated[str, Security(get_user, scopes=["read"])],
        ):
            return {"db": db}
    
        return app
    
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 21:25:59 UTC 2025
    - 1006 bytes
    - Viewed (0)
  5. tests/test_validation_error_context.py

    async def websocket_validation_handler(
        websocket: WebSocket, exc: WebSocketRequestValidationError
    ):
        captured_exception.capture(exc)
        raise exc
    
    
    @app.get("/users/{user_id}")
    def get_user(user_id: int):
        return {"user_id": user_id}  # pragma: no cover
    
    
    @app.get("/items/", response_model=Item)
    def get_item():
        return {"name": "Widget"}
    
    
    @sub_app.get("/items/", response_model=Item)
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 06 12:21:57 UTC 2025
    - 4.7K bytes
    - Viewed (0)
  6. docs_src/security/tutorial003_py39.py

    
    class UserInDB(User):
        hashed_password: str
    
    
    def get_user(db, username: str):
        if username in db:
            user_dict = db[username]
            return UserInDB(**user_dict)
    
    
    def fake_decode_token(token):
        # This doesn't provide any security at all
        # Check the next version
        user = get_user(fake_users_db, token)
        return user
    
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 2.4K bytes
    - Viewed (0)
  7. tests/test_schema_compat_pydantic_v2.py

            user = "user"
    
        class OtherRole(str, Enum): ...
    
        class User(BaseModel):
            username: str
            role: PlatformRole | OtherRole
    
        @app.get("/users")
        async def get_user() -> User:
            return {"username": "alice", "role": "admin"}
    
        client = TestClient(app)
        return client
    
    
    @needs_py310
    def test_get(client: TestClient):
        response = client.get("/users")
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 20 15:55:38 UTC 2025
    - 2.7K bytes
    - Viewed (0)
  8. tests/test_params_repr.py

    from typing import Any
    
    from fastapi.params import Body, Cookie, Header, Param, Path, Query
    
    test_data: list[Any] = ["teststr", None, ..., 1, []]
    
    
    def get_user():
        return {}  # pragma: no cover
    
    
    def test_param_repr_str():
        assert repr(Param("teststr")) == "Param(teststr)"
    
    
    def test_param_repr_none():
        assert repr(Param(None)) == "Param(None)"
    
    
    def test_param_repr_ellipsis():
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 2.3K bytes
    - Viewed (0)
  9. tests/test_dependency_contextvars.py

    ):
        response = await call_next(request)
        response.headers["custom"] = "foo"
        return response
    
    
    @app.get("/user", dependencies=[Depends(set_up_request_state_dependency)])
    def get_user():
        request_state = legacy_request_state_context_var.get()
        assert request_state
        return request_state["user"]
    
    
    client = TestClient(app)
    
    
    def test_dependency_contextvars():
        """
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 21:25:59 UTC 2025
    - 1.5K bytes
    - Viewed (0)
  10. tests/test_infer_param_optionality.py

    app = FastAPI()
    
    
    user_router = APIRouter()
    item_router = APIRouter()
    
    
    @user_router.get("/")
    def get_users():
        return [{"user_id": "u1"}, {"user_id": "u2"}]
    
    
    @user_router.get("/{user_id}")
    def get_user(user_id: str):
        return {"user_id": user_id}
    
    
    @item_router.get("/")
    def get_items(user_id: Optional[str] = None):
        if user_id is None:
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 12.1K bytes
    - Viewed (0)
Back to top