diff options
author | Tim Graham <timograham@gmail.com> | 2018-02-12 10:50:43 -0500 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-02-12 12:53:02 -0500 |
commit | a6fb81750a2f2c426e44f828b0e06420e760bf6d (patch) | |
tree | 061d7eaa536018c0162662f4d8c2d5ca283cb3e7 /tests/test_client | |
parent | b8a41a2872624a6d9e61308932dd81d001e31eb9 (diff) | |
download | django-a6fb81750a2f2c426e44f828b0e06420e760bf6d.tar.gz |
Added a test for Client.generic() data coercion.
The smart_str() call (now force_bytes()) added in
e73838b6ddcc7b37c03f9eee04fa6e6a283fedb3 is otherwise untested.
Diffstat (limited to 'tests/test_client')
-rw-r--r-- | tests/test_client/tests.py | 7 | ||||
-rw-r--r-- | tests/test_client/views.py | 5 |
2 files changed, 11 insertions, 1 deletions
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py index e5bd1dac75..5c691f2b27 100644 --- a/tests/test_client/tests.py +++ b/tests/test_client/tests.py @@ -117,6 +117,13 @@ class ClientTest(TestCase): self.assertTrue(mock_encoder.called) self.assertTrue(mock_encoding.encode.called) + def test_put(self): + response = self.client.put('/put_view/', {'foo': 'bar'}) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.templates[0].name, 'PUT Template') + self.assertEqual(response.context['data'], "{'foo': 'bar'}") + self.assertEqual(response.context['Content-Length'], 14) + def test_trace(self): """TRACE a view""" response = self.client.trace('/trace_view/') diff --git a/tests/test_client/views.py b/tests/test_client/views.py index 9ffb1bd6a3..60a0b765d4 100644 --- a/tests/test_client/views.py +++ b/tests/test_client/views.py @@ -53,7 +53,10 @@ def trace_view(request): def put_view(request): if request.method == 'PUT': t = Template('Data received: {{ data }} is the body.', name='PUT Template') - c = Context({'data': request.body.decode()}) + c = Context({ + 'Content-Length': request.META['CONTENT_LENGTH'], + 'data': request.body.decode(), + }) else: t = Template('Viewing GET page.', name='Empty GET Template') c = Context() |