Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 24 for dependency_overrides (0.3 sec)

  1. tests/test_dependency_overrides.py

    )
    def test_override_simple(url, status_code, expected):
        app.dependency_overrides[common_parameters] = overrider_dependency_simple
        response = client.get(url)
        assert response.status_code == status_code
        assert response.json() == expected
        app.dependency_overrides = {}
    
    
    def test_override_with_sub_main_depends():
        app.dependency_overrides[common_parameters] = overrider_dependency_with_sub
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Thu Apr 18 19:40:57 UTC 2024
    - 15.4K bytes
    - Viewed (0)
  2. docs/en/docs/advanced/testing-dependencies.md

    In this case, you can override the dependency that calls that provider, and use a custom dependency that returns a mock user, only for your tests.
    
    ### Use the `app.dependency_overrides` attribute
    
    For these cases, your **FastAPI** application has an attribute `app.dependency_overrides`, it is a simple `dict`.
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 2.9K bytes
    - Viewed (0)
  3. tests/test_dependency_security_overrides.py

        }
    
    
    def test_override_data():
        app.dependency_overrides[get_data] = get_data_override
        response = client.get("/user")
        assert response.json() == {
            "user": "john",
            "scopes": ["foo", "bar"],
            "data": [3, 4, 5],
        }
        app.dependency_overrides = {}
    
    
    def test_override_security():
        app.dependency_overrides[get_user] = get_user_override
        response = client.get("/user")
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Jun 14 15:54:46 UTC 2020
    - 1.4K bytes
    - Viewed (0)
  4. docs_src/settings/app02/test_main.py

    from .config import Settings
    from .main import app, get_settings
    
    client = TestClient(app)
    
    
    def get_settings_override():
        return Settings(admin_email="******@****.***")
    
    
    app.dependency_overrides[get_settings] = get_settings_override
    
    
    def test_app():
        response = client.get("/info")
        data = response.json()
        assert data == {
            "app_name": "Awesome API",
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Thu Jul 29 09:26:07 UTC 2021
    - 515 bytes
    - Viewed (0)
  5. docs/em/docs/advanced/testing-dependencies.md

    👆 🎲 💚 💯 🔢 🐕‍🦺 🕐, ✋️ 🚫 🎯 🤙 ⚫️ 🔠 💯 👈 🏃.
    
    👉 💼, 👆 💪 🔐 🔗 👈 🤙 👈 🐕‍🦺, & ⚙️ 🛃 🔗 👈 📨 🎁 👩‍💻, 🕴 👆 💯.
    
    ### ⚙️ `app.dependency_overrides` 🔢
    
    👫 💼, 👆 **FastAPI** 🈸 ✔️ 🔢 `app.dependency_overrides`, ⚫️ 🙅 `dict`.
    
    🔐 🔗 🔬, 👆 🚮 🔑 ⏮️ 🔗 (🔢), & 💲, 👆 🔗 🔐 (➕1️⃣ 🔢).
    
    & ⤴️ **FastAPI** 🔜 🤙 👈 🔐 ↩️ ⏮️ 🔗.
    
    ```Python hl_lines="28-29  32"
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 1.7K bytes
    - Viewed (0)
  6. docs/de/docs/advanced/testing-dependencies.md

    ### Verwenden Sie das Attribut `app.dependency_overrides`.
    
    Für diese Fälle verfügt Ihre **FastAPI**-Anwendung über das Attribut `app.dependency_overrides`, bei diesem handelt sich um ein einfaches `dict`.
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 3.5K bytes
    - Viewed (0)
  7. docs/zh/docs/advanced/testing-dependencies.md

    常见实例是调用外部第三方身份验证应用。
    
    向第三方应用发送令牌,然后返回经验证的用户。
    
    但第三方服务商处理每次请求都可能会收费,并且耗时通常也比调用写死的模拟测试用户更长。
    
    一般只要测试一次外部验证应用就够了,不必每次测试都去调用。
    
    此时,最好覆盖调用外部验证应用的依赖项,使用返回模拟测试用户的自定义依赖项就可以了。
    
    ### 使用 `app.dependency_overrides` 属性
    
    对于这些用例,**FastAPI** 应用支持 `app.dependency_overrides` 属性,该属性就是**字典**。
    
    要在测试时覆盖原有依赖项,这个字典的键应当是原依赖项(函数),值是覆盖依赖项(另一个函数)。
    
    这样一来,**FastAPI** 就会调用覆盖依赖项,不再调用原依赖项。
    
    ```Python hl_lines="26-27  30"
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 1.9K bytes
    - Viewed (0)
  8. docs/pt/docs/advanced/testing-dependencies.md

    ### Utilize o atributo `app.dependency_overrides`
    
    Para estes casos, a sua aplicação **FastAPI** possui o atributo `app.dependency_overrides`. Ele é um simples `dict`.
    
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 3.2K bytes
    - Viewed (0)
  9. docs_src/settings/app02_an/test_main.py

    from .config import Settings
    from .main import app, get_settings
    
    client = TestClient(app)
    
    
    def get_settings_override():
        return Settings(admin_email="******@****.***")
    
    
    app.dependency_overrides[get_settings] = get_settings_override
    
    
    def test_app():
        response = client.get("/info")
        data = response.json()
        assert data == {
            "app_name": "Awesome API",
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sat Mar 18 12:29:59 UTC 2023
    - 515 bytes
    - Viewed (0)
  10. docs_src/settings/app02_an_py39/test_main.py

    from .config import Settings
    from .main import app, get_settings
    
    client = TestClient(app)
    
    
    def get_settings_override():
        return Settings(admin_email="******@****.***")
    
    
    app.dependency_overrides[get_settings] = get_settings_override
    
    
    def test_app():
        response = client.get("/info")
        data = response.json()
        assert data == {
            "app_name": "Awesome API",
    Registered: Sun Nov 03 07:19:11 UTC 2024
    - Last Modified: Sat Mar 18 12:29:59 UTC 2023
    - 515 bytes
    - Viewed (0)
Back to top