@@ -386,7 +386,7 @@ def get(self, request):
386
386
387
387
388
388
class JsonRequestTests (TestCase ):
389
- def test_application_json (self ):
389
+ def test_with_json_content_type (self ):
390
390
data = {
391
391
'foo' : 'bar' ,
392
392
'baz' : 'qux' ,
@@ -395,7 +395,7 @@ def test_application_json(self):
395
395
396
396
@json_request
397
397
def temp (req ):
398
- return req .data
398
+ return req .json_data
399
399
400
400
res = temp (rf .post (
401
401
'/' ,
@@ -404,61 +404,32 @@ def temp(req):
404
404
))
405
405
eq_ (res , data )
406
406
407
- def test_get_requests (self ):
407
+ def test_without_json_content_type (self ):
408
408
data = {
409
409
'foo' : 'bar' ,
410
410
'baz' : '0'
411
411
}
412
412
413
- @json_request (assume_json = False )
414
- def temp (req ):
415
- return req .data
416
-
417
- res = temp (rf .get ('/?foo=bar&baz=0' ))
418
- eq_ (res , data )
419
-
420
- def test_post_requests (self ):
421
- data = {
422
- 'foo' : 'bar' ,
423
- 'baz' : '0'
424
- }
425
-
426
- @json_request (assume_json = False )
413
+ @json_request (assume_json = True )
427
414
def temp (req ):
428
- return req .data
415
+ return req .json_data
429
416
430
- # test application/x-www-form-urlencoded
431
417
res = temp (rf .post (
432
418
'/' ,
433
- data = 'foo=bar&baz=0' ,
419
+ data = json . dumps ( data ) ,
434
420
content_type = 'application/x-www-form-urlencoded'
435
421
))
436
422
eq_ (res , data )
437
423
438
- # test multipart/form-data
439
- res = temp (rf .post ('/' , data = data , files = None ))
440
- eq_ (res , data )
441
-
442
- def test_assume_json (self ):
424
+ def test_without_json_data (self ):
443
425
data = {
444
426
'foo' : 'bar' ,
445
427
'baz' : '0'
446
428
}
447
429
448
- @json_request (assume_json = True )
449
- def temp (req ):
450
- return req .data
451
-
452
430
@json_request (assume_json = False )
453
- def temp_2 (req ):
454
- return req .data
455
-
456
- # test get request
457
- res = temp (rf .get ('/?foo=bar&baz=0' ))
458
- eq_ (res , {})
459
-
460
- res = temp_2 (rf .get ('/?foo=bar&baz=0' ))
461
- eq_ (res , data )
431
+ def temp (req ):
432
+ return req .json_data
462
433
463
434
# test application/x-www-form-urlencoded
464
435
res = temp (rf .post (
0 commit comments