Skip to content

Commit 3146f6b

Browse files
committed
Split out the response data decoding chunk.
1 parent 7cca838 commit 3146f6b

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

tests/test_mig_api.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@
3030
from urllib.request import urlopen, Request
3131

3232

33+
def attempt_to_decode_response_data(data, response_encoding=None):
34+
if response_encoding == 'textual':
35+
data = codecs.decode(data, 'utf8')
36+
37+
try:
38+
return json.loads(data)
39+
except Exception as e:
40+
return data
41+
elif response_encoding == 'binary':
42+
return data
43+
else:
44+
raise AssertionError(
45+
'issue_POST: unknown response_encoding "%s"' % (response_encoding,))
46+
47+
3348
class MigServerGrid_openid(MigTestCase, HtmlAssertMixin):
3449
def before_each(self):
3550
self.server_addr = None
@@ -107,18 +122,8 @@ def issue_POST(self, request_path, request_data=None, request_json=None, respons
107122
status = httpexc.code
108123
data = httpexc.file.read()
109124

110-
if response_encoding == 'textual':
111-
data = codecs.decode(data, 'utf8')
112-
113-
try:
114-
data = json.loads(data)
115-
except Exception as e:
116-
pass
117-
elif response_encoding != 'binary':
118-
raise AssertionError(
119-
'issue_POST: unknown response_encoding "%s"' % (response_encoding,))
120-
121-
return (status, data)
125+
content = attempt_to_decode_response_data(data, response_encoding)
126+
return (status, content)
122127

123128
@unittest.skipIf(PY2, "Python 3 only")
124129
def test__GET_returns_not_found_for_missing_path(self):

0 commit comments

Comments
 (0)