This repository was archived by the owner on May 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 55from django .forms import widgets
66
77
8- if StrictVersion (rest_framework .VERSION ) < StrictVersion ('3.0.0' ):
8+ DRF_VERSION_INFO = StrictVersion (rest_framework .VERSION ).version
9+ DRF2 = DRF_VERSION_INFO [0 ] == 2
10+ DRF3 = DRF_VERSION_INFO [0 ] == 3
11+
12+
13+ if DRF2 :
914 class Serializer (serializers .Serializer ):
1015 pass
1116
@@ -57,10 +62,8 @@ def get_username(user):
5762
5863
5964def get_request_data (request ):
60- if getattr (request , 'data' , None ):
61- data = request .data
62- else :
63- # DRF < 3.2
65+ if DRF2 :
6466 data = request .DATA
65-
67+ else :
68+ data = request .data
6669 return data
Original file line number Diff line number Diff line change @@ -19,6 +19,13 @@ def test_get_request_data(self):
1919
2020 assert get_request_data (request ) == {'a' : 'b' }
2121
22+ def test_get_request_data_empty (self ):
23+ data = ''
24+ post = self .factory .post ('/' , data , content_type = 'application/json' )
25+ request = Request (post , parsers = [JSONParser ()])
26+
27+ assert get_request_data (request ) == {}
28+
2229 def test_get_request_data_invalid (self ):
2330 data = '{a:b}'
2431 post = self .factory .post ('/' , data , content_type = 'application/json' )
You can’t perform that action at this time.
0 commit comments