MCPcopy
hub / github.com/django/django / generic

Method generic

django/test/client.py:633–671  ·  view source on GitHub ↗

Construct an arbitrary HTTP request.

(
        self,
        method,
        path,
        data="",
        content_type="application/octet-stream",
        secure=False,
        *,
        headers=None,
        query_params=None,
        **extra,
    )

Source from the content-addressed store, hash-verified

631 )
632
633 def generic(
634 self,
635 method,
636 path,
637 data="",
638 content_type="application/octet-stream",
639 secure=False,
640 *,
641 headers=None,
642 query_params=None,
643 **extra,
644 ):
645 """Construct an arbitrary HTTP request."""
646 parsed = urlsplit(str(path)) # path can be lazy
647 data = force_bytes(data, settings.DEFAULT_CHARSET)
648 r = {
649 "PATH_INFO": self._get_path(parsed),
650 "REQUEST_METHOD": method,
651 "SERVER_PORT": "443" if secure else "80",
652 "wsgi.url_scheme": "https" if secure else "http",
653 }
654 if data:
655 r.update(
656 {
657 "CONTENT_LENGTH": str(len(data)),
658 "CONTENT_TYPE": content_type,
659 "wsgi.input": FakePayload(data),
660 }
661 )
662 if headers:
663 extra.update(HttpHeaders.to_wsgi_names(headers))
664 if query_params:
665 extra["QUERY_STRING"] = urlencode(query_params, doseq=True)
666 r.update(extra)
667 # If QUERY_STRING is absent or empty, extract it from the URL.
668 if not r.get("QUERY_STRING"):
669 # WSGI requires latin-1 encoded strings. See get_path_info().
670 r["QUERY_STRING"] = parsed.query.encode().decode("iso-8859-1")
671 return self.request(**r)
672
673
674class AsyncRequestFactory(RequestFactory):

Callers 9

getMethod · 0.95
postMethod · 0.95
headMethod · 0.95
traceMethod · 0.95
optionsMethod · 0.95
putMethod · 0.95
patchMethod · 0.95
deleteMethod · 0.95

Calls 10

_get_pathMethod · 0.95
requestMethod · 0.95
force_bytesFunction · 0.90
urlencodeFunction · 0.90
FakePayloadClass · 0.85
to_wsgi_namesMethod · 0.80
updateMethod · 0.45
getMethod · 0.45
decodeMethod · 0.45
encodeMethod · 0.45

Tested by 1