Skip to content

Commit 95e6787

Browse files
committed
Add test for BinaryFieldStorage.
Start a test specifically for BinaryFieldStorage.
1 parent a2bf119 commit 95e6787

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/rest_common.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,47 @@ def testEtagProcessing(self):
11941194
else:
11951195
self.assertEqual(self.dummy_client.response_code, 412)
11961196

1197+
def testBinaryFieldStorage(self):
1198+
''' attempt to exercise all paths in the BinaryFieldStorage
1199+
class
1200+
'''
1201+
1202+
expected={ "data": {
1203+
"link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1",
1204+
"id": "1"
1205+
}
1206+
}
1207+
1208+
body=b'{ "title": "Joe Doe has problems", \
1209+
"nosy": [ "1", "3" ], \
1210+
"assignedto": "2", \
1211+
"abool": true, \
1212+
"afloat": 2.3, \
1213+
"anint": 567890 \
1214+
}'
1215+
env = { "CONTENT_TYPE": "application/json",
1216+
"CONTENT_LENGTH": len(body),
1217+
"REQUEST_METHOD": "POST"
1218+
}
1219+
headers={"accept": "application/json; version=1",
1220+
"content-type": env['CONTENT_TYPE'],
1221+
"content-length": env['CONTENT_LENGTH'],
1222+
}
1223+
self.headers=headers
1224+
# we need to generate a FieldStorage the looks like
1225+
# FieldStorage(None, None, 'string') rather than
1226+
# FieldStorage(None, None, [])
1227+
body_file=BytesIO(body) # FieldStorage needs a file
1228+
form = client.BinaryFieldStorage(body_file,
1229+
headers=headers,
1230+
environ=env)
1231+
self.server.client.request.headers.get=self.get_header
1232+
results = self.server.dispatch(env["REQUEST_METHOD"],
1233+
"/rest/data/issue",
1234+
form)
1235+
json_dict = json.loads(b2s(results))
1236+
self.assertEqual(json_dict,expected)
1237+
11971238
def testDispatchPost(self):
11981239
"""
11991240
run POST through rest dispatch(). This also tests

0 commit comments

Comments
 (0)