Commit Graph

39 Commits

Author SHA1 Message Date
Marcelo Trylesinski 5ccbc62175
Pin httpx in `full` extra (#2773) 2024-11-30 10:53:55 +01:00
Joel Sleppy fe46d99d92
Support `request.url_for` when only "app" scope is avaialable (#2672)
* Support request.url_for in BaseMiddleware

* Move test to test_requests

* Call the endpoint properly

* fix test

* order the type hint

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-09-29 09:40:23 +00:00
Orenoid 4fbf766b3e
test: add tests in `test_requests` (#2677)
* test: add tests in test_requests

* test: add test for Request.close method

* fix: typo

* test: ignore conditional branch in coverage report and remove unnecessary test

* test: pragma no branch

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-09-23 18:38:19 +00:00
Scirlat Danut 78fcd54c07
Create types module inside tests (#2502)
* Create types module inside tests

* Apply suggestions from code review

* Apply suggestions from code review

* Fix check errors

* Change testclientfactory due to autotest

* No cover fix

* Apply suggestions from code review

* Skip code coverage for TestClientFactory protocol

* Apply suggestions from code review

* Small improvements

* Lint

* Fix everything

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-07-27 03:31:16 -06:00
Godot 5f57ef4eb1
test: refine the test of client disconnection after reading request body (#2639)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-07-20 09:06:30 +00:00
Marcelo Trylesinski bd77d7d9f0
Enforce `__future__.annotations` (#2483) 2024-02-29 10:16:42 +00:00
Scirlat Danut 8c222960ba
Add type hints to `test_requests.py` (#2481)
* added type annotations to test_requests.py

* requested changes

* indentations

* typos

* typos

* Apply suggestions from code review

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-06 13:18:43 -07:00
Viicos 7c8ca17773
Use mypy `strict` (#2180)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-07-23 15:41:50 -06:00
Adrian Garcia Badaracco 554b9e21f6
Reuse Request's body buffer for call_next in BaseHTTPMiddleware (#1692) 2023-06-01 13:57:28 -05:00
Adrian Garcia Badaracco c568b55dff
allow using Request.form() as a context manager (#1903)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-02-06 05:58:21 +00:00
Marcelo Trylesinski 6765502c1e
Replace HTTP client on TestClient from `requests` to `httpx` (#1376) 2022-09-06 07:43:32 +02:00
Marcelo Trylesinski d425c84b10
Skip test when brotli is installed (#1620)
* Skip test when brotli is installed

* A better reason message
2022-05-05 11:04:10 +02:00
Adrian Garcia Badaracco 6182d0a0bc
fix handling of scope's client in Request (#1462) 2022-02-01 05:55:35 -06:00
Marcelo Trylesinski 87641dc8e7
Add `raw_path` to `TestClient` scope (#1445)
* Add "raw_path" to TestClient request scope

* Return raw_path as byte string

According to ASGI spec [0], connection scope's `raw_path` should be a
byte string.

[0] https://asgi.readthedocs.io/en/latest/specs/www.html#connection-scope

Co-authored-by: Justas Trimailovas <j.trimailovas@gmail.com>
2022-01-31 10:31:40 +01:00
Thomas Grainger d222b87cb4
TestClient accepts backend and backend_options as arguments to constructor (#1211)
as opposed to ClassVar assignment 

Co-authored-by: Jamie Hewland <jhewland@gmail.com>
Co-authored-by: Jordan Speicher <jordan@jspeicher.com>
Co-authored-by: Jordan Speicher <uSpike@users.noreply.github.com>
2021-06-28 21:36:13 +01:00
Jordan Speicher 42592d68e5
anyio integration (#1157)
* First whack at anyio integration

* Fix formatting

* Remove debug messages

* mypy fixes

* Update README.md

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Fix install_requires typo

* move_on_after blocks if deadline is too small

* Linter fixes

* Improve WSGI structured concurrency

* Tests use anyio

* Checkin progress on testclient

* Prep for anyio 3

* Remove debug backend option

* Use anyio 3.0.0rc1

* Remove old style executor from GraphQLApp

* Fix extra import

* Don't cancel task scope early

* Wait for wsgi sender to finish before exiting

* Use memory object streams in websocket tests

* Test on asyncio, asyncio+uvloop, and trio

* Formatting fixes

* run_until_first_complete doesn't need a return

* Fix middleware app call

* Simplify middleware exceptions

* Use anyio for websocket test

* Set STARLETTE_TESTCLIENT_ASYNC_BACKEND in tests

* Pass async backend to portal

* Formatting fixes

* Bump anyio

* Cleanup portals and add TestClient.async_backend

* Use anyio.run_async_from_thread to send from worker thread

* Use websocket_connect as context manager

* Document changes in TestClient

* Formatting fix

* Fix websocket raises coverage

* Update to anyio 3.0.0rc3 and replace aiofiles

* Apply suggestions from code review

Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>

* Bump to require anyio 3.0.0 final

* Remove mention of aiofiles in README.md

* Pin jinja2 to releases before 3 due to DeprecationWarnings

* Add task_group as application attribute

* Remove run_until_first_complete

* Undo jinja pin

* Refactor anyio.sleep into an event

* Use one less task in test_websocket_concurrency_pattern

* Apply review suggestions

* Rename argument

* fix start_task_soon type

* fix BaseHTTPMiddleware when used without Starlette

* Testclient receive() is a non-trapping function if the response is already complete

This allows for a zero deadline when waiting for a disconnect message

* Use variable annotation for async_backend

* Update docs regarding dependency on anyio

* Use CancelScope instead of move_on_after in request.is_disconnected

* Cancel task group after returning middleware response

Add test for https://github.com/encode/starlette/issues/1022

* Add link to anyio backend options in testclient docs

* Add types-dataclasses

* Re-implement starlette.concurrency.run_until_first_complete and add a test

* Fix type on handler callable

* Apply review comments to clarify run_until_first_complete scope

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
2021-06-18 15:48:43 +01:00
Jamie Hewland b95acea973
Update CI scripts to match httpcore (#1043)
* Update CI scripts to match httpcore

* Run test suite on pushes to master

* Update scripts README

* Don't bother with flake8 extensions for now

* Remove unnecessary PYTHONPATH from build, publish

* test_routing: Use a stub app instead of ellipsis

* Add link to issue about type-checking tests
2020-09-06 12:08:07 +02:00
Erik 773fe0a353
Switch to a more lenient cookie parsing method (#900)
* ADd failing test representing cookie parsing failing

* Add tests inspired by tornado test suite

* Modify requests.cookies to utilize new cookie parsing strategy
2020-04-23 09:32:45 +01:00
Aviram Hassan 73225c3acc
Update tests/test_requests.py
@florimondmanca better test

Co-Authored-By: Florimond Manca <florimond.manca@gmail.com>
2020-03-18 10:33:30 +02:00
Aviram Hassan c63f22fecb ignore malformed cookie instead of raising an exception 2020-03-18 10:00:30 +02:00
Jeremy Lainé a46747377b Add support for server push
This adds support for HTTP/2 and HTTP/3 server push by adding a
Request.send_push_promise method, which signals to push-enabled
servers that a push should be sent.
2019-09-02 14:01:30 +02:00
Tom Christie 99057dd538 request.scope and request.state 2019-06-19 10:08:19 +01:00
Didip Kerabat 93bf4f3f92 Address some PR feedbacks. 2019-06-17 07:29:49 -07:00
Didip Kerabat c85c13d229 Applying linter. 2019-06-17 05:56:29 -07:00
Didip Kerabat 0d6bf72a6d More tests and yet it is still 99%. 2019-06-16 09:18:38 -07:00
Didip Kerabat 5f5d0188af Added more tests on State object. 2019-06-16 08:38:48 -07:00
Didip Kerabat 81b0089ab6 Begin work in making sure `request.state` is preserved between middlewares. 2019-06-15 17:22:50 -07:00
Tom Christie 4d5708e468
ASGI 3 (#435)
* TestClient supports ASGI2 and ASGI3

* Starlette instances present ASGI3 interface

* ServerErrorMiddleware presents ASGI3 interface

* Use ASGI3 protocol throughout

* Response signatures match ASGI interface.
2019-03-19 16:03:19 +00:00
Tom Christie 82c610559c
Request state (#404)
* Add Mount(routes=...)

* Lifespan route instance

* Lifespan as a standard routing component

* Linting

* Linting

* Version 0.10.6

* Release notes

* Version 0.11.0

* Drop redundant import

* Drop redundant database requirements

* Include htmlcov in scripts/clean

* Drop redundant import

* Release notes

* Linting

* Add request.state
2019-02-19 13:14:53 +00:00
Tom Christie 10b61f6cc2
Multi item form data (#339)
* Add a multidict FormData structure
2019-01-22 19:47:47 +00:00
Tom Christie c220994eb1
Add `request.is_disconnected()` (#320)
* Add request.is_disconnected()

* Add request.is_disconnected
2019-01-15 09:59:59 +00:00
Tom Christie a2613494a4
Add request.client (#272)
* Add request.client

* Docs for request.client
2018-12-14 09:58:27 +00:00
Shen Li 80369c1b85 add tests for chunked requests (#235) 2018-11-23 08:56:37 +00:00
Tom Christie 98fa5598de Tweak test case 2018-11-16 13:52:05 +00:00
supriyo-biswas 1e4ce58ec7 Fix incorrect decoding of application/x-www-form-urlencoded request body (#217)
* Fix incorrect decoding of application/x-www-form-urlencoded request body.

* Add test for URLencoded forms.
2018-11-16 13:51:14 +00:00
Tom Christie bcf876c686
Use isort for consistent import ordering (#156) 2018-10-29 14:46:42 +00:00
Jordan Eremieff d1ba5d6722 Cookies (#86)
* Initial cookies support for response/request classes

* Type hint

* Drop .get_cookie() from request class
2018-10-06 13:08:16 +01:00
Tom Christie 94044e5991
Tweaks to URL datastructure (#81)
* Tweaks to URL datastructure

* Linting
2018-10-05 11:29:06 +01:00
Tom Christie 78d1829758
Version 0.3 (#57)
* Renamings

* Version 0.3.0

* Black formatting

* Update docs for 0.3
2018-09-05 11:39:38 +01:00