comparison test/rest_common.py @ 6554:576d630fc908

Fix error status for invalid props Some places were raising AttributeError which results in a 405 (bad method) not a 400. Replace with UsageError or KeyError. Make rest.py::transitive_props run aginst a prop that has no transitive elements as well. So it will verify that assignedto exists even though it has no period like assignedto.name would. These should check properties in @fields and @sort. Also validate fields that are used as search params: ?assignedto=1 If the search prop was mispelled or incorrect, the search element was ignored as though it had not been specified. Now it returns a 400 to notify sender they sent an incorrect filter. Also remove unused statements that were originally for finding invalid props before we supported transitive props.
author John Rouillard <rouilj@ieee.org>
date Sat, 11 Dec 2021 21:41:49 -0500
parents f8df7fed18f6
children 32c6e98e5a21
comparison
equal deleted inserted replaced
6553:75da037d1c54 6554:576d630fc908
388 cgi.MiniFieldStorage('@fields', 'status,assignedto.issue'), 388 cgi.MiniFieldStorage('@fields', 'status,assignedto.issue'),
389 cgi.MiniFieldStorage('@sort', 'status.name'), 389 cgi.MiniFieldStorage('@sort', 'status.name'),
390 ] 390 ]
391 results = self.server.get_collection('issue', form) 391 results = self.server.get_collection('issue', form)
392 self.assertDictEqual(expected, results) 392 self.assertDictEqual(expected, results)
393
394 def testGetBadTransitive(self):
395 """
396 Mess up the names of various properties and make sure we get a 400
397 and a somewhat useful error message.
398 """
399 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/'
400 #self.maxDiff=None
401 self.create_sampledata()
402 self.db.issue.set('2', status=self.db.status.lookup('closed'))
403 self.db.issue.set('3', status=self.db.status.lookup('chatting'))
404 expected = [
405 {'error': {'msg': KeyError('Unknown property: assignedto.isse',),
406 'status': 400}},
407 {'error': {'msg': KeyError('Unknown property: stat',),
408 'status': 400}},
409 {'error': {'msg': KeyError('Unknown property: status.nam',),
410 'status': 400}},
411 ]
412
413 ## test invalid transitive property in @fields
414 form = cgi.FieldStorage()
415 form.list = [
416 cgi.MiniFieldStorage('status.name', 'o'),
417 cgi.MiniFieldStorage('@fields', 'status,assignedto.isse'),
418 cgi.MiniFieldStorage('@sort', 'status.name'),
419 ]
420 results = self.server.get_collection('issue', form)
421 self.assertEqual(self.dummy_client.response_code, 400)
422 self.assertEqual(repr(expected[0]['error']['msg']),
423 repr(results['error']['msg']))
424 self.assertEqual(expected[0]['error']['status'],
425 results['error']['status'])
426
427 ## test invalid property in @fields
428 form = cgi.FieldStorage()
429 form.list = [
430 cgi.MiniFieldStorage('status.name', 'o'),
431 cgi.MiniFieldStorage('@fields', 'stat,assignedto.isuse'),
432 cgi.MiniFieldStorage('@sort', 'status.name'),
433 ]
434 results = self.server.get_collection('issue', form)
435 self.assertEqual(self.dummy_client.response_code, 400)
436 self.assertEqual(repr(expected[1]['error']['msg']),
437 repr(results['error']['msg']))
438 self.assertEqual(expected[1]['error']['status'],
439 results['error']['status'])
440
441 ## test invalid transitive property in filter TODO
442 form = cgi.FieldStorage()
443 form.list = [
444 cgi.MiniFieldStorage('status.nam', 'o'),
445 cgi.MiniFieldStorage('@fields', 'status,assignedto.isuse'),
446 cgi.MiniFieldStorage('@sort', 'status.name'),
447 ]
448 results = self.server.get_collection('issue', form)
449 # is currently 403 not 400
450 self.assertEqual(self.dummy_client.response_code, 400)
451 self.assertEqual(repr(expected[2]['error']['msg']),
452 repr(results['error']['msg']))
453 self.assertEqual(expected[2]['error']['status'],
454 results['error']['status'])
393 455
394 def testGetExactMatch(self): 456 def testGetExactMatch(self):
395 """ Retrieve all issues with an exact title 457 """ Retrieve all issues with an exact title
396 """ 458 """
397 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/' 459 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/'

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