Skip to content

Commit 1ff4161

Browse files
committed
improved test-coverage
1 parent 3061439 commit 1ff4161

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

ellar/common/routing/schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
from ellar.common.constants import ROUTE_METHODS
44
from ellar.common.interfaces import IResponseModel
55
from ellar.common.responses.models import EmptyAPIResponseModel, create_response_model
6+
from ellar.common.routing.websocket import WebSocketExtraHandler
67
from ellar.common.serializer import BaseSerializer
78
from pydantic import BaseModel, Field, PrivateAttr, root_validator, validator
89

9-
if t.TYPE_CHECKING: # pragma: no cover
10-
from ellar.common.routing.websocket import WebSocketExtraHandler
11-
1210

1311
class TResponseModel:
1412
@classmethod
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from ellar.common.routing import ModuleMount
2+
3+
4+
class ControlType:
5+
pass
6+
7+
8+
def test_module_mount_default_handler(test_client_factory):
9+
mount = ModuleMount("/", ControlType, routes=[])
10+
client = test_client_factory(mount.handle)
11+
res = client.get("/")
12+
assert res.status_code == 404
13+
assert res.text == "Not Found"

tests/test_websocket_handler.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ImproperConfiguration,
66
WebSocketRequestValidationError,
77
)
8+
from ellar.common.routing.websocket import WebSocketExtraHandler
89
from ellar.reflect import reflect
910
from ellar.testing import Test
1011
from starlette.websockets import WebSocket, WebSocketState
@@ -316,3 +317,25 @@ def test_add_websocket_handler_raise_exception_for_wrong_handler_name():
316317
str(ex.value)
317318
== "Invalid Handler Name. Handler Name must be in ['encoding', 'on_receive', 'on_connect', 'on_disconnect']"
318319
)
320+
websocket_operation.add_websocket_handler(
321+
handler_name="on_receive", handler=websocket_with_handler_connect
322+
)
323+
324+
325+
def test_websocket_handler_fails_for_invalid_handlers():
326+
a_type = type("AType", (), {})
327+
with pytest.raises(ValueError):
328+
329+
@ws_route(extra_handler_type=a_type)
330+
def invalid_ws_route():
331+
pass
332+
333+
with pytest.raises(ValueError):
334+
335+
@ws_route(extra_handler_type=a_type())
336+
def invalid_ws_route_case_2():
337+
pass
338+
339+
@ws_route(extra_handler_type=WebSocketExtraHandler)
340+
def valid_ws_route():
341+
pass

0 commit comments

Comments
 (0)