]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Update references to Requests for tests to HTTPX, and add HTTPX to extras (#5628)
authorSebastián Ramírez <tiangolo@gmail.com>
Sun, 13 Nov 2022 15:20:05 +0000 (16:20 +0100)
committerGitHub <noreply@github.com>
Sun, 13 Nov 2022 15:20:05 +0000 (16:20 +0100)
39 files changed:
README.md
docs/az/docs/index.md
docs/de/docs/features.md
docs/de/docs/index.md
docs/en/docs/advanced/async-tests.md
docs/en/docs/advanced/openapi-callbacks.md
docs/en/docs/alternatives.md
docs/en/docs/features.md
docs/en/docs/index.md
docs/en/docs/tutorial/testing.md
docs/es/docs/features.md
docs/es/docs/index.md
docs/fa/docs/index.md
docs/fr/docs/index.md
docs/he/docs/index.md
docs/id/docs/index.md
docs/it/docs/index.md
docs/ja/docs/features.md
docs/ja/docs/index.md
docs/ja/docs/tutorial/testing.md
docs/ko/docs/index.md
docs/nl/docs/index.md
docs/pl/docs/index.md
docs/pt/docs/features.md
docs/pt/docs/index.md
docs/ru/docs/features.md
docs/ru/docs/index.md
docs/sq/docs/index.md
docs/sv/docs/index.md
docs/tr/docs/features.md
docs/tr/docs/index.md
docs/uk/docs/index.md
docs/zh/docs/features.md
docs/zh/docs/index.md
pyproject.toml
tests/test_security_http_basic_optional.py
tests/test_security_http_basic_realm.py
tests/test_security_http_basic_realm_description.py
tests/test_tutorial/test_security/test_tutorial006.py

index fe0ad49de1bec2045776f934a1237915b2fad4a4..7c4a6c4b4f344ba9d5bb5a115c0247b4ffc85b1f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -427,7 +427,7 @@ For a more complete example including more features, see the <a href="https://fa
 * **GraphQL** integration with <a href="https://strawberry.rocks" class="external-link" target="_blank">Strawberry</a> and other libraries.
 * Many extra features (thanks to Starlette) as:
     * **WebSockets**
-    * extremely easy tests based on `requests` and `pytest`
+    * extremely easy tests based on HTTPX and `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...and more.
@@ -447,7 +447,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index 3129f9dc6dc33ec9aa7def54d4edad90784b707a..282c150322ef98dbf61fc75c62b9e471587a098a 100644 (file)
@@ -446,7 +446,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index f825472a9a9404c2c8f37d085549db378a16d2dd..f281afd1edc5b71741c262bc718de4588ea0b73d 100644 (file)
@@ -169,7 +169,7 @@ Mit **FastAPI** bekommen Sie viele von **Starlette**'s Funktionen (da FastAPI nu
 * **WebSocket**-Unterstützung.
 * Hintergrundaufgaben im selben Prozess.
 * Ereignisse für das Starten und Herunterfahren.
-* Testclient basierend auf `requests`.
+* Testclient basierend auf HTTPX.
 * **CORS**, GZip, statische Dateien, Antwortfluss.
 * **Sitzungs und Cookie** Unterstützung.
 * 100% Testabdeckung.
index 07f51b1be79771b45db7c01e8d77bf0e6c34fe02..68fc8b753ad61cbabcc137c8a210971a35e48152 100644 (file)
@@ -445,7 +445,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index e34f48f1732faa8ec04cdd7ec91e00596163fe02..9b39d70fca6a8e82257282598ab87b41224fa4b4 100644 (file)
@@ -1,6 +1,6 @@
 # Async Tests
 
-You have already seen how to test your **FastAPI** applications using the provided `TestClient`, but with it, you can't test or run any other `async` function in your (synchronous) pytest functions.
+You have already seen how to test your **FastAPI** applications using the provided `TestClient`. Up to now, you have only seen how to write synchronous tests, without using `async` functions.
 
 Being able to use asynchronous functions in your tests could be useful, for example, when you're querying your database asynchronously. Imagine you want to test sending requests to your FastAPI application and then verify that your backend successfully wrote the correct data in the database, while using an async database library.
 
@@ -8,7 +8,7 @@ Let's look at how we can make that work.
 
 ## pytest.mark.anyio
 
-If we want to call asynchronous functions in our tests, our test functions have to be asynchronous. Anyio provides a neat plugin for this, that allows us to specify that some test functions are to be called asynchronously.
+If we want to call asynchronous functions in our tests, our test functions have to be asynchronous. AnyIO provides a neat plugin for this, that allows us to specify that some test functions are to be called asynchronously.
 
 ## HTTPX
 
@@ -16,13 +16,7 @@ Even if your **FastAPI** application uses normal `def` functions instead of `asy
 
 The `TestClient` does some magic inside to call the asynchronous FastAPI application in your normal `def` test functions, using standard pytest. But that magic doesn't work anymore when we're using it inside asynchronous functions. By running our tests asynchronously, we can no longer use the `TestClient` inside our test functions.
 
-Luckily there's a nice alternative, called <a href="https://www.python-httpx.org/" class="external-link" target="_blank">HTTPX</a>.
-
-HTTPX is an HTTP client for Python 3 that allows us to query our FastAPI application similarly to how we did it with the `TestClient`.
-
-If you're familiar with the <a href="https://requests.readthedocs.io/en/master/" class="external-link" target="_blank">Requests</a> library, you'll find that the API of HTTPX is almost identical.
-
-The important difference for us is that with HTTPX we are not limited to synchronous, but can also make asynchronous requests.
+The `TestClient` is based on <a href="https://www.python-httpx.org" class="external-link" target="_blank">HTTPX</a>, and luckily, we can use it directly to test the API.
 
 ## Example
 
@@ -85,7 +79,7 @@ This is the equivalent to:
 response = client.get('/')
 ```
 
-that we used to make our requests with the `TestClient`.
+...that we used to make our requests with the `TestClient`.
 
 !!! tip
     Note that we're using async/await with the new `AsyncClient` - the request is asynchronous.
index 656ddbb3f5abe0142156343fbac0038a86050d53..71924ce8b20486e8b1928ce113d11e184542e177 100644 (file)
@@ -50,7 +50,7 @@ It could be just one or two lines of code, like:
 
 ```Python
 callback_url = "https://example.com/api/v1/invoices/events/"
-requests.post(callback_url, json={"description": "Invoice paid", "paid": True})
+httpx.post(callback_url, json={"description": "Invoice paid", "paid": True})
 ```
 
 But possibly the most important part of the callback is making sure that your API user (the external developer) implements the *external API* correctly, according to the data that *your API* is going to send in the request body of the callback, etc.
@@ -64,7 +64,7 @@ This example doesn't implement the callback itself (that could be just a line of
 !!! tip
     The actual callback is just an HTTP request.
 
-    When implementing the callback yourself, you could use something like <a href="https://www.encode.io/httpx/" class="external-link" target="_blank">HTTPX</a> or <a href="https://requests.readthedocs.io/" class="external-link" target="_blank">Requests</a>.
+    When implementing the callback yourself, you could use something like <a href="https://www.python-httpx.org" class="external-link" target="_blank">HTTPX</a> or <a href="https://requests.readthedocs.io/" class="external-link" target="_blank">Requests</a>.
 
 ## Write the callback documentation code
 
index bcd406bf9d50e9e0a06987a7617edbd4b2e69240..0f074ccf32dccf837a76079671fc549691c1d20e 100644 (file)
@@ -367,7 +367,7 @@ It has:
 * WebSocket support.
 * In-process background tasks.
 * Startup and shutdown events.
-* Test client built on requests.
+* Test client built on HTTPX.
 * CORS, GZip, Static Files, Streaming responses.
 * Session and Cookie support.
 * 100% test coverage.
index 02bb3ac1f232273903852f86978c11b72bb340a5..387ff86c992344376eef1839dd03f5efc5317b1f 100644 (file)
@@ -166,7 +166,7 @@ With **FastAPI** you get all of **Starlette**'s features (as FastAPI is just Sta
 * **WebSocket** support.
 * In-process background tasks.
 * Startup and shutdown events.
-* Test client built on `requests`.
+* Test client built on HTTPX.
 * **CORS**, GZip, Static Files, Streaming responses.
 * **Session and Cookie** support.
 * 100% test coverage.
index 1ad9c760683ad4e851467dc9ac3eff6cf0ea4380..deb8ab5d54312adc729d9a8fc67ff5654fad7037 100644 (file)
@@ -424,7 +424,7 @@ For a more complete example including more features, see the <a href="https://fa
 * **GraphQL** integration with <a href="https://strawberry.rocks" class="external-link" target="_blank">Strawberry</a> and other libraries.
 * Many extra features (thanks to Starlette) as:
     * **WebSockets**
-    * extremely easy tests based on `requests` and `pytest`
+    * extremely easy tests based on HTTPX and `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...and more.
@@ -444,7 +444,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index d2ccd7dc77d45a8098a97cb98b502ff3efa8b120..be07aab37dc34528a7f50a783d9b303257f7acc0 100644 (file)
@@ -2,16 +2,16 @@
 
 Thanks to <a href="https://www.starlette.io/testclient/" class="external-link" target="_blank">Starlette</a>, testing **FastAPI** applications is easy and enjoyable.
 
-It is based on <a href="https://requests.readthedocs.io" class="external-link" target="_blank">Requests</a>, so it's very familiar and intuitive.
+It is based on <a href="https://www.python-httpx.org" class="external-link" target="_blank">HTTPX</a>, which in turn is designed based on Requests, so it's very familiar and intuitive.
 
 With it, you can use <a href="https://docs.pytest.org/" class="external-link" target="_blank">pytest</a> directly with **FastAPI**.
 
 ## Using `TestClient`
 
 !!! info
-    To use `TestClient`, first install <a href="https://github.com/psf/requests" class="external-link" target="_blank">`requests`</a>.
+    To use `TestClient`, first install <a href="https://www.python-httpx.org" class="external-link" target="_blank">`httpx`</a>.
 
-    E.g. `pip install requests`.
+    E.g. `pip install httpx`.
 
 Import `TestClient`.
 
@@ -19,7 +19,7 @@ Create a `TestClient` by passing your **FastAPI** application to it.
 
 Create functions with a name that starts with `test_` (this is standard `pytest` conventions).
 
-Use the `TestClient` object the same way as you do with `requests`.
+Use the `TestClient` object the same way as you do with `httpx`.
 
 Write simple `assert` statements with the standard Python expressions that you need to check (again, standard `pytest`).
 
@@ -130,7 +130,7 @@ You could then update `test_main.py` with the extended tests:
 {!> ../../../docs_src/app_testing/app_b/test_main.py!}
 ```
 
-Whenever you need the client to pass information in the request and you don't know how to, you can search (Google) how to do it in `requests`.
+Whenever you need the client to pass information in the request and you don't know how to, you can search (Google) how to do it in `httpx`, or even how to do it with `requests`, as HTTPX's design is based on Requests' design.
 
 Then you just do the same in your tests.
 
@@ -142,7 +142,7 @@ E.g.:
 * To pass *headers*, use a `dict` in the `headers` parameter.
 * For *cookies*, a `dict` in the `cookies` parameter.
 
-For more information about how to pass data to the backend (using `requests` or the `TestClient`) check the <a href="https://requests.readthedocs.io" class="external-link" target="_blank">Requests documentation</a>.
+For more information about how to pass data to the backend (using `httpx` or the `TestClient`) check the <a href="https://www.python-httpx.org" class="external-link" target="_blank">HTTPX documentation</a>.
 
 !!! info
     Note that the `TestClient` receives data that can be converted to JSON, not Pydantic models.
index 3c59eb88c07371a3afcfc9fb250fa886a015bdfc..5d6b6509a715f15c873a54f9ec521b392b8bfaff 100644 (file)
@@ -167,7 +167,7 @@ Con **FastAPI** obtienes todas las características de **Starlette** (porque Fas
 * Soporte para **GraphQL**.
 * <abbr title="En español: tareas que se ejecutan en el fondo, sin frenar requests, en el mismo proceso. En ingles: In-process background tasks">Tareas en background</abbr>.
 * Eventos de startup y shutdown.
-* Cliente de pruebas construido con `requests`.
+* Cliente de pruebas construido con HTTPX.
 * **CORS**, GZip, Static Files, Streaming responses.
 * Soporte para **Session and Cookie**.
 * Cobertura de pruebas al 100%.
index aa3fa222809398457a3039e317845a87b3b36e43..727a6617b507f178caabda5873ed194909228fb6 100644 (file)
@@ -418,7 +418,7 @@ Para un ejemplo más completo que incluye más características ve el <a href="h
 * Muchas características extra (gracias a Starlette) como:
     * **WebSockets**
     * **GraphQL**
-    * pruebas extremadamente fáciles con `requests` y `pytest`
+    * pruebas extremadamente fáciles con HTTPX y `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...y mucho más.
@@ -438,7 +438,7 @@ Usadas por Pydantic:
 
 Usados por Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Requerido si quieres usar el `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Requerido si quieres usar el `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Requerido si quieres usar la configuración por defecto de templates.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Requerido si quieres dar soporte a  <abbr title="convertir el string que viene de un HTTP request a datos de Python">"parsing"</abbr> de formularios, con `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Requerido para dar soporte a `SessionMiddleware`.
index 0f7cd569aec1ed3163152e366dc421387b25cd03..dfc4d24e33c7b7a1fd7b3d1a55c8e23cba86ff80 100644 (file)
@@ -421,7 +421,7 @@ item: Item
 * قابلیت‌های اضافی دیگر (بر اساس Starlette) شامل:
     * **<abbr title="WebSocket">وب‌سوکت</abbr>**
     * **GraphQL**
-    * تست‌های خودکار آسان مبتنی بر `requests` و `pytest`
+    * تست‌های خودکار آسان مبتنی بر HTTPX و `pytest`
     * **CORS**
     * **Cookie Sessions**
     * و موارد بیشمار دیگر.
@@ -441,7 +441,7 @@ item: Item
 
 استفاده شده توسط Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - در صورتی که می‌خواهید از `TestClient` استفاده کنید.
+* <a href="https://www.python-httpx.org" target="_blank"><code>HTTPX</code></a> - در صورتی که می‌خواهید از `TestClient` استفاده کنید.
 * <a href="https://github.com/Tinche/aiofiles" target="_blank"><code>aiofiles</code></a> - در صورتی که می‌خواهید از `FileResponse` و `StaticFiles` استفاده کنید.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - در صورتی که بخواهید از پیکربندی پیش‌فرض برای قالب‌ها استفاده کنید.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - در صورتی که بخواهید با استفاده از `request.form()` از قابلیت <abbr title="تبدیل رشته متنی موجود در درخواست HTTP به انواع داده پایتون">"تجزیه (parse)"</abbr> فرم استفاده کنید.
index 69520445889cf058539f1e43be7ff9b69869783c..e7fb9947d5ad0134732bc8aa280b253bfc809c76 100644 (file)
@@ -426,7 +426,7 @@ For a more complete example including more features, see the <a href="https://fa
 * Many extra features (thanks to Starlette) as:
     * **WebSockets**
     * **GraphQL**
-    * extremely easy tests based on `requests` and `pytest`
+    * extremely easy tests based on HTTPX and `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...and more.
@@ -446,7 +446,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>HTTPX</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index fa63d8cb7cf8fa48c7c306087850f7fb83c899e0..19f2f204134a877a92f8820f97874267fb012b0d 100644 (file)
@@ -445,7 +445,7 @@ item: Item
 
 בשימוש Starlette:
 
--   <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - דרוש אם ברצונכם להשתמש ב - `TestClient`.
+-   <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - דרוש אם ברצונכם להשתמש ב - `TestClient`.
 -   <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - דרוש אם ברצונכם להשתמש בברירת המחדל של תצורת הטמפלייטים.
 -   <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - דרוש אם ברצונכם לתמוך ב <abbr title="המרת המחרוזת שמגיעה מבקשת HTTP למידע פייתון">"פרסור"</abbr> טפסים, באצמעות <code dir="ltr">request.form()</code>.
 -   <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - דרוש אם ברצונכם להשתמש ב - `SessionMiddleware`.
index 3129f9dc6dc33ec9aa7def54d4edad90784b707a..66fc2859e7dda61e30bcec756b5934c24e5ab92b 100644 (file)
@@ -426,7 +426,7 @@ For a more complete example including more features, see the <a href="https://fa
 * Many extra features (thanks to Starlette) as:
     * **WebSockets**
     * **GraphQL**
-    * extremely easy tests based on `requests` and `pytest`
+    * extremely easy tests based on HTTPX and `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...and more.
@@ -446,7 +446,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index 852a5e56e82b5a3a252fc86e1cb6bbcafaba7bd3..9d95dd6d720fde5380b70915c66415cb66ab1553 100644 (file)
@@ -423,7 +423,7 @@ For a more complete example including more features, see the <a href="https://fa
 * Many extra features (thanks to Starlette) as:
     * **WebSockets**
     * **GraphQL**
-    * extremely easy tests based on `requests` and `pytest`
+    * extremely easy tests based on HTTPX and `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...and more.
@@ -443,7 +443,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index 5ea68515da35bb3faba37c6190e6e20cba0e64d2..a40b48cf0ed8fda1780e5593f91e384119d857f7 100644 (file)
@@ -169,7 +169,7 @@ FastAPIには非常に使いやすく、非常に強力な<abbr title='also know
 * **GraphQL**のサポート
 * プロセス内バックグラウンドタスク
 * 起動およびシャットダウンイベント
-* `requests`に基づいて構築されたテストクライアント
+* `httpx`に基づいて構築されたテストクライアント
 * **CORS**、GZip、静的ファイル、ストリーミング応答
 * **セッションとCookie**のサポート
 * テストカバレッジ100%
index 177a78786cb39f2e9705160542733685178de057..f3a159f70026add3deca8851351f1d9173e48007 100644 (file)
@@ -416,7 +416,7 @@ item: Item
 - 以下のようなたくさんのおまけ機能(Starlette のおかげです):
   - **WebSockets**
   - **GraphQL**
-  - `requests` や `pytest`をもとにした極限に簡単なテスト
+  - `httpx` や `pytest`をもとにした極限に簡単なテスト
   - **CORS**
   - **クッキーセッション**
   - ...などなど。
@@ -436,7 +436,7 @@ Pydantic によって使用されるもの:
 
 Starlette によって使用されるもの:
 
-- <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - `TestClient`を使用するために必要です。
+- <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - `TestClient`を使用するために必要です。
 - <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - デフォルトのテンプレート設定を使用する場合は必要です。
 - <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>`request.form()`からの変換をサポートしたい場合は必要です。
 - <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - `SessionMiddleware` サポートのためには必要です。
index 03b0e1deef3591dce114ee69fb27f6c236449993..56f5cabac84931d4c00166205f152f6d5f37a777 100644 (file)
@@ -2,7 +2,7 @@
 
 <a href="https://www.starlette.io/testclient/" class="external-link" target="_blank">Starlette</a> のおかげで、**FastAPI** アプリケーションのテストは簡単で楽しいものになっています。
 
-<a href="http://docs.python-requests.org" class="external-link" target="_blank">Requests</a> がベースなので、非常に使いやすく直感的です。
+<a href="https://www.python-httpx.org" class="external-link" target="_blank">HTTPX</a> がベースなので、非常に使いやすく直感的です。
 
 これを使用すると、**FastAPI** と共に <a href="https://docs.pytest.org/" class="external-link" target="_blank">pytest</a> を直接利用できます。
 
@@ -14,7 +14,7 @@
 
 `test_` から始まる名前の関数を作成します (これは `pytest` の標準的なコンベンションです)。
 
-`requests` と同じ様に `TestClient` オブジェクトを使用します。
+`httpx` と同じ様に `TestClient` オブジェクトを使用します。
 
 チェックしたい Python の標準的な式と共に、シンプルに `assert` 文を記述します。
 
@@ -94,7 +94,7 @@
 {!> ../../../docs_src/app_testing/app_b/test_main.py!}
 ```
 
-リクエストに情報を渡せるクライアントが必要で、その方法がわからない場合はいつでも、`requests` での実現方法を検索 (Google) できます。
+リクエストに情報を渡せるクライアントが必要で、その方法がわからない場合はいつでも、`httpx` での実現方法を検索 (Google) できます。
 
 テストでも同じことを行います。
 
 * *ヘッダー* を渡すには、`headers` パラメータに `dict` を渡します。
 * *cookies* の場合、 `cookies` パラメータに `dict` です。
 
-(`requests` または `TestClient` を使用して) バックエンドにデータを渡す方法の詳細は、<a href="http://docs.python-requests.org" class="external-link" target="_blank">Requestsのドキュメント</a>を確認してください。
+(`httpx` または `TestClient` を使用して) バックエンドにデータを渡す方法の詳細は、<a href="https://www.python-httpx.org" class="external-link" target="_blank">HTTPXのドキュメント</a>を確認してください。
 
 !!! info "情報"
     `TestClient` は、Pydanticモデルではなく、JSONに変換できるデータを受け取ることに注意してください。
index 6d35afc47f28253988050cb30747c0783b7bba49..c64713705b13ea9ede5235d6bd91d7462de447d8 100644 (file)
@@ -422,7 +422,7 @@ item: Item
 * (Starlette 덕분에) 많은 추가 기능:
     * **웹 소켓**
     * **GraphQL**
-    * `requests` 및 `pytest`에 기반한 극히 쉬운 테스트
+    * HTTPX 및 `pytest`에 기반한 극히 쉬운 테스트
     * **CORS**
     * **쿠키 세션**
     * ...기타 등등.
@@ -442,7 +442,7 @@ Pydantic이 사용하는:
 
 Starlette이 사용하는:
 
-* <a href="http://docs.python-requests.org" target="_blank"><code>requests</code></a> - `TestClient`를 사용하려면 필요.
+* <a href="https://www.python-httpx.org" target="_blank"><code>HTTPX</code></a> - `TestClient`를 사용하려면 필요.
 * <a href="http://jinja.pocoo.org" target="_blank"><code>jinja2</code></a> - 기본 템플릿 설정을 사용하려면 필요.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - `request.form()`과 함께 <abbr title="HTTP 요청에서 파이썬 데이터로 가는 문자열 변환">"parsing"</abbr>의 지원을 원하면 필요.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - `SessionMiddleware` 지원을 위해 필요.
index fe55f6c1bb3b607189fb515c3a170116f4d4d44a..23143a96fbd82a668e8b1cf5e7a232f8483d1699 100644 (file)
@@ -429,7 +429,7 @@ For a more complete example including more features, see the <a href="https://fa
 * **GraphQL** integration with <a href="https://strawberry.rocks" class="external-link" target="_blank">Strawberry</a> and other libraries.
 * Many extra features (thanks to Starlette) as:
     * **WebSockets**
-    * extremely easy tests based on `requests` and `pytest`
+    * extremely easy tests based on HTTPX and `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...and more.
@@ -449,7 +449,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index 671c235a67098a51fc1039ca4009cd5688d4001c..98e1e82fc2bfa0578adfc4c315582215001114cc 100644 (file)
@@ -420,7 +420,7 @@ Dla bardziej kompletnych przykładów posiadających więcej funkcjonalności, z
 * Wiele dodatkowych funkcji (dzięki Starlette) takie jak:
     * **WebSockety**
     * **GraphQL**
-    * bardzo proste testy bazujące na `requests` oraz `pytest`
+    * bardzo proste testy bazujące na HTTPX oraz `pytest`
     * **CORS**
     * **Sesje cookie**
     * ...i więcej.
@@ -440,7 +440,7 @@ Używane przez Pydantic:
 
 Używane przez Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Wymagane jeżeli chcesz korzystać z `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Wymagane jeżeli chcesz korzystać z `TestClient`.
 * <a href="https://github.com/Tinche/aiofiles" target="_blank"><code>aiofiles</code></a> - Wymagane jeżeli chcesz korzystać z `FileResponse` albo `StaticFiles`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Wymagane jeżeli chcesz używać domyślnej konfiguracji szablonów.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Wymagane jeżelich chcesz wsparcie <abbr title="przetwarzania stringa którzy przychodzi z żądaniem HTTP na dane używane przez Pythona">"parsowania"</abbr> formularzy, używając `request.form()`.
index 2b7836a6f2c2f479114fd42032e9a60c003e7375..bd0db8e76285206bb2e01604c8d2af162aef6e00 100644 (file)
@@ -167,7 +167,7 @@ Com **FastAPI**, você terá todos os recursos do **Starlette** (já que FastAPI
 * Suporte a **GraphQL**.
 * Tarefas em processo _background_.
 * Eventos na inicialização e encerramento.
-* Cliente de testes construído sobre `requests`.
+* Cliente de testes construído sobre HTTPX.
 * Respostas em **CORS**, GZip, Static Files, Streaming.
 * Suporte a **Session e Cookie**.
 * 100% de cobertura de testes.
index ccbb8dba8dbecf3b051b030099036bb4eb48c078..afc101edea5ca1ef5bb7b6b3351fdc8b41f8208f 100644 (file)
@@ -415,7 +415,7 @@ Para um exemplo mais completo incluindo mais recursos, veja <a href="https://fas
 * Muitos recursos extras (graças ao Starlette) como:
     * **WebSockets**
     * **GraphQL**
-    * testes extrememamente fáceis baseados em `requests` e `pytest`
+    * testes extrememamente fáceis baseados em HTTPX e `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...e mais.
@@ -435,7 +435,7 @@ Usados por Pydantic:
 
 Usados por Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Necessário se você quiser utilizar o `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Necessário se você quiser utilizar o `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Necessário se você quiser utilizar a configuração padrão de templates.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Necessário se você quiser suporte com <abbr title="converte uma string que chega de uma requisição HTTP para dados Python">"parsing"</abbr> de formulário, com `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Necessário para suporte a `SessionMiddleware`.
index 0cec4eee2a0129b55bc824c5124075504ecb50bf..e18f7bc87cba5d6c772c35f4a26bb5b17f10bdc9 100644 (file)
@@ -169,7 +169,7 @@ FastAPI включает в себя чрезвычайно простую в и
 * Поддержка **WebSocket**.
 * Фоновые задачи для процессов.
 * События запуска и выключения.
-* Тестовый клиент построен на библиотеке `requests`.
+* Тестовый клиент построен на библиотеке HTTPX.
 * **CORS**, GZip, статические файлы, потоковые ответы.
 * Поддержка **сессий и cookie**.
 * 100% покрытие тестами.
index 24f547ecc0f5919e81d993cd14b1320d5a8c3304..14a6d5a8b96013fb842c70b6871ab97c75af5a1c 100644 (file)
@@ -424,7 +424,7 @@ item: Item
 * **GraphQL** интеграция с <a href="https://strawberry.rocks" class="external-link" target="_blank">Strawberry</a> и другими библиотеками.
 * Множество дополнительных функций (благодаря Starlette), таких как:
     * **Веб-сокеты**
-    * очень простые тесты на основе `requests` и `pytest`
+    * очень простые тесты на основе HTTPX и `pytest`
     * **CORS**
     * **Cookie сеансы(сессии)**
     * ...и многое другое.
@@ -444,7 +444,7 @@ item: Item
 
 Используется Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Обязательно, если вы хотите использовать `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>HTTPX</code></a> - Обязательно, если вы хотите использовать `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Обязательно, если вы хотите использовать конфигурацию шаблона по умолчанию.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Обязательно, если вы хотите поддерживать форму <abbr title="преобразование строки, полученной из HTTP-запроса, в данные Python">"парсинга"</abbr> с помощью `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Обязательно, для поддержки `SessionMiddleware`.
index e799ff8d580e0db09876a7120e4d97493630829f..cff2c280431ddfc2482e8ed81534415bc40fe32f 100644 (file)
@@ -426,7 +426,7 @@ For a more complete example including more features, see the <a href="https://fa
 * Many extra features (thanks to Starlette) as:
     * **WebSockets**
     * **GraphQL**
-    * extremely easy tests based on `requests` and `pytest`
+    * extremely easy tests based on HTTPX and `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...and more.
@@ -446,7 +446,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index fe55f6c1bb3b607189fb515c3a170116f4d4d44a..23143a96fbd82a668e8b1cf5e7a232f8483d1699 100644 (file)
@@ -429,7 +429,7 @@ For a more complete example including more features, see the <a href="https://fa
 * **GraphQL** integration with <a href="https://strawberry.rocks" class="external-link" target="_blank">Strawberry</a> and other libraries.
 * Many extra features (thanks to Starlette) as:
     * **WebSockets**
-    * extremely easy tests based on `requests` and `pytest`
+    * extremely easy tests based on HTTPX and `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...and more.
@@ -449,7 +449,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index 0bcda4e9c7f85ea17bf1cc487160654db5518130..f8220fb58f66bf3ed9c25049c6dee30e5cc57650 100644 (file)
@@ -174,7 +174,7 @@ Bütün entegrasyonlar kullanımı kolay olmak üzere (zorunluluklar ile beraber
 * **GraphQL** desteği.
 * Kullanım halinde arka plan işlevleri.
 * Başlatma ve kapatma eventleri(startup and shutdown).
-* Test sunucusu `requests` üzerine kurulu.
+* Test sunucusu HTTPX üzerine kurulu.
 * **CORS**, GZip, Static dosyalar, Streaming responseları.
 * **Session and Cookie** desteği.
 * 100% test kapsayıcılığı.
index 73caa6d61072c295f8e97d1bf11b7cb79bbd770f..6bd30d7091371a9367f7850206f361aa7d6c66cf 100644 (file)
@@ -434,7 +434,7 @@ Daha fazla örnek ve özellik için <a href="https://fastapi.tiangolo.com/tutori
 * Diğer ekstra özellikler (Starlette sayesinde):
     * **WebSockets**
     * **GraphQL**
-    * `requests` ve `pytest` sayesinde aşırı kolay testler.
+    * HTTPX ve `pytest` sayesinde aşırı kolay testler.
     * **CORS**
     * **Cookie Sessions**
     * ...ve daha fazlası.
@@ -454,7 +454,7 @@ Pydantic tarafında kullanılan:
 
 Starlette tarafında kullanılan:
 
-* <a href="http://docs.python-requests.org" target="_blank"><code>requests</code></a> - Eğer `TestClient` kullanmak istiyorsan gerekli.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Eğer `TestClient` kullanmak istiyorsan gerekli.
 * <a href="http://jinja.pocoo.org" target="_blank"><code>jinja2</code></a> - Eğer kendine ait template konfigürasyonu oluşturmak istiyorsan gerekli
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Form kullanmak istiyorsan gerekli <abbr title="HTTP bağlantısından gelen stringi Python objesine çevirmek için">("dönüşümü")</abbr>.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - `SessionMiddleware` desteği için gerekli.
index e799ff8d580e0db09876a7120e4d97493630829f..cff2c280431ddfc2482e8ed81534415bc40fe32f 100644 (file)
@@ -426,7 +426,7 @@ For a more complete example including more features, see the <a href="https://fa
 * Many extra features (thanks to Starlette) as:
     * **WebSockets**
     * **GraphQL**
-    * extremely easy tests based on `requests` and `pytest`
+    * extremely easy tests based on HTTPX and `pytest`
     * **CORS**
     * **Cookie Sessions**
     * ...and more.
@@ -446,7 +446,7 @@ Used by Pydantic:
 
 Used by Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - Required if you want to use the `TestClient`.
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - Required if you want to use the `TestClient`.
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - Required if you want to use the default template configuration.
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
index fefe4b1973995c99d9f3d56653a640c95713d277..2db7f852a9e836f140180a33cc4df87f1cfaacd4 100644 (file)
@@ -171,7 +171,7 @@ FastAPI 有一个使用非常简单,但是非常强大的<abbr title='也叫
 * **支持 GraphQL** 。
 * 后台任务处理。
 * Startup 和 shutdown 事件。
-* 测试客户端基于 `requests`
+* 测试客户端基于 HTTPX
 * **CORS**, GZip, 静态文件, 流响应。
 * 支持 **Session 和 Cookie** 。
 * 100% 测试覆盖率。
index 3898beaee06770b357306606d8e660e2e65a0c25..7901e9c2ccd5c018891bd5f66be0eeebcb7b89da 100644 (file)
@@ -422,7 +422,7 @@ item: Item
 * 许多额外功能(归功于 Starlette)比如:
     * **WebSockets**
     * **GraphQL**
-    * 基于 `requests` 和 `pytest` 的极其简单的测试
+    * 基于 HTTPX 和 `pytest` 的极其简单的测试
     * **CORS**
     * **Cookie Sessions**
     * ......以及更多
@@ -442,7 +442,7 @@ item: Item
 
 用于 Starlette:
 
-* <a href="https://requests.readthedocs.io" target="_blank"><code>requests</code></a> - 使用 `TestClient` 时安装。
+* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - 使用 `TestClient` 时安装。
 * <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - 使用默认模板配置时安装。
 * <a href="https://andrew-d.github.io/python-multipart/" target="_blank"><code>python-multipart</code></a> - 需要通过 `request.form()` 对表单进行<abbr title="将来自 HTTP 请求中的字符串转换为 Python 数据类型">「解析」</abbr>时安装。
 * <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - 需要 `SessionMiddleware` 支持时安装。
index fc4602ea8e6cc18cc73e7730aa9a337a340a4ea3..af20c8ef7862e0948475f08bc322c4a08958e609 100644 (file)
@@ -56,7 +56,6 @@ test = [
     "flake8 >=3.8.3,<6.0.0",
     "black == 22.8.0",
     "isort >=5.0.6,<6.0.0",
-    "requests >=2.24.0,<3.0.0",
     "httpx >=0.23.0,<0.24.0",
     "email_validator >=1.1.1,<2.0.0",
     # TODO: once removing databases from tutorial, upgrade SQLAlchemy
@@ -94,7 +93,7 @@ dev = [
     "pre-commit >=2.17.0,<3.0.0",
 ]
 all = [
-    "requests >=2.24.0,<3.0.0",
+    "httpx >=0.23.0,<0.24.0",
     "jinja2 >=2.11.2,<4.0.0",
     "python-multipart >=0.0.5,<0.0.6",
     "itsdangerous >=1.1.0,<3.0.0",
index 289bd5c74cfe513cdbea46d4b448940a3280af8b..91824d22347b7bdf3d6e645e720dc9d6d6e041b0 100644 (file)
@@ -4,7 +4,6 @@ from typing import Optional
 from fastapi import FastAPI, Security
 from fastapi.security import HTTPBasic, HTTPBasicCredentials
 from fastapi.testclient import TestClient
-from requests.auth import HTTPBasicAuth
 
 app = FastAPI()
 
@@ -51,8 +50,7 @@ def test_openapi_schema():
 
 
 def test_security_http_basic():
-    auth = HTTPBasicAuth(username="john", password="secret")
-    response = client.get("/users/me", auth=auth)
+    response = client.get("/users/me", auth=("john", "secret"))
     assert response.status_code == 200, response.text
     assert response.json() == {"username": "john", "password": "secret"}
 
index 54867c2e01b57fa8cb9d612a7c26b6032a90857c..6d760c0f92e2a12be1b82fa5e93f9a2a62ae61f6 100644 (file)
@@ -3,7 +3,6 @@ from base64 import b64encode
 from fastapi import FastAPI, Security
 from fastapi.security import HTTPBasic, HTTPBasicCredentials
 from fastapi.testclient import TestClient
-from requests.auth import HTTPBasicAuth
 
 app = FastAPI()
 
@@ -48,8 +47,7 @@ def test_openapi_schema():
 
 
 def test_security_http_basic():
-    auth = HTTPBasicAuth(username="john", password="secret")
-    response = client.get("/users/me", auth=auth)
+    response = client.get("/users/me", auth=("john", "secret"))
     assert response.status_code == 200, response.text
     assert response.json() == {"username": "john", "password": "secret"}
 
index 6ff9d9d07ff5de85d3a694199728095f00a2343b..7cc5475614ddf1f32df12694a27802794dc2ba20 100644 (file)
@@ -3,7 +3,6 @@ from base64 import b64encode
 from fastapi import FastAPI, Security
 from fastapi.security import HTTPBasic, HTTPBasicCredentials
 from fastapi.testclient import TestClient
-from requests.auth import HTTPBasicAuth
 
 app = FastAPI()
 
@@ -54,8 +53,7 @@ def test_openapi_schema():
 
 
 def test_security_http_basic():
-    auth = HTTPBasicAuth(username="john", password="secret")
-    response = client.get("/users/me", auth=auth)
+    response = client.get("/users/me", auth=("john", "secret"))
     assert response.status_code == 200, response.text
     assert response.json() == {"username": "john", "password": "secret"}
 
index 3b0a36ebca0ad3ef8f8b0ed344a0bbb3b02048d3..bbfef9f7c4d7b84f5b347753737bdd51034f0711 100644 (file)
@@ -1,7 +1,6 @@
 from base64 import b64encode
 
 from fastapi.testclient import TestClient
-from requests.auth import HTTPBasicAuth
 
 from docs_src.security.tutorial006 import app
 
@@ -38,8 +37,7 @@ def test_openapi_schema():
 
 
 def test_security_http_basic():
-    auth = HTTPBasicAuth(username="john", password="secret")
-    response = client.get("/users/me", auth=auth)
+    response = client.get("/users/me", auth=("john", "secret"))
     assert response.status_code == 200, response.text
     assert response.json() == {"username": "john", "password": "secret"}