django / daphne

Django Channels HTTP/WebSocket server
BSD 3-Clause "New" or "Revised" License
2.37k stars 266 forks source link

Set default attributes on WebRequest #406

Closed marcinowski closed 2 years ago

marcinowski commented 2 years ago

Moves the problematic attributes initialization to the init of the WebRequest class to provide the default None values. A regression test checking whether the default values set is also added. Closes #402

Test results:

pytest
=========================================================================================== test session starts ============================================================================================
platform linux -- Python 3.7.4, pytest-7.0.1, pluggy-1.0.0
rootdir: /home/marcin/programming/daphne, configfile: setup.cfg, testpaths: tests
plugins: hypothesis-6.36.2, asyncio-0.18.1
asyncio: mode=legacy
collected 58 items                                                                                                                                                                                         

tests/test_cli.py ............                                                                                                                                                                       [ 20%]
tests/test_http_protocol.py .                                                                                                                                                                        [ 22%]
tests/test_http_request.py ..............                                                                                                                                                            [ 46%]
tests/test_http_response.py .........                                                                                                                                                                [ 62%]
tests/test_utils.py ............                                                                                                                                                                     [ 82%]
tests/test_websocket.py ..........                                                                                                                                                                   [100%]

============================================================================================= warnings summary =============================================================================================
.env/lib/python3.7/site-packages/pytest_asyncio/plugin.py:191
  /home/marcin/programming/daphne/.env/lib/python3.7/site-packages/pytest_asyncio/plugin.py:191: DeprecationWarning: The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
    config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
====================================================================================== 58 passed, 1 warning in 15.02s ======================================================================================

Black:

$ black tests/ daphne/
All done! ✨ 🍰 ✨
19 files left unchanged.

Isort:

$ isort --check-only --diff  ./daphne ./tests
$ echo $?
0