Skip to content

Commit

Permalink
Fix test util typings (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Feb 16, 2024
1 parent dea5674 commit c5bbb00
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions jupyterlab_server/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def __init__(self, request: HTTPRequest, spec: Spec):
path=path,
)

@property
def content_type(self) -> str:
return "application/json"

@property
def host_url(self) -> str:
url = self.request.url
Expand Down Expand Up @@ -95,13 +99,13 @@ def method(self) -> str:
return method and method.lower() or ""

@property
def body(self) -> str | None:
def body(self) -> bytes | None:
if self.request.body is None:
return None # type:ignore[unreachable]
if not isinstance(self.request.body, bytes):
msg = "Request body is invalid" # type:ignore[unreachable]
raise AssertionError(msg)
return self.request.body.decode("utf-8")
return self.request.body

@property
def mimetype(self) -> str:
Expand All @@ -123,16 +127,20 @@ def __init__(self, response: HTTPResponse):
self.response = response

@property
def data(self) -> str:
def data(self) -> bytes | None:
if not isinstance(self.response.body, bytes):
msg = "Response body is invalid" # type:ignore[unreachable]
raise AssertionError(msg)
return self.response.body.decode("utf-8")
return self.response.body

@property
def status_code(self) -> int:
return int(self.response.code)

@property
def content_type(self) -> str:
return "application/json"

@property
def mimetype(self) -> str:
return str(self.response.headers.get("Content-Type", "application/json"))
Expand Down

0 comments on commit c5bbb00

Please sign in to comment.