mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-12-03 17:58:41 +00:00
27 lines
772 B
Python
27 lines
772 B
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from django.http import HttpResponse
|
|
from django.http import StreamingHttpResponse
|
|
from rest_framework.test import APIClient
|
|
|
|
|
|
def read_streaming_response(response: StreamingHttpResponse) -> bytes:
|
|
"""Consume a StreamingHttpResponse/FileResponse and close it."""
|
|
content = b"".join(response.streaming_content)
|
|
response.close()
|
|
return content
|
|
|
|
|
|
def send_json(client: APIClient, method: str, path: str, body: object) -> HttpResponse:
|
|
"""Send a request with a JSON body, any method, whatever the body is."""
|
|
return client.generic(
|
|
method,
|
|
path,
|
|
data=json.dumps(body),
|
|
content_type="application/json",
|
|
)
|