chanx 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chanx-0.1.0/.gitignore +107 -0
- chanx-0.1.0/AUTHORS.rst +13 -0
- chanx-0.1.0/LICENSE +31 -0
- chanx-0.1.0/PKG-INFO +166 -0
- chanx-0.1.0/README.md +95 -0
- chanx-0.1.0/chanx/__init__.py +0 -0
- chanx-0.1.0/chanx/generic/__init__.py +0 -0
- chanx-0.1.0/chanx/generic/authenticator.py +360 -0
- chanx-0.1.0/chanx/generic/websocket.py +487 -0
- chanx-0.1.0/chanx/messages/__init__.py +0 -0
- chanx-0.1.0/chanx/messages/base.py +222 -0
- chanx-0.1.0/chanx/messages/incoming.py +35 -0
- chanx-0.1.0/chanx/messages/outgoing.py +99 -0
- chanx-0.1.0/chanx/playground/__init__.py +0 -0
- chanx-0.1.0/chanx/playground/static/playground/css/websocket.css +520 -0
- chanx-0.1.0/chanx/playground/static/playground/js/websocket/connection.js +119 -0
- chanx-0.1.0/chanx/playground/static/playground/js/websocket/endpoints.js +86 -0
- chanx-0.1.0/chanx/playground/static/playground/js/websocket/main.js +83 -0
- chanx-0.1.0/chanx/playground/static/playground/js/websocket/messages.js +295 -0
- chanx-0.1.0/chanx/playground/static/playground/js/websocket/parameters.js +700 -0
- chanx-0.1.0/chanx/playground/static/playground/js/websocket/ui.js +42 -0
- chanx-0.1.0/chanx/playground/static/playground/js/websocket/utils.js +32 -0
- chanx-0.1.0/chanx/playground/static/playground/js/websocket.js +11 -0
- chanx-0.1.0/chanx/playground/templates/playground/websocket.html +166 -0
- chanx-0.1.0/chanx/playground/urls.py +20 -0
- chanx-0.1.0/chanx/playground/utils.py +243 -0
- chanx-0.1.0/chanx/playground/views.py +124 -0
- chanx-0.1.0/chanx/routing.py +48 -0
- chanx-0.1.0/chanx/settings.py +126 -0
- chanx-0.1.0/chanx/testing.py +270 -0
- chanx-0.1.0/chanx/types.py +32 -0
- chanx-0.1.0/chanx/utils/__init__.py +0 -0
- chanx-0.1.0/chanx/utils/asgi.py +32 -0
- chanx-0.1.0/chanx/utils/asyncio.py +90 -0
- chanx-0.1.0/chanx/utils/logging.py +10 -0
- chanx-0.1.0/chanx/utils/request.py +49 -0
- chanx-0.1.0/chanx/utils/settings.py +123 -0
- chanx-0.1.0/chanx/utils/websocket.py +268 -0
- chanx-0.1.0/pyproject.toml +166 -0
chanx-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
env/
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
|
|
28
|
+
# PyInstaller
|
|
29
|
+
# Usually these files are written by a python script from a template
|
|
30
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
.cache
|
|
44
|
+
nosetests.xml
|
|
45
|
+
coverage.xml
|
|
46
|
+
*.cover
|
|
47
|
+
.hypothesis/
|
|
48
|
+
.pytest_cache/
|
|
49
|
+
|
|
50
|
+
# Translations
|
|
51
|
+
*.mo
|
|
52
|
+
*.pot
|
|
53
|
+
|
|
54
|
+
# Django stuff:
|
|
55
|
+
*.log
|
|
56
|
+
local_settings.py
|
|
57
|
+
|
|
58
|
+
# Flask stuff:
|
|
59
|
+
instance/
|
|
60
|
+
.webassets-cache
|
|
61
|
+
|
|
62
|
+
# Scrapy stuff:
|
|
63
|
+
.scrapy
|
|
64
|
+
|
|
65
|
+
# Sphinx documentation
|
|
66
|
+
docs/_build/
|
|
67
|
+
|
|
68
|
+
# PyBuilder
|
|
69
|
+
target/
|
|
70
|
+
|
|
71
|
+
# Jupyter Notebook
|
|
72
|
+
.ipynb_checkpoints
|
|
73
|
+
|
|
74
|
+
# Dask worker cache
|
|
75
|
+
dask-worker-space/
|
|
76
|
+
|
|
77
|
+
# celery beat schedule file
|
|
78
|
+
celerybeat-schedule
|
|
79
|
+
|
|
80
|
+
# SageMath parsed files
|
|
81
|
+
*.sage.py
|
|
82
|
+
|
|
83
|
+
# dotenv
|
|
84
|
+
.env
|
|
85
|
+
|
|
86
|
+
# virtualenv
|
|
87
|
+
.venv
|
|
88
|
+
.venv-*/
|
|
89
|
+
venv/
|
|
90
|
+
ENV/
|
|
91
|
+
|
|
92
|
+
# Spyder project settings
|
|
93
|
+
.spyderproject
|
|
94
|
+
.spyproject
|
|
95
|
+
|
|
96
|
+
# Rope project settings
|
|
97
|
+
.ropeproject
|
|
98
|
+
|
|
99
|
+
# mkdocs documentation
|
|
100
|
+
/site
|
|
101
|
+
|
|
102
|
+
# mypy
|
|
103
|
+
.mypy_cache/
|
|
104
|
+
|
|
105
|
+
# IDE settings
|
|
106
|
+
.vscode/
|
|
107
|
+
.idea/
|
chanx-0.1.0/AUTHORS.rst
ADDED
chanx-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
BSD License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025, Huy Nguyen
|
|
6
|
+
All rights reserved.
|
|
7
|
+
|
|
8
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
9
|
+
are permitted provided that the following conditions are met:
|
|
10
|
+
|
|
11
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
12
|
+
list of conditions and the following disclaimer.
|
|
13
|
+
|
|
14
|
+
* Redistributions in binary form must reproduce the above copyright notice, this
|
|
15
|
+
list of conditions and the following disclaimer in the documentation and/or
|
|
16
|
+
other materials provided with the distribution.
|
|
17
|
+
|
|
18
|
+
* Neither the name of the copyright holder nor the names of its
|
|
19
|
+
contributors may be used to endorse or promote products derived from this
|
|
20
|
+
software without specific prior written permission.
|
|
21
|
+
|
|
22
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
23
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
24
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
25
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
26
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
27
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
28
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
29
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
30
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
31
|
+
OF THE POSSIBILITY OF SUCH DAMAGE.
|
chanx-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chanx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The missing toolkit for Django Channels — auth, logging, consumers, and more.
|
|
5
|
+
Project-URL: Documentation, https://chanx.readthedocs.io/
|
|
6
|
+
Project-URL: Homepage, https://github.com/huynguyengl99/chanx
|
|
7
|
+
Project-URL: Repository, https://github.com/huynguyengl99/chanx
|
|
8
|
+
Author-email: Huy Nguyen <danghuy1999@gmail.com>
|
|
9
|
+
License:
|
|
10
|
+
|
|
11
|
+
BSD License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2025, Huy Nguyen
|
|
14
|
+
All rights reserved.
|
|
15
|
+
|
|
16
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
17
|
+
are permitted provided that the following conditions are met:
|
|
18
|
+
|
|
19
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
20
|
+
list of conditions and the following disclaimer.
|
|
21
|
+
|
|
22
|
+
* Redistributions in binary form must reproduce the above copyright notice, this
|
|
23
|
+
list of conditions and the following disclaimer in the documentation and/or
|
|
24
|
+
other materials provided with the distribution.
|
|
25
|
+
|
|
26
|
+
* Neither the name of the copyright holder nor the names of its
|
|
27
|
+
contributors may be used to endorse or promote products derived from this
|
|
28
|
+
software without specific prior written permission.
|
|
29
|
+
|
|
30
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
31
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
32
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
33
|
+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
34
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
35
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
36
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
37
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
38
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
39
|
+
OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
40
|
+
License-File: AUTHORS.rst
|
|
41
|
+
License-File: LICENSE
|
|
42
|
+
Classifier: Environment :: Web Environment
|
|
43
|
+
Classifier: Intended Audience :: Developers
|
|
44
|
+
Classifier: Intended Audience :: Information Technology
|
|
45
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
46
|
+
Classifier: Operating System :: OS Independent
|
|
47
|
+
Classifier: Programming Language :: Python :: 3
|
|
48
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
49
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
50
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
51
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
52
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
53
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
54
|
+
Classifier: Topic :: Software Development
|
|
55
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
56
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
57
|
+
Requires-Python: <4.0,>=3.11
|
|
58
|
+
Requires-Dist: channels-redis<5,>=4
|
|
59
|
+
Requires-Dist: channels<5,>=4
|
|
60
|
+
Requires-Dist: django<6,>=5
|
|
61
|
+
Requires-Dist: djangorestframework<4,>=3
|
|
62
|
+
Requires-Dist: polyfactory>=2.20.0
|
|
63
|
+
Requires-Dist: pydantic<3,>=2
|
|
64
|
+
Requires-Dist: redis[hiredis]<6,>=5.2.1
|
|
65
|
+
Requires-Dist: structlog>=25.2.0
|
|
66
|
+
Provides-Extra: jwt
|
|
67
|
+
Requires-Dist: dj-rest-auth[with-social]>=7.0.1; extra == 'jwt'
|
|
68
|
+
Requires-Dist: djangorestframework-simplejwt>=5.5.0; extra == 'jwt'
|
|
69
|
+
Provides-Extra: logging
|
|
70
|
+
Description-Content-Type: text/markdown
|
|
71
|
+
|
|
72
|
+
# CHANX (CHANnels-eXtension)
|
|
73
|
+

|
|
74
|
+
[](https://codecov.io/gh/huynguyengl99/chanx)
|
|
75
|
+
|
|
76
|
+
The missing toolkit for Django Channels — authentication, logging, structured messaging, and more.
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install chanx
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
For complete documentation, visit [chanx docs](https://chanx.readthedocs.io/).
|
|
85
|
+
|
|
86
|
+
## Introduction
|
|
87
|
+
|
|
88
|
+
Django Channels provides excellent WebSocket support for Django applications, but leaves gaps in authentication,
|
|
89
|
+
structured messaging, and developer tooling. Chanx fills these gaps with a comprehensive toolkit that makes
|
|
90
|
+
building WebSocket applications simpler and more maintainable.
|
|
91
|
+
|
|
92
|
+
### Key Features
|
|
93
|
+
|
|
94
|
+
- **REST Framework Integration**: Use DRF authentication and permission classes with WebSockets
|
|
95
|
+
- **Structured Messaging**: Type-safe message handling with Pydantic validation
|
|
96
|
+
- **WebSocket Playground**: Interactive UI for testing WebSocket endpoints
|
|
97
|
+
- **Group Management**: Simplified pub/sub messaging with automatic group handling
|
|
98
|
+
- **Comprehensive Logging**: Structured logging for WebSocket connections and messages
|
|
99
|
+
- **Error Handling**: Robust error reporting and client feedback
|
|
100
|
+
- **Testing Utilities**: Specialized tools for testing WebSocket consumers
|
|
101
|
+
|
|
102
|
+
### Core Components
|
|
103
|
+
|
|
104
|
+
- **AsyncJsonWebsocketConsumer**: Base consumer with authentication and structured messaging
|
|
105
|
+
- **ChanxWebsocketAuthenticator**: Bridges WebSockets with DRF authentication
|
|
106
|
+
- **Message System**: Type-safe message classes with automatic validation
|
|
107
|
+
- **WebSocketTestCase**: Test utilities for WebSocket consumers
|
|
108
|
+
|
|
109
|
+
## Configuration
|
|
110
|
+
|
|
111
|
+
Chanx can be configured through the `CHANX` dictionary in your Django settings. Below is a complete list
|
|
112
|
+
of available settings with their default values and descriptions:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
# settings.py
|
|
116
|
+
CHANX = {
|
|
117
|
+
# Message configuration
|
|
118
|
+
'MESSAGE_ACTION_KEY': 'action', # Key name for action field in messages
|
|
119
|
+
|
|
120
|
+
# Completion messages
|
|
121
|
+
'SEND_COMPLETION': False, # Whether to send completion message after processing messages
|
|
122
|
+
|
|
123
|
+
# Messaging behavior
|
|
124
|
+
'SEND_MESSAGE_IMMEDIATELY': True, # Whether to yield control after sending messages
|
|
125
|
+
'SEND_AUTHENTICATION_MESSAGE': True, # Whether to send auth status after connection
|
|
126
|
+
|
|
127
|
+
# Logging configuration
|
|
128
|
+
'LOG_RECEIVED_MESSAGE': True, # Whether to log received messages
|
|
129
|
+
'LOG_SENT_MESSAGE': True, # Whether to log sent messages
|
|
130
|
+
'LOG_IGNORED_ACTIONS': [], # Message actions that should not be logged
|
|
131
|
+
|
|
132
|
+
# Playground configuration
|
|
133
|
+
'WEBSOCKET_BASE_URL': 'ws://localhost:8000' # Default WebSocket URL for discovery
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## WebSocket Playground
|
|
138
|
+
|
|
139
|
+
Add the playground to your URLs:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
urlpatterns = [
|
|
143
|
+
path('playground/', include('chanx.playground.urls')),
|
|
144
|
+
]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Then visit `/playground/websocket/` to explore and test your WebSocket endpoints.
|
|
148
|
+
|
|
149
|
+
## Testing
|
|
150
|
+
|
|
151
|
+
Write tests for your WebSocket consumers:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
from chanx.testing import WebsocketTestCase
|
|
155
|
+
|
|
156
|
+
class TestChatConsumer(WebsocketTestCase):
|
|
157
|
+
ws_path = "/ws/chat/room1/"
|
|
158
|
+
|
|
159
|
+
async def test_connect(self):
|
|
160
|
+
communicator = self.create_communicator()
|
|
161
|
+
connected, _ = await communicator.connect()
|
|
162
|
+
self.assertTrue(connected)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
MIT
|
chanx-0.1.0/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# CHANX (CHANnels-eXtension)
|
|
2
|
+

|
|
3
|
+
[](https://codecov.io/gh/huynguyengl99/chanx)
|
|
4
|
+
|
|
5
|
+
The missing toolkit for Django Channels — authentication, logging, structured messaging, and more.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install chanx
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For complete documentation, visit [chanx docs](https://chanx.readthedocs.io/).
|
|
14
|
+
|
|
15
|
+
## Introduction
|
|
16
|
+
|
|
17
|
+
Django Channels provides excellent WebSocket support for Django applications, but leaves gaps in authentication,
|
|
18
|
+
structured messaging, and developer tooling. Chanx fills these gaps with a comprehensive toolkit that makes
|
|
19
|
+
building WebSocket applications simpler and more maintainable.
|
|
20
|
+
|
|
21
|
+
### Key Features
|
|
22
|
+
|
|
23
|
+
- **REST Framework Integration**: Use DRF authentication and permission classes with WebSockets
|
|
24
|
+
- **Structured Messaging**: Type-safe message handling with Pydantic validation
|
|
25
|
+
- **WebSocket Playground**: Interactive UI for testing WebSocket endpoints
|
|
26
|
+
- **Group Management**: Simplified pub/sub messaging with automatic group handling
|
|
27
|
+
- **Comprehensive Logging**: Structured logging for WebSocket connections and messages
|
|
28
|
+
- **Error Handling**: Robust error reporting and client feedback
|
|
29
|
+
- **Testing Utilities**: Specialized tools for testing WebSocket consumers
|
|
30
|
+
|
|
31
|
+
### Core Components
|
|
32
|
+
|
|
33
|
+
- **AsyncJsonWebsocketConsumer**: Base consumer with authentication and structured messaging
|
|
34
|
+
- **ChanxWebsocketAuthenticator**: Bridges WebSockets with DRF authentication
|
|
35
|
+
- **Message System**: Type-safe message classes with automatic validation
|
|
36
|
+
- **WebSocketTestCase**: Test utilities for WebSocket consumers
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
Chanx can be configured through the `CHANX` dictionary in your Django settings. Below is a complete list
|
|
41
|
+
of available settings with their default values and descriptions:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
# settings.py
|
|
45
|
+
CHANX = {
|
|
46
|
+
# Message configuration
|
|
47
|
+
'MESSAGE_ACTION_KEY': 'action', # Key name for action field in messages
|
|
48
|
+
|
|
49
|
+
# Completion messages
|
|
50
|
+
'SEND_COMPLETION': False, # Whether to send completion message after processing messages
|
|
51
|
+
|
|
52
|
+
# Messaging behavior
|
|
53
|
+
'SEND_MESSAGE_IMMEDIATELY': True, # Whether to yield control after sending messages
|
|
54
|
+
'SEND_AUTHENTICATION_MESSAGE': True, # Whether to send auth status after connection
|
|
55
|
+
|
|
56
|
+
# Logging configuration
|
|
57
|
+
'LOG_RECEIVED_MESSAGE': True, # Whether to log received messages
|
|
58
|
+
'LOG_SENT_MESSAGE': True, # Whether to log sent messages
|
|
59
|
+
'LOG_IGNORED_ACTIONS': [], # Message actions that should not be logged
|
|
60
|
+
|
|
61
|
+
# Playground configuration
|
|
62
|
+
'WEBSOCKET_BASE_URL': 'ws://localhost:8000' # Default WebSocket URL for discovery
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## WebSocket Playground
|
|
67
|
+
|
|
68
|
+
Add the playground to your URLs:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
urlpatterns = [
|
|
72
|
+
path('playground/', include('chanx.playground.urls')),
|
|
73
|
+
]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Then visit `/playground/websocket/` to explore and test your WebSocket endpoints.
|
|
77
|
+
|
|
78
|
+
## Testing
|
|
79
|
+
|
|
80
|
+
Write tests for your WebSocket consumers:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from chanx.testing import WebsocketTestCase
|
|
84
|
+
|
|
85
|
+
class TestChatConsumer(WebsocketTestCase):
|
|
86
|
+
ws_path = "/ws/chat/room1/"
|
|
87
|
+
|
|
88
|
+
async def test_connect(self):
|
|
89
|
+
communicator = self.create_communicator()
|
|
90
|
+
connected, _ = await communicator.connect()
|
|
91
|
+
self.assertTrue(connected)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
MIT
|
|
File without changes
|
|
File without changes
|