|
17 | 17 | from rest_framework.test import (
|
18 | 18 | APIClient, APIRequestFactory, URLPatternsTestCase, force_authenticate
|
19 | 19 | )
|
| 20 | +from rest_framework.views import APIView |
20 | 21 |
|
21 | 22 |
|
22 | 23 | @api_view(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'])
|
@@ -294,6 +295,28 @@ def test_explicitly_enforce_csrf_checks(self):
|
294 | 295 | assert response.status_code == 403
|
295 | 296 | assert response.data == expected
|
296 | 297 |
|
| 298 | + def test_transform_factory_django_request_to_drf_request(self): |
| 299 | + """ |
| 300 | + ref: GH-3608, GH-4440 & GH-6488. |
| 301 | + """ |
| 302 | + |
| 303 | + factory = APIRequestFactory() |
| 304 | + |
| 305 | + class DummyView(APIView): # Your custom view. |
| 306 | + ... |
| 307 | + |
| 308 | + request = factory.get('/', {'demo': 'test'}) |
| 309 | + drf_request = DummyView().initialize_request(request) |
| 310 | + assert drf_request.query_params == {'demo': ['test']} |
| 311 | + |
| 312 | + assert hasattr(drf_request, 'accepted_media_type') is False |
| 313 | + DummyView().initial(drf_request) |
| 314 | + assert drf_request.accepted_media_type == 'application/json' |
| 315 | + |
| 316 | + request = factory.post('/', {'example': 'test'}) |
| 317 | + drf_request = DummyView().initialize_request(request) |
| 318 | + assert drf_request.data.get('example') == 'test' |
| 319 | + |
297 | 320 | def test_invalid_format(self):
|
298 | 321 | """
|
299 | 322 | Attempting to use a format that is not configured will raise an
|
|
0 commit comments