File tree Expand file tree Collapse file tree 2 files changed +46
-4
lines changed Expand file tree Collapse file tree 2 files changed +46
-4
lines changed Original file line number Diff line number Diff line change @@ -163,8 +163,14 @@ def is_content_json(req):
163
163
:param req: the request
164
164
:return: bool
165
165
"""
166
- return req .content_type == 'application/json' \
167
- and int (req .content_length ) > 0
166
+ content_type = ''
167
+ try :
168
+ content_type = req .content_type
169
+ except AttributeError :
170
+ content_type = req .environ .get (['CONTENT_TYPE' ], '' )
171
+ finally :
172
+ return 'application/json' in content_type \
173
+ and int (req .content_length ) > 0
168
174
169
175
170
176
def is_uid_string (string ):
Original file line number Diff line number Diff line change 14
14
15
15
import six
16
16
import unittest
17
-
18
- from pycadf import cadftaxonomy as taxonomy
17
+ import webob
19
18
20
19
import watcher .common as common
21
20
21
+ from . import fake
22
22
23
23
class TestCommon (unittest .TestCase ):
24
24
def test_is_version_string (self ):
@@ -82,6 +82,42 @@ def test_get_project_id_from_path(self):
82
82
stim .get ('help' )
83
83
)
84
84
85
+ def test_is_content_json (self ):
86
+ stimuli = [
87
+ {
88
+ 'request' : fake .create_request (
89
+ path = '/v2.1/os-aggregates/0123456789abcdef0123456789abcdef/action' ,
90
+ method = 'POST' ,
91
+ body_dict = {"add_host" : {"host" : "21549b2f665945baaa7101926a00143c" }},
92
+ ),
93
+ 'expected' : True
94
+ },
95
+ {
96
+ 'request' : fake .create_request (
97
+ path = '/v2.1/os-aggregates/0123456789abcdef0123456789abcdef/action'
98
+ ),
99
+ 'expected' : False
100
+ },
101
+ {
102
+ 'request' : webob .Request .blank (
103
+ path = '/v1/foobar'
104
+ ),
105
+ 'expected' : False
106
+ }
107
+ ]
108
+
109
+ for s in stimuli :
110
+ req = s .get ('request' )
111
+ expected = s .get ('expected' )
112
+ actual = common .is_content_json (req )
113
+
114
+ self .assertEqual (
115
+ actual ,
116
+ expected ,
117
+ "should be '{0}' but got '{1}'" .format (expected , actual )
118
+ )
119
+
120
+
85
121
86
122
if __name__ == '__main__' :
87
123
unittest .main ()
You can’t perform that action at this time.
0 commit comments