Commit Graph

22 Commits

Author SHA1 Message Date
Marcelo Trylesinski 99b6938363
Allow to raise `HTTPException` before `websocket.accept()` (#2725)
* Allow to raise `HTTPException` before `websocket.accept()`

* move <<

* Add documentation
2024-10-15 09:50:49 +02:00
Marcelo Trylesinski 1a6018e08a
Support python-multipart 0.0.12 (#2708) 2024-09-29 10:28:34 +02:00
Marcelo Trylesinski b9db010d49
Set `line-length` to 120 on Ruff (#2679)
* Set `line-length` to 120 on Ruff

* Add links to selected rules

* Remove empty strings

* Fix more stuff
2024-09-01 15:11:01 +02: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
Scirlat Danut fce2809f99
Added type annotations to test_exceptions.py (#2479)
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
2024-02-04 18:21:41 +00:00
bowugit 2168e47052
Fix empty str(exception) when initialized with kwargs (#2181)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-06-20 18:35:45 +00:00
Adrian Garcia Badaracco e99738b719
Move exception handling logic to Route (#2026)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-06-07 00:19:32 -06:00
Marcelo Trylesinski d525431aad
Add `WebSocketException` and support for WS handlers (#1263)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-09-05 14:31:59 +02:00
Marcelo Trylesinski 3453fd6b62
Add 400 response when `boundary` is missing (#1617)
* Add 400 response on MultiParser exceptions

* Add 400 response on MultiParser exceptions [2]

* Add tests and remove name from here

* Remove args from exception

* Move `ExceptionMiddleware` to `starlette.middleware.exceptions`

* add test for deprecation shim

Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
2022-05-19 20:33:03 +02:00
Adrian Garcia Badaracco 18398e7ee2
Convert ASGI 2.0 apps in tests to ASGI 3 (#1476) 2022-02-07 08:58:30 -06:00
Marcelo Trylesinski 085639226d
Add `headers` parameter to `HTTPException` (#1435)
* Add `headers` parameter to `HTTPException`

* Update exceptions docs
2022-01-26 16:06:15 +01:00
Marcelo Trylesinski f5d61fe74a
Add test case for `HTTPException` when status code is 204 (#1432) 2022-01-26 10:49:30 +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
Daniel Hahler 32fafb7307 Add HTTPException.__repr__ (#628) 2019-10-15 13:34:49 +01: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 3faded4f26
Remove redundant test cases 2018-11-08 12:33:58 +00:00
Tom Christie 9f3dcb7d2b
Rejig ExceptionMiddleware and ServerErrorMiddleware (#193)
* Rejig ExceptionMiddleware and ServerErrorMiddleware

* Tweak DebugMiddleware implementation

* Support custom 500 handlers

* Exception handling updates
2018-11-08 11:59:15 +00:00
Tom Christie bcf876c686
Use isort for consistent import ordering (#156) 2018-10-29 14:46:42 +00:00
Tom Christie 8da0f00fe7
Routing interface (#144)
* Path -> Route, PathPrefix -> Mount

* Route, WebSocketRoute, Mount

* Use Route(endpoint=...), not Route(app=...)

* Bare minimum docs update

* Add url_for

* request.path_params and session.path_params

* Version 0.6.0
2018-10-29 09:22:45 +00:00
Jordan Eremieff f4fe0ec312 Name changes (#55)
* Rename View -> HTTPEndpoint

* Rename views doc file -> endpoints

* Rename request/response files -> requests/responses, update imports, update docs

* Rename WebSocketSession -> WebSocket, rename session -> websocket in docs

* Full module imports in tests and source, removing imports from __init__ file

* Fix name in testclient doc
2018-09-05 10:29:04 +01:00
Tom Christie 67d95fcfa7
Exception handling (#54)
* Exception handling

* Black formatting

* Add exception handling to App

* Handle cases where exception raised but response already started

* Order exception handler lookup by class inheritance

* Handle 404/405 as responses without App, or exceptions with it.

* Only use TestClient(app, raise_exceptions=False) explicitly inside test cases

* Documentation for ExceptionMiddleware

* Drop error_handler/exception_handler distinction.

* Finesse and document TestClient(app, raise_server_exceptions=False)

* Refactoring to make debug responses easier to obtain from elsewhere in code

* Use named status_code argument in example

* Clean up raise_server_errors usage in tests

* Consistent title-casing in HTTP reason phrases

* Black formatting

* Add WebSocketClose close. Omit message-body on 204, 304 exception cases.

* Black formatting

* Add 'debug' flag to App and ExceptionMiddleware

* Support app.debug

* Document debug mode

* Documenting debug
2018-09-04 11:52:29 +01:00