fix #99: if charset is specified in content-type, request data should be encoded with charset encoding

This commit is contained in:
httprunner
2018-02-24 15:33:02 +08:00
parent f01bc59d2a
commit 4c9fb6f75b
3 changed files with 43 additions and 9 deletions

View File

@@ -36,7 +36,21 @@ class TestHttpClient(ApiServerUnittest):
self.assertEqual(201, resp.status_code)
self.assertEqual(True, resp.json()['success'])
def test_prepare_kwargs(self):
def test_prepare_kwargs_content_type_application_json_without_charset(self):
kwargs = {
"headers": {
"content-type": "application/json"
},
"data": {
"a": 1,
"b": 2
}
}
prepare_kwargs("POST", kwargs)
self.assertIn('"a": 1', kwargs["data"])
self.assertIn('"b": 2', kwargs["data"])
def test_prepare_kwargs_content_type_application_json_charset_utf8(self):
kwargs = {
"headers": {
"content-type": "application/json; charset=utf-8"
@@ -47,5 +61,4 @@ class TestHttpClient(ApiServerUnittest):
}
}
prepare_kwargs("POST", kwargs)
self.assertIn('"a": 1', kwargs["data"])
self.assertIn('"b": 2', kwargs["data"])
self.assertIsInstance(kwargs["data"], bytes)