Skip to content

Commit

Permalink
chore: rename websocket tutorial folder
Browse files Browse the repository at this point in the history
  • Loading branch information
CaselIT committed Aug 8, 2024
1 parent 1e74a2a commit 12b5641
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- "towncrier"
- "look"
- "asgilook"
- "wslook"
- "ws_tutorial"
- "check_vendored"
- "twine_check"
- "daphne"
Expand Down
18 changes: 9 additions & 9 deletions docs/user/tutorial-websockets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ using the :mod:`venv` module:

.. code-block:: bash
$ mkdir asyncws
$ cd asyncws
$ mkdir ws_tutorial
$ cd ws_tutorial
$ python3 -m venv .venv
$ source .venv/bin/activate
Create the following directory structure::

asyncws
ws_tutorial
├── .venv
└── asyncws
└── ws_tutorial
├── __init__.py
└── app.py

Expand Down Expand Up @@ -153,7 +153,7 @@ _____________
Create a new file called ``client.py`` in the same directory as ``app.py``.
The client will ask for your input and send it to the server.:

.. literalinclude:: ../../examples/wslook/wslook/client.py
.. literalinclude:: ../../examples/ws_tutorial/ws_tutorial/client.py

Run this client in a separate terminal:

Expand Down Expand Up @@ -450,18 +450,18 @@ to take into account when implementing authentication in a WebSocket server.

Updated server code:

.. literalinclude:: ../../examples/wslook/wslook/app.py
.. literalinclude:: ../../examples/ws_tutorial/ws_tutorial/app.py

Updated client code for the reports client:

.. literalinclude:: ../../examples/wslook/wslook/reports_client.py
.. literalinclude:: ../../examples/ws_tutorial/ws_tutorial/reports_client.py

Things we've changed:

- Added a new middleware class `AuthMiddleware` that will check the token on the first message.
- Opening a websocket connection is now handled by the middleware.
- Opening a WebSocket connection is now handled by the middleware.
- The client now sends a token as the first message, if required for that route.
- Falcon was configured to server a simple html page to use the echo websocket client for a browser.
- Falcon was configured to serve a simple HTML page to use the echo WebSocket client for a browser.

If you try to query the reports endpoint now, everything works as expected on an
authenticated route.
Expand Down
4 changes: 4 additions & 0 deletions examples/ws_tutorial/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
omit =
examples/ws_tutorial/ws_tutorial/client.py
examples/ws_tutorial/ws_tutorial/reports_client.py
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from wslook.app import app
from ws_tutorial.app import app

import falcon.testing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ def test_fallback(client):
response = client.simulate_get('/missing')
assert response.status_code == 200
assert response.headers['Content-Type'] == 'text/html'
index = Path(__file__).parent.parent / 'wslook/static/index.html'
index = Path(__file__).parent.parent / 'ws_tutorial/static/index.html'
assert response.text == index.read_text()
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from copy import copy

import pytest
from wslook.app import app
from wslook.app import AuthMiddleware
from ws_tutorial.app import app
from ws_tutorial.app import AuthMiddleware

from falcon import errors
from falcon import testing
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ <h1>WebSocket Echo Test</h1>
<pre id="history"></pre>
</body>

</html>
</html>
4 changes: 0 additions & 4 deletions examples/wslook/.coveragerc

This file was deleted.

14 changes: 7 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -442,21 +442,21 @@ commands =
{toxinidir}/examples/asgilook/tests/

# --------------------------------------------------------------------
# WebSockets tutorial ("wslook") tests
# WebSockets tutorial ("ws_tutorial") tests
# --------------------------------------------------------------------

[testenv:wslook]
[testenv:ws_tutorial]
basepython = python3.12
deps =
-r{toxinidir}/examples/wslook/requirements/app
-r{toxinidir}/examples/wslook/requirements/test
-r{toxinidir}/examples/ws_tutorial/requirements/app
-r{toxinidir}/examples/ws_tutorial/requirements/test
commands =
pytest \
--cov wslook \
--cov-config {toxinidir}/examples/wslook/.coveragerc \
--cov ws_tutorial \
--cov-config {toxinidir}/examples/ws_tutorial/.coveragerc \
--cov-fail-under 100 \
--cov-report term-missing \
{toxinidir}/examples/wslook/tests/
{toxinidir}/examples/ws_tutorial/tests/

# --------------------------------------------------------------------
# Ecosystem
Expand Down

0 comments on commit 12b5641

Please sign in to comment.