Skip to content

Commit 3eb3bc5

Browse files
anderskamaranand360
authored andcommitted
test_classes: Default client_post to application/x-www-form-urlencoded.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
1 parent 43080c8 commit 3eb3bc5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

zerver/lib/test_classes.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,28 @@ def client_post(
532532
secure: bool = False,
533533
headers: Optional[Mapping[str, Any]] = None,
534534
intentionally_undocumented: bool = False,
535+
content_type: Optional[str] = None,
535536
**extra: str,
536537
) -> "TestHttpResponse":
537538
django_client = self.client # see WRAPPER_COMMENT
538539
self.set_http_headers(extra, skip_user_agent)
540+
encoded = info
541+
if content_type is None:
542+
if isinstance(info, dict) and not any(
543+
hasattr(value, "read") and callable(value.read) for value in info.values()
544+
):
545+
content_type = "application/x-www-form-urlencoded"
546+
encoded = urlencode(info, doseq=True)
547+
else:
548+
content_type = MULTIPART_CONTENT
539549
result = django_client.post(
540-
url, info, follow=follow, secure=secure, headers=headers, **extra
550+
url,
551+
encoded,
552+
follow=follow,
553+
secure=secure,
554+
headers=headers,
555+
content_type=content_type,
556+
**extra,
541557
)
542558
self.validate_api_response_openapi(
543559
url,

0 commit comments

Comments
 (0)