Skip to content

Commit

Permalink
Move test client to emmett-core RSGI
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Sep 19, 2024
1 parent c5a6076 commit 08445e4
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 1,625 deletions.
8 changes: 1 addition & 7 deletions emmett/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,8 @@ class App(_App):

config_class = Config
modules_class = AppModule
# routers_class = (HTTPRouter, WebsocketRouter)
signals_class = Signals
test_client_class = None
test_client_class = EmmettTestClient

def __init__(
self,
Expand Down Expand Up @@ -457,11 +456,6 @@ def config_from_yaml(self, filename: str, namespace: Optional[str] = None):
def use_template_extension(self, ext_cls, **config):
return self.templater.use_extension(ext_cls, **config)

# TODO: move to emmett_core
def test_client(self, use_cookies: bool = True, **kwargs) -> EmmettTestClient:
tclass = self.test_client_class or EmmettTestClient
return tclass(self, use_cookies=use_cookies, **kwargs)

def module(
self,
import_name: str,
Expand Down
1 change: 0 additions & 1 deletion emmett/rsgi/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ async def _debug_handler(self) -> str:


class WSHandler(_WSHandler):
__slots__ = ['pre_handler', '__dict__']
wrapper_cls = Websocket
31 changes: 31 additions & 0 deletions emmett/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from emmett_core.protocols.rsgi.test_client.client import EmmettTestClient as _EmmettTestClient, ClientContext as _ClientContext, ClientHTTPHandlerMixin

from .ctx import current
from .rsgi.handlers import HTTPHandler
from .wrappers.response import Response


class ClientContextResponse(Response):
def __init__(self, original_response: Response):
super().__init__()
self.status = original_response.status
self.headers._data.update(original_response.headers._data)
self.cookies.update(original_response.cookies.copy())
self.__dict__.update(original_response.__dict__)


class ClientContext(_ClientContext):
_response_wrap_cls = ClientContextResponse

def __init__(self, ctx):
super().__init__(ctx)
self.T = current.T


class ClientHTTPHandler(ClientHTTPHandlerMixin, HTTPHandler):
_client_ctx_cls = ClientContext


class EmmettTestClient(_EmmettTestClient):
_current = current
_handler_cls = ClientHTTPHandler
1 change: 0 additions & 1 deletion emmett/testing/__init__.py

This file was deleted.

Loading

0 comments on commit 08445e4

Please sign in to comment.