comparison test/rest_common.py @ 5993:a0ab2c5d1c2a

Add test for BinaryFieldStorage. Start a test specifically for BinaryFieldStorage.
author John Rouillard <rouilj@ieee.org>
date Sat, 21 Dec 2019 14:52:06 -0500
parents ea3485c67f94
children e097ff5064b8
comparison
equal deleted inserted replaced
5992:7a324977ee74 5993:a0ab2c5d1c2a
1192 if mode not in ('brokenheader', 'brokenetag', 'none'): 1192 if mode not in ('brokenheader', 'brokenetag', 'none'):
1193 self.assertEqual(self.dummy_client.response_code, 200) 1193 self.assertEqual(self.dummy_client.response_code, 200)
1194 else: 1194 else:
1195 self.assertEqual(self.dummy_client.response_code, 412) 1195 self.assertEqual(self.dummy_client.response_code, 412)
1196 1196
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
1197 def testDispatchPost(self): 1238 def testDispatchPost(self):
1198 """ 1239 """
1199 run POST through rest dispatch(). This also tests 1240 run POST through rest dispatch(). This also tests
1200 sending json payload through code as dispatch is the 1241 sending json payload through code as dispatch is the
1201 code that changes json payload into something we can 1242 code that changes json payload into something we can

Roundup Issue Tracker: http://roundup-tracker.org/