Skip to content

Commit

Permalink
Merge pull request #1244 from acuriel/bugfix/set-djang-http-request-a…
Browse files Browse the repository at this point in the history
…s-spec-for-mocked-request

Fix issue when consulting request attributes while using mocked request
  • Loading branch information
vitalik authored Aug 10, 2024
2 parents aa46acf + 818505e commit f0f5547
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ninja/testing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from urllib.parse import urljoin

from django.http import QueryDict, StreamingHttpResponse
from django.http.request import HttpHeaders
from django.http.request import HttpHeaders, HttpRequest

from ninja import NinjaAPI, Router
from ninja.responses import NinjaJSONEncoder
Expand Down Expand Up @@ -121,7 +121,7 @@ def _resolve(
def _build_request(
self, method: str, path: str, data: Dict, request_params: Any
) -> Mock:
request = Mock()
request = Mock(spec=HttpRequest)
request.method = method
request.path = path
request.body = ""
Expand All @@ -131,6 +131,7 @@ def _build_request(
request.build_absolute_uri = build_absolute_uri

request.auth = None
request.user = Mock()
if "user" not in request_params:
request.user.is_authenticated = False

Expand Down

0 comments on commit f0f5547

Please sign in to comment.