Search Options

Results per page
Sort
Preferred Languages
Advance

Results 281 - 290 of 1,379 for def2 (0.15 sec)

  1. docs_src/handling_errors/tutorial003.py

    from fastapi import FastAPI, Request
    from fastapi.responses import JSONResponse
    
    
    class UnicornException(Exception):
        def __init__(self, name: str):
            self.name = name
    
    
    app = FastAPI()
    
    
    @app.exception_handler(UnicornException)
    async def unicorn_exception_handler(request: Request, exc: UnicornException):
        return JSONResponse(
            status_code=418,
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Thu Mar 26 19:09:53 UTC 2020
    - 626 bytes
    - Viewed (0)
  2. tests/test_tutorial/test_additional_responses/test_tutorial002.py

    from docs_src.additional_responses.tutorial002 import app
    
    client = TestClient(app)
    
    
    def test_path_operation():
        response = client.get("/items/foo")
        assert response.status_code == 200, response.text
        assert response.json() == {"id": "foo", "value": "there goes my hero"}
    
    
    def test_path_operation_img():
        shutil.copy("./docs/en/docs/img/favicon.png", "./image.png")
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Fri Jul 07 17:12:13 UTC 2023
    - 4.6K bytes
    - Viewed (0)
  3. docs/em/docs/advanced/async-tests.md

    ➑️ πŸ‘€ ❔ πŸ‘₯ πŸ’ͺ βš’ πŸ‘ˆ πŸ‘·.
    
    ## pytest.mark.anyio
    
    πŸš₯ πŸ‘₯ πŸ’š πŸ€™ πŸ” πŸ”’ πŸ‘† πŸ’―, πŸ‘† πŸ’― πŸ”’ βœ”οΈ πŸ”. AnyIO 🚚 πŸ‘Œ πŸ“ πŸ‘‰, πŸ‘ˆ βœ” πŸ‘₯ βœ” πŸ‘ˆ πŸ’― πŸ”’ πŸ€™ πŸ”.
    
    ## πŸ‡ΈπŸ‡²
    
    πŸš₯ πŸ‘† **FastAPI** 🈸 βš™οΈ 😐 `def` πŸ”’ ↩️ `async def`, ⚫️ `async` 🈸 πŸ”˜.
    
    `TestClient` πŸ”¨ 🎱 πŸ”˜ πŸ€™ πŸ” FastAPI 🈸 πŸ‘† 😐 `def` πŸ’― πŸ”’, βš™οΈ 🐩 ✳. βœ‹οΈ πŸ‘ˆ 🎱 🚫 πŸ‘· πŸš«πŸ”œ πŸ•β” πŸ‘₯ βš™οΈ ⚫️ πŸ”˜ πŸ” πŸ”’. πŸƒ πŸ‘† πŸ’― πŸ”, πŸ‘₯ πŸ’ͺ πŸ™…β€β™‚ πŸ“ βš™οΈ `TestClient` πŸ”˜ πŸ‘† πŸ’― πŸ”’.
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 3K bytes
    - Viewed (0)
  4. docs_src/path_operation_configuration/tutorial002_py39.py

        tags: set[str] = set()
    
    
    @app.post("/items/", response_model=Item, tags=["items"])
    async def create_item(item: Item):
        return item
    
    
    @app.get("/items/", tags=["items"])
    async def read_items():
        return [{"name": "Foo", "price": 42}]
    
    
    @app.get("/users/", tags=["users"])
    async def read_users():
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sat May 14 11:59:59 UTC 2022
    - 575 bytes
    - Viewed (0)
  5. tests/test_security_api_key_header_optional.py

    api_key = APIKeyHeader(name="key", auto_error=False)
    
    
    class User(BaseModel):
        username: str
    
    
    def get_current_user(oauth_header: Optional[str] = Security(api_key)):
        if oauth_header is None:
            return None
        user = User(username=oauth_header)
        return user
    
    
    @app.get("/users/me")
    def read_current_user(current_user: Optional[User] = Depends(get_current_user)):
        if current_user is None:
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Fri Jun 30 18:25:16 UTC 2023
    - 2K bytes
    - Viewed (0)
  6. tests/test_security_http_digest_optional.py

    security = HTTPDigest(auto_error=False)
    
    
    @app.get("/users/me")
    def read_current_user(
        credentials: Optional[HTTPAuthorizationCredentials] = Security(security),
    ):
        if credentials is None:
            return {"msg": "Create an account first"}
        return {"scheme": credentials.scheme, "credentials": credentials.credentials}
    
    
    client = TestClient(app)
    
    
    def test_security_http_digest():
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Fri Jun 30 18:25:16 UTC 2023
    - 2.2K bytes
    - Viewed (0)
  7. tests/test_tutorial/test_request_form_models/test_tutorial001_an.py

    import pytest
    from dirty_equals import IsDict
    from fastapi.testclient import TestClient
    
    
    @pytest.fixture(name="client")
    def get_client():
        from docs_src.request_form_models.tutorial001_an import app
    
        client = TestClient(app)
        return client
    
    
    def test_post_body_form(client: TestClient):
        response = client.post("/login/", data={"username": "Foo", "password": "secret"})
        assert response.status_code == 200
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Thu Sep 05 15:16:50 UTC 2024
    - 7.4K bytes
    - Viewed (0)
  8. tests/test_tutorial/test_dependencies/test_tutorial008b_an.py

    from fastapi.testclient import TestClient
    
    from docs_src.dependencies.tutorial008b_an import app
    
    client = TestClient(app)
    
    
    def test_get_no_item():
        response = client.get("/items/foo")
        assert response.status_code == 404, response.text
        assert response.json() == {"detail": "Item not found"}
    
    
    def test_owner_error():
        response = client.get("/items/plumbus")
        assert response.status_code == 400, response.text
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Tue Dec 26 20:37:34 UTC 2023
    - 700 bytes
    - Viewed (0)
  9. docs_src/background_tasks/tutorial002_an_py310.py

    app = FastAPI()
    
    
    def write_log(message: str):
        with open("log.txt", mode="a") as log:
            log.write(message)
    
    
    def get_query(background_tasks: BackgroundTasks, q: str | None = None):
        if q:
            message = f"found query: {q}\n"
            background_tasks.add_task(write_log, message)
        return q
    
    
    @app.post("/send-notification/{email}")
    async def send_notification(
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sat Mar 18 12:29:59 UTC 2023
    - 683 bytes
    - Viewed (0)
  10. tests/test_openapi_route_extensions.py

    app = FastAPI()
    
    
    @app.get("/", openapi_extra={"x-custom-extension": "value"})
    def route_with_extras():
        return {}
    
    
    client = TestClient(app)
    
    
    def test_get_route():
        response = client.get("/")
        assert response.status_code == 200, response.text
        assert response.json() == {}
    
    
    def test_openapi():
        response = client.get("/openapi.json")
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Fri Jun 30 18:25:16 UTC 2023
    - 1.1K bytes
    - Viewed (0)
Back to top